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

**URL:** <https://forum.ansible.com/t/how-to-run-an-action-for-a-dynamically-templated-host-group/14135>\
**Category:** Ansible Project\
**Created:** [December 12, 2013, 2:17am UTC](https://forum.ansible.com/t/how-to-run-an-action-for-a-dynamically-templated-host-group/14135 "2013-12-12T02:17:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Conner](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@Joshua\_Conner](https://forum.ansible.com/u/Joshua_Conner)\
**Post date:** [December 12, 2013, 2:17am UTC](https://forum.ansible.com/t/how-to-run-an-action-for-a-dynamically-templated-host-group/14135/1 "2013-12-12T02:17:49Z")

</div>

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](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](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!

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 12, 2013, 2:18pm UTC](https://forum.ansible.com/t/how-to-run-an-action-for-a-dynamically-templated-host-group/14135/2 "2013-12-12T14:18:15Z")

</div>

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
