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
c8fc353b
Commit
c8fc353b
authored
Jan 18, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1811 from fdavis/devel
add when_{failed,changed}, and extended when_{set,unset}
parents
1721357a
fe310dcf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
lib/ansible/utils/__init__.py
+28
-3
No files found.
lib/ansible/utils/__init__.py
View file @
c8fc353b
...
...
@@ -137,6 +137,11 @@ def is_failed(result):
return
((
result
.
get
(
'rc'
,
0
)
!=
0
)
or
(
result
.
get
(
'failed'
,
False
)
in
[
True
,
'True'
,
'true'
]))
def
is_changed
(
result
):
''' is a given JSON result a changed result? '''
return
(
result
.
get
(
'changed'
,
False
)
in
[
True
,
'True'
,
'true'
])
def
check_conditional
(
conditional
):
def
is_set
(
var
):
...
...
@@ -485,6 +490,8 @@ def compile_when_to_only_if(expression):
# when: set $variable
# when: unset $variable
# when: failed $json_result
# when: changed $json_result
# when: int $x >= $z and $y < 3
# when: int $x in $alist
# when: float $x > 2 and $y <= $z
...
...
@@ -498,9 +505,27 @@ def compile_when_to_only_if(expression):
# when_set / when_unset
if
tokens
[
0
]
in
[
'set'
,
'unset'
]:
if
len
(
tokens
)
!=
2
:
raise
errors
.
AnsibleError
(
"usage: when: <set|unset> <$variableName>"
)
return
"is_
%
s('''
%
s''')"
%
(
tokens
[
0
],
tokens
[
1
])
tcopy
=
tokens
[
1
:]
for
(
i
,
t
)
in
enumerate
(
tokens
[
1
:]):
if
t
.
find
(
"$"
)
!=
-
1
:
tcopy
[
i
]
=
"is_
%
s('''
%
s''')"
%
(
tokens
[
0
],
t
)
else
:
tcopy
[
i
]
=
t
return
" "
.
join
(
tcopy
)
# when_failed / when_changed
elif
tokens
[
0
]
in
[
'failed'
,
'changed'
]:
tcopy
=
tokens
[
1
:]
for
(
i
,
t
)
in
enumerate
(
tokens
[
1
:]):
if
t
.
find
(
"$"
)
!=
-
1
:
tcopy
[
i
]
=
"is_
%
s(
%
s)"
%
(
tokens
[
0
],
t
)
else
:
tcopy
[
i
]
=
t
return
" "
.
join
(
tcopy
)
# when_integer / when_float / when_string
elif
tokens
[
0
]
in
[
'integer'
,
'float'
,
'string'
]:
...
...
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