Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there some Ansible equivalent to "failed_when" for success

Tags:

linux

ansible

Looking at the documentation about error handling Ansible error handling

I only see a way to fail the provisioning fail_when, i am wondering if there is any way to do the oposite.

something that looks like this:

- name: ping pong redis
  command: redis-cli ping
  register: command_result
  success_when: "'PONG' in command_result.stderr"

Thanks.

like image 482
Gleeb Avatar asked Jan 06 '15 09:01

Gleeb


2 Answers

There seem to be no such feature, at least my suggestion on the mailing list remained unresponded:

https://groups.google.com/forum/#!topic/ansible-project/cIaQTmY3ZLE

What might help is to know that failed_when behaves differently to its semantics:

- name: ping pong redis
  command: redis-cli ping
  register: command_result
  failed_when: 
    - "'PONG' not in command_result.stderr"
    - "command_result.rc != 0"

will not fail if return code is 0 and there is no 'PONG' in stderr. So it passes if any of the list is False

like image 114
ProfHase85 Avatar answered Sep 22 '22 11:09

ProfHase85


I think maybe assert module is what you want.

New in version 1.5

Examples:

- assert: { that: "ansible_os_family != 'RedHat'" }
like image 33
Max Avatar answered Sep 24 '22 11:09

Max