Ansible 2.0.1 the same playbooks for aws and openstack iaas: how to differentiate?

129 views
Skip to first unread message

Rafał Radecki

unread,
Apr 19, 2016, 7:44:24 AM4/19/16
to Ansible Project
Hi All :)

I am using ansible 2.0.1 on both aws and openstack kilo. I would like to run the same playbook with appropriate conditions so that part of it would be run when iaas is aws and another part when iaas is openstack. I checked with the setup module that:
 - for aws vm:

$ ansible -m setup 127.0.0.1 | egrep -i 'aws|amazon|openstack|virtualization'
        "ansible_bios_version": "4.2.amazon",
        "ansible_product_version": "4.2.amazon",
        "ansible_virtualization_role": "guest",
        "ansible_virtualization_type": "xen",

- for openstack vm:

 ansible -m setup 127.0.0.1 | egrep -i 'aws|amazon|openstack|virtualization'
        "ansible_product_name": "OpenStack Nova",
        "ansible_system_vendor": "OpenStack Foundation",
        "ansible_virtualization_role": "host",
        "ansible_virtualization_type": "kvm",

so I can differentiate/divide tasks based on for example regex on "ansible_product_name". Is there a better way to build playbooks for aws and openstack?

BR,
Rafal.

Dan Lang

unread,
Apr 20, 2016, 10:07:23 AM4/20/16
to Ansible Project
You can use those variables in conjunction with Ansible conditionals and blocks 

Dejay Clayton

unread,
May 12, 2016, 4:28:07 PM5/12/16
to Ansible Project
On Tuesday, April 19, 2016 at 7:44:24 AM UTC-4, Rafał Radecki wrote:
I would like to run the same playbook with appropriate conditions so that part of it would be run when iaas is aws and another part when iaas is openstack.

Note that Ansible works best when you explicitly define what the entire host is supposed to look like, without using conditionals.  This follows Ansible's seemingly "declarative" philosophy.

Once you start getting into using conditionals, you'll also start deviating towards "imperative" logic that doesn't really fit well within Ansible.  It's a bit of a shame, because that imperative type of logic would really help Ansible become more composable.
Reply all
Reply to author
Forward
0 new messages