Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
ebad0d44
Commit
ebad0d44
authored
May 05, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update conditional examples.
parent
1b5dd3f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
26 deletions
+11
-26
examples/playbooks/conditionals_part1.yml
+5
-6
examples/playbooks/conditionals_part2.yml
+6
-20
No files found.
examples/playbooks/conditionals_part1.yml
View file @
ebad0d44
...
...
@@ -29,10 +29,9 @@
vars_files
:
-
"
vars/external_vars.yml"
-
[
"
vars/
$facter_operatingsystem
.yml"
,
"
vars/defaults.yml"
]
-
[
"
vars/
{{
facter_operatingsystem
}}
.yml"
,
"
vars/defaults.yml"
]
# and this is just a regular task line from a playbook, as we're used to.
# but with variables in it that come from above. Note that the variables
...
...
@@ -41,11 +40,11 @@
tasks
:
-
name
:
ensure apache is latest
action
:
$packager pkg=$apache state=latest
action
:
"
{{
packager
}}
pkg={{
apache
}}
state=latest"
-
name
:
ensure apache is running
action
:
service name=$apache state=running
-
name
:
fail
action
:
command /bin/false
action
:
service name={{ apache }} state=running
examples/playbooks/conditionals_part2.yml
View file @
ebad0d44
...
...
@@ -11,44 +11,30 @@
cat
:
"
whiskers"
ssn
:
8675309
# These are the types of when statements available
# when_set: $variable_name
# when_unset: $variable_name
# when_str: $x == "test"
# when_int: $y > 2
# when_float: $z => 2.3
#
# when using 'when', take care to make sure any variables given are surrounded by spaces
# as an example, $z>3 will not do what you want, use "$z > 3"
#
# note, if you are doing comparisons to variables that are stored as hashes or lists,
# you will need to use the older 'only_if', which is more free form.
# see conditionals_part_3.yml
tasks
:
-
name
:
"
do
this
if
my
favcolor
is
blue,
and
my
dog
is
named
fido"
action
:
shell /bin/false
when
_string
:
$favcolor == 'blue' and $
dog == 'fido'
when
:
favcolor == 'blue' and
dog == 'fido'
-
name
:
"
do
this
if
my
favcolor
is
not
blue,
and
my
dog
is
named
fido"
action
:
shell /bin/true
when
_string
:
$favcolor != 'blue' and $
dog == 'fido'
when
:
favcolor != 'blue' and
dog == 'fido'
-
name
:
"
do
this
if
my
SSN
is
over
9000"
action
:
shell /bin/true
when
_integer
:
$
ssn > 9000
when
:
ssn > 9000
-
name
:
"
do
this
if
I
have
one
of
these
SSNs"
action
:
shell /bin/true
when
_integer
:
$
ssn in [ 8675309, 8675310, 8675311 ]
when
:
ssn in [ 8675309, 8675310, 8675311 ]
-
name
:
"
do
this
if
a
variable
named
hippo
is
NOT
defined"
action
:
shell /bin/true
when
_unset
:
$hippo
when
:
hippo is not defined
-
name
:
"
do
this
if
a
variable
named
hippo
is
defined"
action
:
shell /bin/true
when
_set
:
$hippo
when
:
hippo is defined
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment