title: Loop through hosts with ansible
body: <p>I have a problem to find a working solution to loop over my inventory.
  I start my playbook with linking a intentory file:</p>
  
  <blockquote>
    <p>ansible-playbook -i inventory/dev.yml playbook.yml</p>
  </blockquote>
  
  <p>My playbook looks like this:</p>
  
  <pre><code>---
  - hosts: localhost
    tasks:
      - name: Create VM if enviro == true
        include_role:
          name: local_vm_creator
        when: enviro == 'dev' 
  </code></pre>
  
  <p>So when loading the playbook the variable enviro is read from host_vars and sets the when condition to dev. The inventory file dev.yml looks like this:</p>
  
  <pre><code>[local_vm]
  192.168.99.100
  192.168.99.101
  192.168.99.102
  
  [local_vm_manager_1]
  192.168.99.103
  
  [local_vm_manager_2]
  192.168.99.104
  
  [local-all:children]
  local_vm
  local_vm_manager_1
  local_vm_manager_2
  </code></pre>
  
  <p>My main.yml in my role local_vm_creator looks like this:</p>
  
  <pre><code>---
  - name: Create test host
    local_action: shell docker-machine create -d virtualbox {{ item }}
    with_items:
      - node-1
      - node-2
      - node-3
      - node-4
      - node-5
  
  - debug: msg="host is {{item}}"
    with_items:  groups['local_vm'] 
  </code></pre>
  
  <p>And the problem is that i can't get the listed servers from the dev.yml inventory file.</p>
  
  <p>it just returns: </p>
  
  <blockquote>
    <p>ok: [localhost] => (item=groups['local_vm']) => {
        "item": "groups['local_vm']",
        "msg": "host is groups['local_vm']" }</p>
  </blockquote>