# flexible hosts value with ansible-playbook?

**URL:** <https://forum.ansible.com/t/flexible-hosts-value-with-ansible-playbook/17570>\
**Category:** Ansible Project\
**Created:** [February 20, 2015, 9:20am UTC](https://forum.ansible.com/t/flexible-hosts-value-with-ansible-playbook/17570 "2015-02-20T09:20:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rblists](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@rblists](https://forum.ansible.com/u/rblists)\
**Post date:** [February 20, 2015, 9:20am UTC](https://forum.ansible.com/t/flexible-hosts-value-with-ansible-playbook/17570/1 "2015-02-20T09:20:04Z")

</div>

Hi,

I have a simple playbook to install packages on my servers/virtual machines.  
The package name to install is a variable, with prompt if needed.  
As a default behaviour I want it to install the package on all servers, but I want to be able to override it if needed.  
The problem I see (as an ansible beginner) is that I either have to set the hosts as a variable, with no default value possible and hence a systematic prompt or -e flag passed to the command, or hardcode the default value and edit the playbook when I want to install a package to a specific server only. I could also have 2 playbooks, one for installation on all servers, and one with a prompt for the hosts value.

None of those scenarios feel right. I’ve seen also that overriding the hosts value with the ansible-playbook is not seen as a good thing ([https://github.com/ansible/ansible/issues/725](https://github.com/ansible/ansible/issues/725) ). But wouldn’t default values for vars be the right solution in this case?

Thanks

Raph

PS: Of course, if you consider that a server should be reinstallable from scratch like it’s needed on EC2, this question doesn’t make sense. But from my understanding ansible doesn’t mean to limit itself to the cloud scenario.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 20, 2015, 1:03pm UTC](https://forum.ansible.com/t/flexible-hosts-value-with-ansible-playbook/17570/2 "2015-02-20T13:03:41Z")

</div>

You CAN use extra vars to set remote\_user and host, if that is what  
you are asking.
