Ansible: accessing group var variable information without inheritance

Viewed 55

I have a server that is a member of groups a, b, and c (and d, e, f... etc). There are possibly 3 group_var files (or more if the individual group_vars are directories rather than files).

# group_vars/a.yml
foo: 1
# group_vars/b.yml
foo: 2
# group_vars/c.yml
foo: 3
# inventory
[a]
wibble

[b]
wibble

[c]
wibble

[d]
wibble
...

Ultimately I wish for host wibble to have a variable foo_list: [1,2,3]. There was some talk on GitHub about this functionality but it seemed to fizzle out unfortunately. So with that in mind, I want to be able to recreate the functionality using vanilla Ansible, whereby I pluck out all the values of a variable that the hostvar could possibly have been before inheritance squashed it into one value. To do this, I need access to something like groupvars[group_name], but I cannot find if this feature exists, and I cannot find it documented anywhere and all the obvious places I'm looking have been unfruitful. Is this functionality available at all in Ansible?

For my purposes the ordering of foo_list is unimportant.

Alternatively if someone can think of a cute alternative to what I've asked above, I'm open to learning. For example I'm not against setting variables foo_a, foo_b, foo_c in the respective group_vars, and building foo_list that way.

1 Answers

It's not possible, and a PR on Github was closed as being too difficult to implement.

Related