Using variable in hosts group name

45 views
Skip to first unread message

bumelant

unread,
Feb 20, 2015, 7:16:56 AM2/20/15
to ansible...@googlegroups.com
Hi everyone,

Is it possible to use variables in hosts: name, like so:

- name: This does not work
  hosts: "security_group_{{ cluster_name }}"
  roles:
    - my-cluster

The variable {{ cluster_name }} is defined in my-cluster variables and is generally accessible. Not from the hosts: section though.

Thanks,
Maciej

Brian Coca

unread,
Feb 20, 2015, 8:00:04 AM2/20/15
to ansible...@googlegroups.com
You CAN use variables for hosts: but not from inventory as you need
to load hosts: to get the appropriate data.

also it would be:

hosts: "{{ 'security_group_' + cluster_name }}"

--
Brian Coca

bumelant

unread,
Feb 20, 2015, 1:17:35 PM2/20/15
to ansible...@googlegroups.com


On Friday, February 20, 2015 at 2:00:04 PM UTC+1, Brian Coca wrote:
You CAN use variables for hosts [...]  also it would be:

hosts: "{{ 'security_group_' + cluster_name }}"

Hi Brian,

It did work as you wrote, thanks! I had to pass the variables form the command line with -e, as the variables I've tried to use before pulled from roles. Need to figure out a way to pull these to the playbook level apparently.

Regards,
Maciej

Brian Coca

unread,
Feb 20, 2015, 1:23:58 PM2/20/15
to ansible...@googlegroups.com
no way, pretty much extra-vars are only one you have available at that point



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages