This is my list of addresses in a YAML file :
addresses:
person1:
firstname: Maria
lastname: Smith
person2:
firstname: July
lastname: Weber
person3:
firstname: John
lastname: Kurt
person4:
firstname: Simon
lastname: Gates
What i need is a comma separated string like Maria, July, John, Simon
I tried the following:
firstnames: >-
{% set lastnames_list= [] %}
{% for name in addresses %}
{{ name.firstname | join(",")}}
{% endfor %}
{{ lastnames_list }}
firstnames: >-
{% set lastnames_list= [] %}
{% for name in addresses %}
{{ name | map(attribute="firstname") | join(",") }}
{% endfor %}
{{ lastnames_list }}
firstnames: '{{ addresses | map(attribute="firstname") | join(",") }}'
But Ansible gives the following output:
The task includes an option with an undefined variable. The error was: 'unicode object' has no attribute 'firstname'