mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add demonstration of only_if capability
This commit is contained in:
parent
dfbe591cc0
commit
54b98effdf
1 changed files with 25 additions and 0 deletions
25
examples/playbooks/playbook4.yml
Normal file
25
examples/playbooks/playbook4.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
# this is a demo of conditional executions using 'only_if', which can skip
|
||||||
|
# certain tasks on machines/platforms/etc where they do not apply.
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
user: root
|
||||||
|
|
||||||
|
vars:
|
||||||
|
favcolor: "red"
|
||||||
|
ssn: 8675309
|
||||||
|
|
||||||
|
# facter and ohai variables can be used in only_if statements too
|
||||||
|
# ex: "$facter_operatingsystem == 'CentOS'", which bubble up automatically
|
||||||
|
# from the managed machines
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: "do this if my favcolor is blue"
|
||||||
|
action: shell /bin/false
|
||||||
|
only_if: "'$favcolor' == 'blue'"
|
||||||
|
|
||||||
|
- name: "do this if my favcolor is red"
|
||||||
|
action: shell /bin/false
|
||||||
|
only_if: "'$favcolor' == 'red'"
|
||||||
|
|
Loading…
Reference in a new issue