Sunday, December 16, 2018

failed_when directive in ansible



failed_when directive in ansible:

1.
You can mention something specific in failed_when directive which mentions what output(stdout) causes the failure.

Or

2.
you can altogether ignore the failure using failed_when set as "False".

============================================

1.
While creating users you can use something like:

failed_when: "'Password missing' in result.stdout"




2.
failed_when: False

Even if the command fails, do not exit and proceed further.


p1.yml
===================
---
- hosts: webservers
  tasks:
  - name: install tftp
    yum: pkg=tftp state=installed
    failed_when: False

===================


# cat inventory_simple
[webservers]
gant



#ansible-playbook -i inventory_simple       -s  p1.yml


So, even if tftp installation fails(for some reason) proceed further. Do not error out.
--

When the rc value is not 0 not 1 and something else, then fail 
    failed_when: ( results.rc not in [ 0, 1 ] )
--


No comments:

Post a Comment