top of page

Ansible vars_prompt

In most of scenario you need a input from user to decide how the playbook should execute.

When running a playbook, you may wish to prompt the user for certain input, and can do so with the ‘vars_prompt’ section.

Mostly this is use when you want to feed different version of application/programs or a password of user. Ansible has a module called prompt which prompt user to feed the value.

So lets see practically how this works, In this example I am going to show you how to prompt for username and password during playbook run.

[root@siddhesh ~]# cat prompt.yml
- hosts: localhost
  gather_facts: False
    - name: "Username"
      prompt: "Please enter your username?"
    - name: "Password"
      prompt: "Please enter your password?"
    - name: Test case of prompt
         - "Welcome {{ Username }}"
         - "Your Password is {{ Password }}"
[root@siddhesh ~]#

Here :

In above playbook I have prompt module to capture value of username and password in Username & Password variable.

Now lets see the output of this playbook execution.

[root@siddhesh ~]# ansible-playbook prompt.yml
Please enter your username?:
Please enter your password?:

PLAY [localhost] ****************************************************************************************************************************************************

TASK [Test case of prompt] ******************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "Welcome siddhesh",
        "Your Password is Sid@123"

PLAY RECAP **********************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0

[root@siddhesh ~]#

As you can see while playing this book, it prompt to feed username and password. You can also unmask details entered by user by setting private to false.


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page