ansible variables for each os

In our playbooks, we used to load one OS-specific vars file for all our roles. Now we’d like to move the variables into each role. A method I had to do this before does not seem to be working. For our auditd role, in the vars/main.yml file I have this:

auditd_pkg:
CentOS: audit
Rocky: audit
Debian: auditd
Ubuntu: auditd

But it gives me this error:

argument ‘package’ is of type and we were unable to convert to list:

How else can I list these variables without having specific os-related files in each role?

You need use the ansible_os_family fact as a key into your auditd_pkg dictionary.

{{ auditd_pkg[ansible_os_family] }}

Walter

That works, thanks!

If you think of it as a JSON dictionary this might explain why you had to do that.

This format …

auditd_pkg:
CentOS: audit
Rocky: audit
Debian: auditd
Ubuntu: auditd

… is effectively the same as …

auditd_pkg: { “CentOS”: “audit”, “Rocky”: “audit”, “Debian”: “auditd”, “Ubuntu”: “auditd” }

Just helping …

Walter