Looking at the Conditional Imports section of the Advanced Playbook docs, I see this example
vars_files:
- “vars/common.yml”
- [ “vars/{{ ansible_os_family }}.yml”, “vars/os_defaults.yml” ]
I need to differentiate between CentOS 5/6 and SLES 10/11. So, I’m thinking of something like;
vars_files:
- “vars/common.yml”
- [ “vars/{{ ansible_os_family }}-{{ ansible_distribution_version }}.yml”, “vars/os_defaults.yml” ]
But, I only want to differentiate on the “major” version.
e.g. CentOS-5, CentOS-6, Suse-10, Suse-11
So, how would you suggest using the “major” version only here?
Thanks!
Dale
Possibly:
{{ ansible_distribution_version.split(“.”)[0] }}
An alternative is to install lsb utility (redhat-lsb on redhat-ish distros) and use {{ ansible_lsb.major_release }}. ansible_lsb looks like:
“ansible_lsb”: {
“codename”: “Santiago”,
“description”: “Red Hat Enterprise Linux Server release 6.4 (Santiago)”,
“id”: “RedHatEnterpriseServer”,
“major_release”: “6”,
“release”: “6.4”
},
sf
Thanks Michael and Stephen,
I appreciate your responses!
Dale
For anyone that sees this, I don’t recommend it. There are synchronicity issues with installing redhat-lsb-core (for example) and actually accessing ansible_lsb. Unless your node ALREADY has lsb installed BEFORE you run the playbook you’ll be risking the ansible_lsb throwing an undifined error. It doesn’t matter whether you check if the binary is now on the node, or even if you use a wait_for or time command. It’ll fail the playbook and only be available when you RErun the playbook.