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

**URL:** <https://forum.ansible.com/t/ansible-2-0-1-the-same-playbooks-for-aws-and-openstack-iaas-how-to-differentiate/21204>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [April 19, 2016, 11:44am UTC](https://forum.ansible.com/t/ansible-2-0-1-the-same-playbooks-for-aws-and-openstack-iaas-how-to-differentiate/21204 "2016-04-19T11:44:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafal\_Radecki](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@Rafal\_Radecki](https://forum.ansible.com/u/Rafal_Radecki)\
**Post date:** [April 19, 2016, 11:44am UTC](https://forum.ansible.com/t/ansible-2-0-1-the-same-playbooks-for-aws-and-openstack-iaas-how-to-differentiate/21204/1 "2016-04-19T11:44:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dan\_Lang](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@Dan\_Lang](https://forum.ansible.com/u/Dan_Lang)\
**Post date:** [April 20, 2016, 2:07pm UTC](https://forum.ansible.com/t/ansible-2-0-1-the-same-playbooks-for-aws-and-openstack-iaas-how-to-differentiate/21204/2 "2016-04-20T14:07:23Z")

</div>

You can use those variables in conjunction with Ansible [conditionals](http://docs.ansible.com/ansible/playbooks_conditionals.html) and [blocks](http://docs.ansible.com/ansible/playbooks_blocks.html)

---

<div class="post-metadata">

**Author:** ![Dejay\_Clayton](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@Dejay\_Clayton](https://forum.ansible.com/u/Dejay_Clayton)\
**Post date:** [May 12, 2016, 8:28pm UTC](https://forum.ansible.com/t/ansible-2-0-1-the-same-playbooks-for-aws-and-openstack-iaas-how-to-differentiate/21204/3 "2016-05-12T20:28:07Z")

</div>

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.
