Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Ansible ignore failed tarball extraction?

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.

like image 779
bcmcfc Avatar asked Mar 12 '15 15:03

bcmcfc


People also ask

How do you ignore failure in Ansible?

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

How do you execute a failed playbook again?

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

What happens when one task is failed in playbook?

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.


1 Answers

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.

like image 86
udondan Avatar answered Oct 16 '22 23:10

udondan