xxxxxxxxxx
- name: Confirm important file deletion
pause:
prompt: "Are you sure you want to delete backup.db? (yes/no)"
register: confirm_delete
- name: Delete backup file
file:
path: /home/admin/backup.db
state: absent
when: confirm_delete.user_input | bool
xxxxxxxxxx
- name: Exterminate mankind
pause:
prompt: Please confirm you want to exterminate mankind! Press return to continue. Press Ctrl+c and then "a" to abort
xxxxxxxxxx
A good way to achieve prompt for each task without modifying the playbook itself is to use the --step option of ansible-playbook command. This will allow you to confirm each step before it is run. You have options here to select (N)o/(y)es/(c)ontinue. N skips this step, y runs the step and c continues the rest of the playbook without further prompting (useful when you're debugging and are past the troublesome place.) Note that also works fine with the --check option.
xxxxxxxxxx
---
- name: A sample playbook showing that prompt displaying the variable values
hosts: localhost
gather_facts: False
tasks:
- name: "Prompt for user response"
user_prompt:
prompt: "Do you want to continue with {{action}} of {{user}} user?(y/n)?"
passing_response: ['y','yes']
abort_response: ['n','no']
vars:
action: "deletion"
user: "foobar"
- name: "Task next to the prompt"
debug:
msg: "DELETING THE USER OH!!"