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
da90c5f7
Commit
da90c5f7
authored
Nov 26, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document 'when' and tweak the code to be a little more comprehensive on what is false.
parent
08b3c77d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
+42
-1
docsite/rst/playbooks2.rst
+41
-0
lib/ansible/playbook/task.py
+1
-1
No files found.
docsite/rst/playbooks2.rst
View file @
da90c5f7
...
...
@@ -288,6 +288,47 @@ While `only_if` is a pretty good option for advanced users, it exposes more guts
we can do better. In 0.9, we will be adding `when`, which will be like a syntactic sugar for `only_if` and hide
this level of complexity -- it will numerous built in operators.
Conditional Execution (Simplified)
``````````````````````````````````
In Ansible 0.9, we realized that only_if was a bit syntactically complicated, and exposed too much Python
to the user. As a result, the 'when' set of keywords was added. The 'when' statements do not have
to be quoted or casted to specify types, but you should seperate any variables used with whitespace. In
most cases users will be able to use 'when', but for more complex cases, only_if may still be required.
Here are various examples of 'when' in use. 'when' is incompatible with 'only_if' in the same task::
- 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'
- 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'
- name: "do this if my SSN is over 9000"
action: shell /bin/true
when_integer: $ssn > 9000
- name: "do this if I have one of these SSNs"
action: shell /bin/true
when_integer: $ssn in [ 8675309, 8675310, 8675311 ]
- name: "do this if a variable named hippo is NOT defined"
action: shell /bin/true
when_unset: $hippo
- name: "do this if a variable named hippo is defined"
action: shell /bin/true
when_set: $hippo
- name: "do this if a variable named hippo is true"
action: shell /bin/true
when_boolean: $hippo
The when_boolean check will look for variables that look to be true as well, such as the string 'True' or
'true', non-zero numbers, and so on.
Conditional Imports
```````````````````
...
...
lib/ansible/playbook/task.py
View file @
da90c5f7
...
...
@@ -232,7 +232,7 @@ class Task(object):
tcopy
=
tokens
[
1
:]
for
(
i
,
t
)
in
enumerate
(
tcopy
):
if
t
.
find
(
"$"
)
!=
-
1
:
tcopy
[
i
]
=
"(is_set('''
%
s''') and '''
%
s'''.lower() not in ('false', 'none', '0', ''))"
%
(
t
,
t
)
tcopy
[
i
]
=
"(is_set('''
%
s''') and '''
%
s'''.lower() not in ('false', 'no
', 'n', 'no
ne', '0', ''))"
%
(
t
,
t
)
return
" "
.
join
(
tcopy
)
else
:
...
...
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