mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 11:10:21 -07:00
Merge pull request #3805 from lwade/docs
Modified playbooks2.rst to include conditional boolean example.
This commit is contained in:
commit
220cc75cd9
1 changed files with 19 additions and 0 deletions
|
@ -338,8 +338,27 @@ Tip: Sometimes you'll get back a variable that's a string and you'll want to do
|
||||||
- shell: echo "only on Red Hat 6, derivatives, and later"
|
- shell: echo "only on Red Hat 6, derivatives, and later"
|
||||||
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int >= 6
|
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int >= 6
|
||||||
|
|
||||||
|
Note the above example requires the lsb_release package on the target host in order to return the ansible_lsb.major_release fact.
|
||||||
|
|
||||||
Variables defined in the playbooks or inventory can also be used.
|
Variables defined in the playbooks or inventory can also be used.
|
||||||
|
|
||||||
|
An example may be the execution of a task based on a variable's boolean value::
|
||||||
|
|
||||||
|
vars:
|
||||||
|
epic: true
|
||||||
|
|
||||||
|
Then a conditional execution with action on the boolean value of epic being True::
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- shell: echo "This certainly is epic!"
|
||||||
|
when: epic
|
||||||
|
|
||||||
|
With a boolean value of False::
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- shell: echo "This certainly isn't epic!"
|
||||||
|
when: not epic
|
||||||
|
|
||||||
If a required variable has not been set, you can skip or fail using Jinja2's
|
If a required variable has not been set, you can skip or fail using Jinja2's
|
||||||
`defined` test. For example::
|
`defined` test. For example::
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue