title: Ansible, how to define a list in host inventory?
body: <p>I have a playbook and I want to define a list of strings in my hosts file.</p>
  
  <p>Here's my host file:</p>
  
  <pre><code>[dashboard]
  1.2.3.4 dashboard_domain=test site_domain=['one','two','foo', 'bar'] 
  </code></pre>
  
  <p>Here's my playbook that I attempted to write using the <a href="http://docs.ansible.com/ansible/playbooks_loops.html#flattening-a-list" rel="nofollow noreferrer">list documentation</a>:</p>
  
  <pre><code>---
  - hosts: dashboard
    gather_facts: False
    remote_user: ubuntu
    become: yes
  
    tasks:
  
      - name: ping
        ping:
  
      - debug: 
          msg: "Domain: {{dashboard_domain}}"
  
      - debug: 
          msg: "Site: {{ item }}"
        with_items: "{{site_domain}}"
  </code></pre>
  
  <p>However running this playbook with <code>ansible-playbook -i hosts ping.yml</code> causes this error:</p>
  
  <blockquote>
    <p>TASK: [debug ] ****************************************************************<br>
    fatal: [1.2.3.4] => with_items expects a list or a set</p>
  </blockquote>
  
  <p>This seems to be an issue of transferring the defined list from the host file to the playbook because defining the list directly in the playbook works:</p>
  
  <pre><code>---
  - hosts: dashboard
    gather_facts: False
    remote_user: ubuntu
    become: yes
    vars:
      site_domain: ['one','two','foo', 'bar'] 
    tasks:
  
      #### APPLY HTTP-AUTH ####
      - name: ping
        ping:
  
      - debug: 
          msg: "Domain: {{dashboard_domain}}"
  
      - debug: 
          msg: "Site: {{ item }}"
        with_items: "{{site_domain}}"
  </code></pre>