I am having trouble finding a working solution to work on my inventory. I start my game with a link to the intent file:
ansible-playbook -i inventory / dev.yml playbook.yml
My play looks like this:
- hosts: localhost
tasks:
- name: Create VM if enviro == true
include_role:
name: local_vm_creator
when: enviro == 'dev'
Therefore, when loading a playbook, the enviro variable is read from host_vars and sets the condition for dev. The dev.yml inventory file is as follows:
[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
My main.yml in my local_vm_creator role is as follows:
- 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']
And the problem is that I cannot get the listed servers from the dev.yml inventory file.
it just returns:
ok: [localhost] => (item = groups ['local_vm']) => {"item": "groups ['local_vm']", msg ":" host is groups ['local_vm'] "}