Reputation: 26785
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.
Upvotes: 13
Views: 16907
Reputation: 24603
You want to use the ignore_errors
argument:
- name: extract the tarball
command: tar --ignore-command-error -xvkf release.tar
ignore_errors: yes
See "Ignore Failed Commands" in the Error Handling documentation page.
ignore_errors
works best when you can detect success in some manner- you can register
the output and check that, or you can use creates
to look for a specific filename.
Upvotes: 32
Reputation: 59989
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.
Upvotes: 10