title: How can I get a comma separated list of firstnames?
body: <p>This is my list of addresses in a YAML file :</p>
  <pre class="lang-yaml prettyprint-override"><code>addresses:
    person1:
      firstname: Maria
      lastname:  Smith
    person2:
      firstname: July
      lastname:  Weber
    person3:
      firstname: John
      lastname:  Kurt
    person4:
      firstname: Simon
      lastname:  Gates
  </code></pre>
  <p>What i need is a comma separated string like <code>Maria, July, John, Simon</code></p>
  <p>I tried the following:</p>
  <pre class="lang-yaml prettyprint-override"><code>firstnames: &gt;-
    {% set lastnames_list= [] %}
    {% for name in addresses %}
        {{ name.firstname | join(&quot;,&quot;)}}
    {% endfor %}
    {{ lastnames_list }} 
  
  firstnames: &gt;-
    {% set lastnames_list= [] %}
    {% for name in addresses %}
        {{ name | map(attribute=&quot;firstname&quot;) | join(&quot;,&quot;) }}
    {% endfor %}
    {{ lastnames_list }} 
  
  firstnames: '{{ addresses | map(attribute=&quot;firstname&quot;) | join(&quot;,&quot;) }}' 
  </code></pre>
  <p>But Ansible gives the following output:</p>
  <blockquote>
  <p>The task includes an option with an undefined variable. The error was: 'unicode object' has no attribute 'firstname'</p>
  </blockquote>