Prompting for hosts

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

you can do:

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

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

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

– Michael