Adapting the roles
So how do we go about building the logic into our roles to only execute certain parts of the roles on different operating systems, and also as we know that package names will be different? How do we define different sets of variables per operating system?
Operating system family
We have looked at the setup
module in previous chapters; this is the module that gathers facts about our target hosts. One of these facts is ansible_os_family
; this tells us the type of operating system we are running. Let's check on both of our boxes:
$ ansible -i production centos -m setup | grep ansible_os_family $ ansible -i production ubuntu -m setup | grep ansible_os_family
As you can see from the following Terminal output, the CentOS box returns Red Hat, which is expected. However, the Ubuntu box does not return any information:

Let's take a look at why this is. First of all, we can rerun the command, but this time minus the grep
so we can see the full output:
$ ansible -i production ubuntu -m...