Is it possible to include the value of an existing variable in the message output by vars_prompt
?
I am looking to do something like this:
- hosts: production
vars_prompt:
confirm: "This playbook is configured to act on all $hosts hosts, please confirm"
...where the question printed by vars_prompt
should be:
"This playbook is configured to act on all **production** hosts, please confirm"
This is not exactly answering the question, as what I tried to achieve apparently is not possible using the current stable version of Ansible, but I would like to describe a workaround that helped my solve my use case:
First of all, the reason I wanted to output the hosts
from the playbook inside a vars_prompt
message was to make sure that the playbook would never be run on hosts it was not intended for. The playbook sets up backup for a VM, and while its actions are idempotent, only some of my VMs require backups in the first place. So I wrote the playbook to automate installation of a backup client on a VM and to configure the new client on a central backup server.
What I did to make sure that I only ever run this playbook for the intended host was to make the hosts
parameter in the playbook itself a variable, like this:
- hosts: '{{ host }}'
Now the playbook will fail immediately, if no host is specified on the command line. The way to specify such a variable on the command line is this:
ansible-playbook --extra-vars="host=HOSTNAME" playbook.yml
This is not possible, at least as recently as ansible version 1.4.4. The vars_prompt displays literally exactly what is within the quotes, so any $, {{ }}, etc. is displayed exactly as entered.
It might be worth submitting a feature request for this by posting at https://github.com/ansible/ansible/issues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With