Using variable in hosts group name

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

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 }}"

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

no way, pretty much extra-vars are only one you have available at that point