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
b8e4e59d
Commit
b8e4e59d
authored
Oct 02, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Signatures
parent
daab8e7a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
53 deletions
+4
-53
lib/v2/playbook/conditional.py
+4
-53
No files found.
lib/v2/playbook/conditional.py
View file @
b8e4e59d
...
@@ -20,59 +20,10 @@ from v2.utils import template
...
@@ -20,59 +20,10 @@ from v2.utils import template
from
v2.utils
import
list_union
from
v2.utils
import
list_union
class
Conditional
(
object
):
class
Conditional
(
object
):
def
__init__
(
self
,
basedir
,
conditionals
=
[]):
self
.
basedir
=
basedir
self
.
conditionals
=
conditionals
def
push
(
self
,
conditional
):
def
__init__
(
self
,
task
):
if
conditional
not
in
self
.
conditionals
:
pass
self
.
conditionals
.
append
(
conditional
)
def
get_conditionals
(
self
):
def
evaluate
(
self
,
context
):
# return a full slice to make sure the reference
pass
# doesn't get mangled by other users of the result
return
self
.
conditionals
[:]
def
merge
(
self
,
conditional
):
if
isinstance
(
conditional
,
basestring
):
conditional
=
Conditional
(
self
.
basedir
,
[
conditional
])
elif
isinstance
(
conditional
,
list
):
conditional
=
Conditional
(
self
.
basedir
,
conditional
)
elif
not
isinstance
(
conditional
,
Conditional
):
raise
AnsibleError
(
'expected a Conditional() class, instead got a
%
s'
%
type
(
conditional
))
self
.
conditionals
=
list_union
(
self
.
conditionals
,
conditional
.
get_conditonals
())
def
evaluate
(
self
,
inject
):
for
conditional
in
self
.
conditional
:
if
not
self
.
_do_evaluate
(
conditional
,
inject
):
return
False
return
True
def
_do_evaluate
(
self
,
conditional
,
inject
):
# allow variable names
if
conditional
in
inject
and
'-'
not
in
str
(
inject
[
conditional
]):
conditional
=
inject
[
conditional
]
conditional
=
template
.
template
(
self
.
basedir
,
conditional
,
inject
,
fail_on_undefined
=
C
.
fail_on_undefined
)
original
=
str
(
conditional
)
.
replace
(
"jinja2_compare "
,
""
)
# a Jinja2 evaluation that results in something Python can eval!
presented
=
"{
%%
if
%
s
%%
} True {
%%
else
%%
} False {
%%
endif
%%
}"
%
conditional
conditional
=
template
.
template
(
self
.
basedir
,
presented
,
inject
)
val
=
conditional
.
strip
()
if
val
==
presented
:
# the templating failed, meaning most likely a
# variable was undefined. If we happened to be
# looking for an undefined variable, return True,
# otherwise fail
if
"is undefined"
in
conditional
:
return
True
elif
"is defined"
in
conditional
:
return
False
else
:
raise
errors
.
AnsibleError
(
"error while evaluating conditional:
%
s"
%
original
)
elif
val
==
"True"
:
return
True
elif
val
==
"False"
:
return
False
else
:
raise
errors
.
AnsibleError
(
"unable to evaluate conditional:
%
s"
%
original
)
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