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

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

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!

I like options. Thanks