Have have a configuration file looking like that:
one:
some: 'conf'
foo:
-
bar:
- 'one'
- 'two'
- 'three'
-
bar:
- 'one'
- 'four'
- 'five'
I want to get a list containing all strings of bar lists. I did this task:
- name: My amazing task
debug: var=item
with_flattened:
- "{{ foo | map(attribute='bar') | list }}"
#- Another lists here, but removed for simplicity
Here is the problem; the resulting list looks like this:
[{"one": "some": "conf"}, "two", "three", {"one": "some": "conf"}, "four", "five"]
Ansible seems to interpret the “one” variable previously set, ignoring the fact I’m expecting a string.
What did I do wrong? How can I get a list of strings out of the bar variables configuration?
(I use Ansible 1.9)
To prevent this very issue bare variables in
with_loops don't work in recent Ansible releases.To handle it in your case, use:
sum(start=[])makes a list of lists flat here.