FreeKB - Ansible ignore_errors paramater
Ansible - ignore_errors paramater

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

- 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 an 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.

 

Here is how the ignore_errors parameter could be used.

- name: append 'Hello World' to /tmp/foo.txt
  lineinfile:
    path: /tmp/foo.txt
    line: Hello World
  ignore_errors: true

 

Invoking the playbook could return something like this. Notice the task contains ...ignoring and the play recap has ignore=1.

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

PLAY RECAP
openshift1.software.eng.us : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1

 



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 d5527 in the box below so that we can be sure you are a human.




Comments

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