Having an issue with one of my new playbooks. I am assuming this should work:
In my hosts file:
[develop.us-east-1.vpn]
vpn01.us ansible_ssh_host=10.1.1.1
vpn02.us ansible_ssh_host=10.1.1.2
[develop.us-east-1.vpn:vars]
ansible_ssh_user=openvpnas
[develop.us-east-1.haproxy]
haproxy01.us ansible_ssh_host=10.1.1.10
[develop.us-east-1.haproxy:vars]
ansible_ssh_user=ubuntu
In my playbook:
vars:
machine_environment: ‘development’
vpc_region: ‘us-east-1’
proxy_servers: ‘haproxy’
haproxy_group: “groups[‘{{machine_environment}}.{{vpc_region}}.{{ proxy_servers }}’]”
tasks:
- debug:
msg: “{{ item }}”
with_items: haproxy_group
Which I assume will loop through my proxy servers as they are listed in my hosts file, but instead I get this:
TASK: [debug ] ****************************************************************
fatal: [haproxy01.us] => One or more undefined variables: ‘item’ is undefined
If I change it to this:
- debug:
msg: “{{ haproxy_group }}”
I get this:
TASK: [debug ] ****************************************************************
ok: [haproxy01.us] => {
“msg”: “groups[‘development.us-east-1.haproxy’]”
}
How do I get my groups programmatically so I can use them inside my template to configure haproxy, etc?
I’m sure I’ve just boneheaded something or am assuming it works a specific way, any help greatly appreciated!
D