How to run an action for a dynamically–templated host group

Hello!

I’m trying to develop an ec2-instances role that I can use to ensure the proper number and type of ec2 instances are running for a given playbook. You can see what I’ve got so far here: https://gist.github.com/joshuaconner/da70f903172a6583d463

My problem is that, as it the hosts: file isn’t templated from the value ec2_tag_Name value in my group_vars/all file. I originally filed a Github issue* (here: https://github.com/ansible/ansible/issues/5252), where I learned that it’s because the value is inventory-scoped and the value for hosts: is templated pre-inventory. mpdehaan recommended I pass the value for ec2_tag_Name in with the -e flag – is there any other way? It’s not a value that will change maybe ever on a per-playbook basis, so I was really hoping I could use something like a vars file for the value.

Any ideas?

Thanks!
Josh

*Sorry!

Josh,

Hosts are evaluated before var files, so putting it in var files won't
work. You can use the -e option, which can ever slurp up the contents
of a file our output of a script with your tag name. If typing the
'-e' option is cumbersome, then create a script wrapper or command
alias around it.

Thanks,

- James