# Overriding value of 'hosts' playbook variable

**URL:** <https://forum.ansible.com/t/overriding-value-of-hosts-playbook-variable/15208>\
**Category:** Ansible Project\
**Created:** [May 11, 2014, 2:10am UTC](https://forum.ansible.com/t/overriding-value-of-hosts-playbook-variable/15208 "2014-05-11T02:10:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JC11](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@JC11](https://forum.ansible.com/u/JC11)\
**Post date:** [May 11, 2014, 2:10am UTC](https://forum.ansible.com/t/overriding-value-of-hosts-playbook-variable/15208/1 "2014-05-11T02:10:10Z")

</div>

Hi guys,

Anyone know if you can completely override the hosts: value in a playbook?

I don’t use inventory files so I always just have this set to ‘all’. But when I call a playbook from another playbook like this, for example:

# Playbook1

- name: Format EBS volumes  
hosts: ec2\_group # coming from the ec2 module and add\_host  
…

- include: playbook2.yml hosts=ec2\_group

or

- { include: playbook2.yml, hosts: ec2\_group }

It works but then it also tries to run the playbook to the ‘all’ group (which is everything in my default hosts file). I want the ‘all’ value to be completely overridden by the new value I specified.

Is there a better way to do this without creating an inventory file?

Thanks

---

<div class="post-metadata">

**Author:** ![Paul\_Durivage](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Durivage](https://forum.ansible.com/u/Paul_Durivage)\
**Post date:** [May 12, 2014, 2:38pm UTC](https://forum.ansible.com/t/overriding-value-of-hosts-playbook-variable/15208/2 "2014-05-12T14:38:06Z")

</div>

I don’t think what you want to do is override a value at runtime, but rather _create_ a new group dynamically at runtime. Make a new group for hosts that meet some arbitrary criteria. See the [group\_by](http://docs.ansible.com/group_by_module.html) module – I think you’ll find what you’re looking for there.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 12, 2014, 5:13pm UTC](https://forum.ansible.com/t/overriding-value-of-hosts-playbook-variable/15208/3 "2014-05-12T17:13:10Z")

</div>

I’m confused by this as well.

When you say you are not using an inventory file, do you mean you are using the dynamic inventory plugin?

If you want a group that contains just the new hosts you have brought online, or want to add new hosts (in memory) to an existing host name, look at how the “add\_host” plugin is used in various examples – it does exactly this.
