Can one add items to a list within(!) the inventory?

18 views
Skip to first unread message

Frank Thommen

unread,
Jun 16, 2017, 5:49:44 AM6/16/17
to Ansible Project
Hi,

is it possible to expand a list variable within the inventory? E.g. I
have a list of users which should be allowed on all hosts but on /some/
hosts, additional users should be allowed. I want to define this in the
inventory:

So far I so:

----
[all]
users=['user1', 'user2']

[servers]
host1
host2 users=['user1', 'user2', 'user3']
host3
---

But this is redundant and inflexible. I'd prefer something like

----
[all]
users=['user1', 'user2']


host1
host2 users=users + ['user3']
host3
---

I've tried several variants to no avail.

users = users + ['user3']
users = [users, 'user3']
users = [{{users}}, 'user3']


Is such a lsit expansion possible?

Cheers
frank


Brian Coca

unread,
Jun 16, 2017, 10:29:28 AM6/16/17
to Ansible Project
Yes and no, variables cannot 'self reference' so they cannot all be
named `users`. Even then, not in the ini file format, you need to
either use a YAML inventory or YAML group_vars/host_vars


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages