Trying to access groups[] programmatically not working

27 views
Skip to first unread message

Dean Mills

unread,
Jul 2, 2015, 10:55:19 AM7/2/15
to ansible...@googlegroups.com
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

Brian Coca

unread,
Jul 3, 2015, 11:07:52 PM7/3/15
to ansible...@googlegroups.com
try

haproxy_group: "{{groups[machine_environment + '.' + vpc_region + '.'
+ proxy_servers]}}"

--
Brian Coca

Dean Mills

unread,
Jul 6, 2015, 9:51:42 AM7/6/15
to ansible...@googlegroups.com
Thanks Brian, although that didn't change the error any :(

D

Brian Coca

unread,
Jul 6, 2015, 10:09:39 AM7/6/15
to ansible...@googlegroups.com
well, the group is 'develop' and your string is 'development'



--
Brian Coca

Dean Mills

unread,
Jul 6, 2015, 11:26:00 AM7/6/15
to ansible...@googlegroups.com
Sorry Brian, I should have mentioned I caught that and fixed it after posting the original question! :(

D
Reply all
Reply to author
Forward
0 new messages