Ansible - vars_prompt

vars_prompt can be used to create a prompt that will define one or more variables. In this example, two variables will be defined, "foo" and "bar". 

---
- hosts: localhost
  vars_prompt:
  - name: foo
    prompt: Please enter a value for the 'foo' variable
    private: no

  - name: bar
    prompt: Please enter a value for the 'bar' variable
    private: yes

  tasks:
  - debug:
      msg: the foo variable contains a value of {{ foo }}

  - debug:
      msg: the bar variable contains a value of {{ bar }}
...

 

AVOID TROUBLE

The -e or --extra-vars command line optionExtra Variables in Tower and set_fact module will take precedence over the vars prompt.

 

Running this playbook should generate prompts. Notice that the bar prompt will not print any output because the bar prompt is private.

Be aware that all though the "bar" variable is private, the value of the "bar" variable will be accessible when running the ansible-playbook command with the -vvv (very verbose) flag.

Please enter a value for the 'foo' variable: Hello
Please enter a value for the 'bar' variable: 

 

Something like this should be returned.

TASK [debug]
ok: [localhost] => {
    "msg": "the foo variable contains a value of Hello"
}

TASK [debug]
ok: [localhost] => {
    "msg": "the bar variable contains a value of World"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 1cbd5 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |