FreeKB - Ansible meta clear_host_errors (continue fail fatal)
Ansible - meta clear_host_errors (continue fail fatal)

The meta module with clear_host_errors can be used to clear fatal and fail errors.

The ansible-doc meta command can be used to show the Ansible documention on the meta module.

Let's say /tmp/foo.txt does not exist on a managed node (e.g. target systems), and you attempt to append "Hello World" to /tmp/foo.txt using the lineinfile module.

---
- hosts: all
  tasks:
    - name: append 'Hello World' to /tmp/foo.txt
      lineinfile:
        path: /tmp/foo.txt
        line: Hello World

 

When the target file does not exist, invoking this playbook will return a fatal error, like this.

TASK [append 'Hello World' to /tmp/foo.txt] 
fatal: [server1.example.com]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Destination /tmp/foo.txt does not exist !", "rc": 257}

 

There are a few ways to approach this.

  • Use the --check command line flag to run the playbook in a dry run mode
  • Use the check_mode parameter to determine if the lineinfile module will return an error
  • Use the ignore_errors parameter can be used.
  • Use the meta: clear_host_errors parameter (that is what is described in this article)
  • Use the stat module to determine if /tmp/foo.txt exists and the when parameter to skip the lineinfile module if /tmp/foo.txt does not exist.
  • Use the stat module to determine if /tmp/foo.txt exists and then use the file module and the when parameter to create /tmp/foo.txt if the file does not exist

 

The meta module with clear_host_errors will change this behavior, so that server1.example.com is processed in the subsequent tasks.

---
- hosts: all
  tasks:
    - name: append 'Hello World' to /tmp/foo.txt
      lineinfile:
        path: /tmp/foo.txt
        line: Hello World

    - meta: clear_host_errors

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 902da in the box below so that we can be sure you are a human.




Comments


September 29th, 2019 by Tony
Good afternoon. I am planning to buy one of these thinclients: https ://thinclientbenefits.com/products/wyse-5070 the "Extended" option. But need to know if I can install a Linux distro on it (for example TinyCorePlus by following your walkthru, or the procedure does not apply anymore to newer thinclient generations? If that is the case, what can you suggest I should do? I plan to use the machine as an HTPC, so I NEED to get rid of the thinclient's OS and install a "household" :P OS, so any suggestion will be welcome. Thank you for your attention.

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |