Interactive prompt for one or more commands in a playbook

409 views
Skip to first unread message

Josh Karki

unread,
Aug 4, 2021, 5:43:23 PM8/4/21
to Ansible Project
For example, 

show interface status
show version 
show ip route 

how can a module be written in Ansible to prompt user for the show command to type in when running a playbook. If entered one command (show interface status) and matched, print the output and ignore the rest other commands. If no match found, print default msg : "command not found" or  something like that. 

I am noob to Ansible. 

Thanks for your help!


Brian Coca

unread,
Aug 5, 2021, 10:51:07 AM8/5/21
to Ansible Project
I would use vars_prompt and feed that data to the module or you can
use the pause action
(https://docs.ansible.com/ansible-core/2.11/collections/ansible/builtin/pause_module.html)

But a normal module cannot prompt the user, they are designed to be
executed on the remote.



--
----------
Brian Coca

Roland Müller

unread,
Aug 5, 2021, 5:47:11 PM8/5/21
to Ansible Project
If you just want to execute task by task and press OK for continuing you could use the step mode by adding --step to the ansible-playbook command.

This way ansible-playbook will ask before every task to execute it (=y) skip it (=n) or continue without stepping (=c).

Perform task: configure ssh (y/n/c):


$ ansible-playbook playbook.yml --step

However, - as Brian already pointed out - providing additional information during execution of the playbook is not supported.
Reply all
Reply to author
Forward
0 new messages