title: Using Ansible loop to create multiple users: Undefined error
body: <p>I am using the following <code>ansible</code> code to create multiple unix user accounts</p>
  
  <p><code>---
  - hosts: test
    become: true
    tasks:
        - name: more complex items to add several users
          user:
           name: "{{ item.name }}"
           uid: "{{ item.uid }}"
           groups: "{{ item.groups }}"
           state: present
          with_items: "{{ user_details }}"</code></p>
  
  <p>I am storing the user information by using a separate a variable file as below  </p>
  
  <pre><code>  `cat /etc/ansible/vars.yml
     ---
  
     user_details:
         - { name: testuser1, uid: 1002, groups: "admin, logs" }
         - { name: testuser2, uid: 1003, groups: logs: }`
  </code></pre>
  
  <p>To execute above playbook , I tried with both the commands below</p>
  
  <pre><code>   sudo ansible-playbook /etc/ansible/userloop.yml -e /etc/ansible/vars.yml
     sudo ansible-playbook /etc/ansible/userloop.yml
  </code></pre>
  
  <p>but both commands are failing with below error</p>
  
  <pre><code> fatal: [host-003]: FAILED! =&gt; {"msg": "'user_details' is undefined"}
   fatal: [host-004]: FAILED! =&gt; {"msg": "'user_details' is undefined"}
  </code></pre>
  
  <p>How to resolve the issue ? I want to maintain a separate variable file to store the user information rather then putting them in the same playbook file  .</p>