title: In Ansible how to execute a role while looping over an array in the playbook
body: <p>I want to iterate over array and pass each array element value to role from playbook but it is not working in ansible, Can some one help</p>
  <pre><code>
  ---
  #play book
  - name: create config for instance
    hosts: all
    vars:
      LIST: [Asia, Americas, Artic, Antartic ,Oceania,Europe,Africa]
    connection: local
    roles:
      - role: create_config
        debug:
          msg : &quot;{{ item }}&quot;
        vars:
          VENUE: &quot;{{ item }}&quot;
  
        with_items:
          - &quot;{{ LIST }}&quot;
  
  
  ## Role
  - name: create directory structure
    file:
      path: &quot;{{item}}&quot;
      state: directory
      mode: 0755
    with_items:
      - &quot;{{dest_folder}}/{{instance_name}}/{{VENUE}}&quot;
  
  
  
  
  </code></pre>
  <p>I am getting below error</p>
  <pre><code>ansible-playbook  -i inventory/AlgoTest_SP  create_pkg_1.yml 
  
  PLAY [create config for instance] **************************************************************************************************************************************
  
  TASK [Gathering Facts] ****************************************************************************************************************************************************
  ok: [localhost]
  
  TASK [create_config : create directory structure] *******************************************************************************************************************
  fatal: [localhost]: FAILED! =&gt; {&quot;msg&quot;: &quot;{{ item }}: 'item' is undefined&quot;}
  
  PLAY RECAP ****************************************************************************************************************************************************************
  localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
  </code></pre>