title: How to set a Ansible extra variable to answer a pause prompt in a playbook
body: <p>We use an Ansible playbook for running a few commands like <code>version_get</code>, <code>device_status</code> on the target machine. Intentionally we have restricted <code>reboot</code> option from being executed. But occasionally, we would like to automatically answer the <code>yes</code> prompt by setting some variables in the <code>--extra-vars</code> option.</p>
  
  <p>A simple representation of our playbook minimized to run on localhost. </p>
  
  <pre><code>---
   - hosts: localhost
     gather_facts: no
     tasks:
     - name: Confirm Execution
       pause:
         prompt: "You are about to execute a '{{cmd}}' command on the device. Enter 'yes' to proceed"
       register: pause_result
       run_once: True
       when: not (cmd|regex_search('(get|status)'))
     - meta: end_play
       when: pause_result.user_input|default('yes') != 'yes'
  </code></pre>
  
  <p>I know I can add <code>reboot</code> as part of the existing <code>get|status</code> list, but I don't want to do that, because I want the users exercise special precaution when running it. So with the current code as above, if I run <code>reboot</code> I'm left with a prompt like</p>
  
  <pre><code>$ ansible-playbook loc.yml  -e 'cmd=reboot'
   [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
  
  
  PLAY [localhost] ***********************************************************************************************************************************************************
  
  TASK [Confirm Execution] ***************************************************************************************************************************************************
  [Confirm Execution]
  You are about to execute a 'reboot' command on this device. Enter 'yes' to proceed:
  </code></pre>
  
  <p>I just know how to set a variable to automatically answer this prompt. Tried passing <code>echo yes |</code> to the playbook and seeing an error as</p>
  
  <pre><code>$ echo yes | ansible-playbook loc.yml  -e 'cmd=reboot'
  
  [WARNING]: Not waiting for response to prompt as stdin is not interactive
  </code></pre>
  
  <p>I also tried to pass the <code>--extra-vars</code> as below but none of them seemed to work</p>
  
  <pre><code>-e 'cmd=reboot {"pause_result": "yes"}'
  -e 'cmd=reboot pause_result=yes'
  </code></pre>