Sunday, March 18, 2018

Ansible How to Hide Expected Stderr Output


   There are some cases the SHELL scripts we run via ansible, the return code (rc) is not 0
   And it is expected to return non-zero.

   Ansible always output stderr for you which can be annoyed.  ie

TASK [run the script  to get the result] ************************************************************************************************
fatal: []: FAILED! => {"changed": true, "cmd": ". /tmp/ --batch text", "delta": "0:00:01.688319", "end": "2018-03-19 00:36:12.670522", "failed": true, "msg": "non-zero return code", "rc": 2, "start": "2018-03-19 00:36:10.982203", "stderr": 

 We try to hide them


   Use  ignore_errors to continue the ansible yml file without disruption by the failed error

   Use  failed_when to be set as false. It will force the task never to be failed
   Example codes like

- name: run the script  to get the result
     shell: |
           . /tmp/ --batch text
     register: output
     failed_when: false
     ignore_errors: True

Before set  failed_when
"changed": true,
    "cmd": ". /tmp/ --batch text",
    "delta": "0:00:01.724031",
    "end": "2018-03-19 00:55:37.677224",
    "failed": true

After set  failed_when
"changed": true,
    "cmd": ". /tmp/ --batch text",
    "delta": "0:00:01.966887",
    "end": "2018-03-19 00:53:10.673414",
    "failed": false,
    "failed_when_result": false, 

1 comment:

oqft3d7qqy said...

In this technique, a plastic molder horizontally heats sheets of pre-extruded inflexible plastics and sucks them down into hollow one-piece tools. Further, when sizzling plastic solidifies, it gets the final form of the mildew. Structural foam molding is a course of that uses the part materials blended with a foaming agent, which turns into gas as it enters the mildew. Less materials than wanted to fill the cavity is injected into Shower Curtains the mildew and the gas bubbles expand till it fills the cavity. Due to the unpredictable nature of the gas, structural foam parts may not be not|will not be} aesthetically pleasing. Structural foam parts have an uneven floor color; you can to|you presumably can} visibly see tints and shades of the chosen color in a swirl-like sample.