title: Convert Unicode to String with Ansible and Jinja2
body: <p>I need help with converting a Unicode variable to a string in order for the below Ansible construct to work.</p>
  
  <p>In this particular case, I want to use the <code>item.keys()</code> method in order to get the current <code>env</code> name (i.e. <code>uat</code>) but I get <code>[u'uat']</code> instead. I have been searching the Internet but could not find a way to convert <code>[u'uat']</code> to a simple <code>uat</code>.</p>
  
  <p><code>defaults/main.yml</code>:</p>
  
  <pre><code>blablabla:
    env:
      - uat:
          accounts:
            - david:
                email: david@example.com
            - anna:
                email: anna@example.com
      - develop:
          accounts:
            - john:
                email: john@example.com
  </code></pre>
  
  <p><code>tasks/main.yml</code>:</p>
  
  <pre><code>- include_tasks: dosomething.yml
    with_items:
      - "{{ blablabla.env }}"
  </code></pre>
  
  <p><code>tasks/dosomething.yml</code>:</p>
  
  <pre><code>- name: Get accounts
    set_fact:
      accounts: "{%- set tmp = [] -%}
                   {%- for account in item[item.keys()].accounts -%}  
                        {{ tmp.append(account) }}
                   {%- endfor -%}
                 {{ tmp }}"
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
    &lt;failed value="True"/&gt;
    &lt;msg value="The task includes an option with an undefined variable. The error was: dict object has no element [u'uat']
  
  The error appears to have been in 'dosomething.yml': line 9, column 3, but may
  be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
  
  
  - name: Get accounts
    ^ here
  
  exception type: &amp;lt;class 'ansible.errors.AnsibleUndefinedVariable'&amp;gt;
  exception: dict object has no element [u'uat']"/&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Alternatively, I would also welcome alternative approaches, as long the data structure (i.e. the <code>defaults/main.yml</code> file) remains unchanged.</p>