mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Explain when statements with |failure and |success.
This commit is contained in:
parent
c4a125e6d9
commit
7f0e89a2f6
1 changed files with 14 additions and 0 deletions
|
@ -284,6 +284,20 @@ Don't panic -- it's actually pretty simple::
|
||||||
action: command /sbin/shutdown -t now
|
action: command /sbin/shutdown -t now
|
||||||
when: ansible_os_family == "Debian"
|
when: ansible_os_family == "Debian"
|
||||||
|
|
||||||
|
A number of Jinja2 "filters" can also be used in when statements, some of which are unique
|
||||||
|
and provided by ansible. Suppose we want to ignore the error of one statement and then
|
||||||
|
decide to do something conditionally based on success or failure::
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- action: command /bin/false
|
||||||
|
register: result
|
||||||
|
ignore_errors: True
|
||||||
|
- action: command /bin/something
|
||||||
|
when: result|failed
|
||||||
|
- action: command /bin/something_else
|
||||||
|
when: result|sucess
|
||||||
|
|
||||||
|
|
||||||
As a reminder, to see what derived variables are available, you can do::
|
As a reminder, to see what derived variables are available, you can do::
|
||||||
|
|
||||||
ansible hostname.example.com -m setup
|
ansible hostname.example.com -m setup
|
||||||
|
|
Loading…
Reference in a new issue