ansible variables for each os

52 views
Skip to first unread message

Kathy L

unread,
Mar 2, 2023, 11:57:30 AM3/2/23
to Ansible Project
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 <class dict> and we were unable to convert to list:

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

Rowe, Walter P. (Fed)

unread,
Mar 2, 2023, 12:33:32 PM3/2/23
to ansible...@googlegroups.com
You need use the ansible_os_family fact as a key into your auditd_pkg dictionary.

{{ auditd_pkg[ansible_os_family] }}

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c58a3df2-0639-47fd-85fd-801897604f4cn%40googlegroups.com.

Kathy L

unread,
Mar 2, 2023, 2:20:51 PM3/2/23
to Ansible Project
That works,  thanks!

Rowe, Walter P. (Fed)

unread,
Mar 2, 2023, 2:34:27 PM3/2/23
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
Reply all
Reply to author
Forward
0 new messages