I have a command in an ansible playbook:
- name: extract the tarball
command: tar --ignore-command-error -xvkf release.tar
It is expected that some files won't be extracted as they exist already (-k
flag).
However, this results in ansible stopping the overall playbook as there is an error code from the tar extraction.
How can I work around this? As you can see I have tried --ignore-command-error
to no avail.
Ignoring failed commands By default Ansible stops executing tasks on a host when a task fails on that host. You can use ignore_errors to continue on in spite of the failure. The ignore_errors directive only works when the task is able to run and returns a value of 'failed'.
To start executing your playbook at a particular task (usually the task that failed on the previous run), use the --start-at-task option. In this example, Ansible starts executing your playbook at a task named “install packages”.
Handlers and Failure If a task later on in the same play fails, the service will not be restarted despite the configuration change. You can change this behavior with the --force-handlers command-line option, or by including force_handlers: True in a play, or force_handlers = True in ansible.
ignore_errors: yes
will still raise an error showing the failed task on the prompt. If you want that task to fail silently, you can set failed_when: false
or more sophisticated condition like described in the manual:
- name: this command prints FAILED when it fails
command: /usr/bin/example-command -x -y -z
register: command_result
failed_when: "'FAILED' in command_result.stderr"
So you could search the output of stderr
. You maybe still want to fail if the file is not readable, not exists or whatever, but not fail when the archive is broken and can't be extracted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With