Methods
Include Vars with_first_found
You can include vars based on the first found.
- name: Load required variables based on the OS type
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
If the distribution is debian, the file in vars/debian.yml would have been included.
Dynamic Map List
Create a file named Ubuntu in the vars role directory
packages:
"package-name":
"debian": "package-name-for-debian"
Use the ansible_distribution facts to select the package names to install