# Prompting for hosts

**URL:** <https://forum.ansible.com/t/prompting-for-hosts/13896>\
**Category:** Ansible Project\
**Created:** [November 12, 2013, 11:38pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896 "2013-11-12T23:38:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 12, 2013, 11:38pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896/1 "2013-11-12T23:38:50Z")

</div>

Hi All,

Trying to do something like:

- vars\_prompt:

- name: server  
prompt: “Hostname of the server”  
private: no

- hosts: “{{ server }}”  
tasks:  
debug: msg=“Host is {{ inventory\_hostname }}”

The host that I run the playbook against is dynamic, so I want to be able to either specify it via “-e” or prompt for it. Is this possible?

Error message is:

**ERROR: hosts declaration is required**

Thanks.  
GS

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 12, 2013, 11:44pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896/2 "2013-11-12T23:44:02Z")

</div>

you can do:

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 12, 2013, 11:51pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896/3 "2013-11-12T23:51:23Z")

</div>

Thanks Brian. Since I can’t prompt for it and I can’t figure out a way to validate that {{ target }} is set, I’ve gone with:

- name: “Make sure you specify -e "target=" on the command line for this playbook!”  
hosts: “{{ target }}”  
tasks:  
debug: msg=“Host is {{ inventory\_hostname }}”

Thanks  
GS

---

<div class="post-metadata">

**Author:** ![Heret1qu3](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@Heret1qu3](https://forum.ansible.com/u/Heret1qu3)\
**Post date:** [November 14, 2013, 4:51pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896/4 "2013-11-14T16:51:38Z")

</div>

You can use ansible-playbook playbook.yml --limit host1,host2

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 15, 2013, 5:32pm UTC](https://forum.ansible.com/t/prompting-for-hosts/13896/5 "2013-11-15T17:32:50Z")

</div>

Limit is definitely cleaner though if omitted realize it will target everything by design.

– Michael
