Stop displaying stdout when task fails

20 views
Skip to first unread message

texas living

unread,
Dec 30, 2017, 7:19:48 PM12/30/17
to Ansible Project
I have a task that sends a reboot command to a host, then pings every 10-seconds until a ping has failed. This indicates the hosts has begun the reboot and moves on the a ping every 60-seconds waiting for a ping success indicating the host is back up. It works fine with no issues. The only thing is the fatal output when the ping fails, I would like to stop this from displaying. i have no_logs: true and ignore_errors set already, but can not figure out how to stop the output.

The code snippet:
- name: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure.
  local_action: raw ping -c 1 -W 1 {{vars[inventory_hostname].IP_Address}}
  register: output
  until: output.stdout.find("0 received") != -1
  retries: 12
  delay: 10
  ignore_errors: true

- name: Waiting for Reboot to Complete. Checking Every 60-Seconds for Ping Success.
  local_action: shell ping -c 1 {{vars[inventory_hostname].IP_Address}}
  register: result
  until: result.stdout.find("64 bytes from") != -1
  retries: 15
  delay: 60
  ignore_errors: true

The tasks output, want to suppress the red:
TASK [base_config_oam : Send Reboot Command] ***************************************************************************************
changed: [vsrx-01]

TASK [base_config_oam : Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure.] ************************************
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (12 retries left).
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (11 retries left).
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (10 retries left).
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (9 retries left).
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (8 retries left).
FAILED - RETRYING: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping Failure. (7 retries left).
fatal: [vsrx-01 -> localhost]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"}

STDOUT:

PING 192.168.1.209 (192.168.1.209) 56(84) bytes of data.

--- 192.168.1.209 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms


MSG:

non-zero return code
...ignoring

TASK [base_config_oam : Waiting for Reboot to Complete. Checking Every 60-Seconds for Ping Success.] *******************************
FAILED - RETRYING: Waiting for Reboot to Complete. Checking Every 60-Seconds for Ping Success. (15 retries left).

Kai Stian Olstad

unread,
Dec 31, 2017, 7:20:27 AM12/31/17
to ansible...@googlegroups.com
On Sunday, 31 December 2017 01.19.47 CET texas living wrote:
> I have a task that sends a reboot command to a host, then pings every
> 10-seconds until a ping has failed. This indicates the hosts has begun the
> reboot and moves on the a ping every 60-seconds waiting for a ping success
> indicating the host is back up. It works fine with no issues. The only
> thing is the fatal output when the ping fails, I would like to stop this
> from displaying. i have no_logs: true and ignore_errors set already, but
> can not figure out how to stop the output.
>
> *The code snippet:*
> - name: Pause for Reboot to Begin. Checking Every 10-Seconds for Ping
> Failure.
> local_action: raw ping -c 1 -W 1 {{vars[inventory_hostname].IP_Address}}
> register: output
> until: output.stdout.find("0 received") != -1
> retries: 12
> delay: 10
> ignore_errors: true
>
> - name: Waiting for Reboot to Complete. Checking Every 60-Seconds for Ping
> Success.
> local_action: shell ping -c 1 {{vars[inventory_hostname].IP_Address}}
> register: result
> until: result.stdout.find("64 bytes from") != -1
> retries: 15
> delay: 60
> ignore_errors: true

Why not just use the wait_for_connection[1] module that is designed for this?

[1] https://docs.ansible.com/ansible/latest/wait_for_connection_module.html

--
Kai Stian Olstad
Message has been deleted

texas living

unread,
Dec 31, 2017, 5:08:15 PM12/31/17
to Ansible Project
I was reading about custom callbacks and modified the default stdout_callback module to no display the fatal outputs.
Reply all
Reply to author
Forward
0 new messages