Q: How to use "major" portion of {{ ansible_distribution_version }} for conditional imports?

3,139 views
Skip to first unread message

Dale Quigg

unread,
Jul 19, 2013, 3:55:57 PM7/19/13
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Jul 19, 2013, 4:12:42 PM7/19/13
to ansible...@googlegroups.com
Possibly:

{{ ansible_distribution_version.split(".")[0] }}




Dale

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Stephen Fromm

unread,
Jul 19, 2013, 4:25:44 PM7/19/13
to ansible...@googlegroups.com
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

Dale Quigg

unread,
Jul 19, 2013, 5:07:36 PM7/19/13
to ansible...@googlegroups.com
Thanks Michael and Stephen,

I appreciate your responses!

Dale

einar....@gmail.com

unread,
May 25, 2016, 10:22:03 AM5/25/16
to Ansible Project, sfr...@gmail.com
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.
Reply all
Reply to author
Forward
0 new messages