pause that fails if it expires

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?

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
  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?

- fail:
     msg: "Aborting because of no interaction"
   when: pause_result.delta >= 60

you can probably do it all in one task with failed_when:

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.

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 %}"
   run_once: true

This will print something like this.

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