# pause that fails if it expires

**URL:** <https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690>\
**Category:** Ansible Project\
**Created:** [June 8, 2017, 11:18pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690 "2017-06-08T23:18:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmeyer](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lmeyer](https://forum.ansible.com/u/lmeyer)\
**Post date:** [June 8, 2017, 11:18pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690/1 "2017-06-08T23:18:25Z")

</div>

I’d like to check a condition, then if it’s not good, ask the user if they’d like to continue anyway. And in case the run is not interactive, I’d like the play to fail if they don’t answer within a few minutes.

This would _seem_ like a job for the pause module, but it doesn’t work that way.

Pausing for 60 seconds  
(ctrl+C then ‘C’ = continue early, ctrl+C then ‘A’ = abort)  
Press ‘C’ to continue the play or ‘A’ to abort

I’d like to proceed only if they press ctrl+C + ‘C’ explicitly. However, lack of response is taken as success, and there’s no way I can see to distinguish ctrl-C + ‘C’ from that. I’ve tried:

- hosts: all  
name: pause result  
max\_fail\_percentage: 0  
gather\_facts: False  
tasks:
- pause:  
prompt: “Failed, what do you want to do?”  
minutes: 1  
ignore\_errors: True  
register: pause\_result
- fail:  
msg: “{{ pause\_result.user\_input }}”  
when:
- pause\_result is defined
- pause\_result.user\_input | default(“c”) == “a”

… however the ctrl-C+“C” is not counted as user input.

Is there some other way to do this or is this an RFE?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 9, 2017, 12:35pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690/2 "2017-06-09T12:35:18Z")

</div>

> I'd like to check a condition, then if it's not good, ask the user if  
> they'd like to continue anyway. And in case the run is not interactive, I'd  
> like the play to fail if they don't answer within a few minutes.
> 
> This would \*seem\* like a job for the pause module, but it doesn't work that  
> way.
> 
> Pausing for 60 seconds  
> (ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)  
> Press 'C' to continue the play or 'A' to abort
> 
> I'd like to proceed only if they press ctrl+C + 'C' explicitly. However,  
> lack of response is taken as success, and there's no way I can see to  
> distinguish ctrl-C + 'C' from that. I've tried:

You can use the delta, if delta is \>= the waiting time nobody has done any action.

> - hosts: all  
> &nbsp;&nbsp;name: pause result  
> &nbsp;&nbsp;max\_fail\_percentage: 0  
> &nbsp;&nbsp;gather\_facts: False  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- pause:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Failed, what do you want to do?"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minutes: 1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore\_errors: True  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: pause\_result  
> &nbsp;&nbsp;&nbsp;&nbsp;- fail:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ pause\_result.user\_input }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- pause\_result is defined  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- pause\_result.user\_input | default("c") == "a"
> 
> ... however the ctrl-C+"C" is not counted as user input.
> 
> Is there some other way to do this or is this an RFE?

- fail:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "Aborting because of no interaction"  
&nbsp;&nbsp;&nbsp;when: pause\_result.delta \>= 60

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 9, 2017, 6:21pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690/3 "2017-06-09T18:21:58Z")

</div>

you can probably do it all in one task with failed\_when:

---

<div class="post-metadata">

**Author:** ![lmeyer](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lmeyer](https://forum.ansible.com/u/lmeyer)\
**Post date:** [June 9, 2017, 7:25pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690/4 "2017-06-09T19:25:02Z")

</div>

Thanks, folks, that seems like it will work pretty well.

Now my only problem is that I’d like to first summarize the check results that ran across multiple hosts, then ask the user if they want to proceed anyway. This seems like it might be complicated, not sure if a single task can access previous task results from all the hosts.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 9, 2017, 8:54pm UTC](https://forum.ansible.com/t/pause-that-fails-if-it-expires/24690/5 "2017-06-09T20:54:13Z")

</div>

You could do something like this.

Lets say the summarize/status is in one variable called sum\_stat

- debug: msg="{% for i in ansible\_play\_batch %}{{ i }} has the status: {{ hostvars[i].sum\_stat }}\n{% endfor %}"  
&nbsp;&nbsp;&nbsp;run\_once: true

This will print something like this.

host1 has the status: Failed  
host2 has the status: OK  
...  
and so on
