# one playbook, two OS versions, common tasks, how?

**URL:** <https://forum.ansible.com/t/one-playbook-two-os-versions-common-tasks-how/14105>\
**Category:** Ansible Project\
**Created:** [December 9, 2013, 2:00pm UTC](https://forum.ansible.com/t/one-playbook-two-os-versions-common-tasks-how/14105 "2013-12-09T14:00:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Palmer1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Eric\_Palmer1](https://forum.ansible.com/u/Eric_Palmer1)\
**Post date:** [December 9, 2013, 2:00pm UTC](https://forum.ansible.com/t/one-playbook-two-os-versions-common-tasks-how/14105/1 "2013-12-09T14:00:51Z")

</div>

I have a multi host deployment playbook that needs to service Nnbuntu and Amazon linux (RPB based) servers. Some of the common tasks are very specific to debian like OS and some to RPB based OS. How do I get the common tasks to just run what is appropriate?

thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 9, 2013, 2:05pm UTC](https://forum.ansible.com/t/one-playbook-two-os-versions-common-tasks-how/14105/2 "2013-12-09T14:05:16Z")

</div>

Very very easy and you have many options!

You have the “when” conditional for one, which can easily key off facts like “ansible\_os\_family”.

- shell: /usr/bin/foo  
when: “ansible\_os\_family == ‘redhat’”

You have things like “include\_vars” which can include variables based on OS facts (1.4) at role or task level

- include\_vars: “{{ansible\_os\_family}}.yml”

or even

- include\_vars: redhat.yml  
when: “ansible\_os\_family == ‘redhat’”

You can also do this with “vars\_files” at the play level:

- hosts: webservers  
vars\_files: “{{ ansible\_os\_family}}.yml”

You can have roles for each OS if you want and include a common role dependency for common parts

(see roles chapter in docs)

You can have a standard task file and do things like:

- include: redhat.yml  
when: “ansible\_os\_family == ‘redhat’”

So, yes, lots of options!

---

<div class="post-metadata">

**Author:** ![Eric\_Palmer1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Eric\_Palmer1](https://forum.ansible.com/u/Eric_Palmer1)\
**Post date:** [December 9, 2013, 2:06pm UTC](https://forum.ansible.com/t/one-playbook-two-os-versions-common-tasks-how/14105/3 "2013-12-09T14:06:53Z")

</div>

I like options. Thanks
