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
90cce359
Commit
90cce359
authored
Oct 30, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
This allows variable references in playbooks in a different way.
parent
b5c9d5a5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletions
+17
-1
lib/ansible/runner/action_plugins/debug.py
+3
-1
lib/ansible/utils/__init__.py
+6
-0
lib/ansible/utils/template.py
+8
-0
No files found.
lib/ansible/runner/action_plugins/debug.py
View file @
90cce359
...
@@ -49,7 +49,9 @@ class ActionModule(object):
...
@@ -49,7 +49,9 @@ class ActionModule(object):
else
:
else
:
result
=
dict
(
msg
=
args
[
'msg'
])
result
=
dict
(
msg
=
args
[
'msg'
])
elif
'var'
in
args
:
elif
'var'
in
args
:
(
intermediate
,
exception
)
=
utils
.
safe_eval
(
args
[
'var'
],
inject
,
include_exceptions
=
True
,
template_call
=
True
)
results
=
utils
.
safe_eval
(
args
[
'var'
],
inject
,
include_exceptions
=
True
,
template_call
=
True
)
intermediate
=
results
[
0
]
exception
=
results
[
1
]
if
exception
is
not
None
:
if
exception
is
not
None
:
intermediate
=
"failed to evaluate:
%
s"
%
str
(
exception
)
intermediate
=
"failed to evaluate:
%
s"
%
str
(
exception
)
result
[
args
[
'var'
]]
=
intermediate
result
[
args
[
'var'
]]
=
intermediate
...
...
lib/ansible/utils/__init__.py
View file @
90cce359
...
@@ -917,11 +917,17 @@ def safe_eval(str, locals=None, include_exceptions=False, template_call=False):
...
@@ -917,11 +917,17 @@ def safe_eval(str, locals=None, include_exceptions=False, template_call=False):
# do not allow method calls to modules
# do not allow method calls to modules
if
not
isinstance
(
str
,
basestring
):
if
not
isinstance
(
str
,
basestring
):
# already templated to a datastructure, perhaps?
# already templated to a datastructure, perhaps?
if
include_exceptions
:
return
(
str
,
None
)
return
str
return
str
if
re
.
search
(
r'\w\.\w+\('
,
str
):
if
re
.
search
(
r'\w\.\w+\('
,
str
):
if
include_exceptions
:
return
(
str
,
None
)
return
str
return
str
# do not allow imports
# do not allow imports
if
re
.
search
(
r'import \w+'
,
str
):
if
re
.
search
(
r'import \w+'
,
str
):
if
include_exceptions
:
return
(
str
,
None
)
return
str
return
str
try
:
try
:
result
=
None
result
=
None
...
...
lib/ansible/utils/template.py
View file @
90cce359
...
@@ -30,6 +30,7 @@ import subprocess
...
@@ -30,6 +30,7 @@ import subprocess
import
datetime
import
datetime
import
pwd
import
pwd
import
ast
import
ast
import
traceback
class
Globals
(
object
):
class
Globals
(
object
):
...
@@ -304,6 +305,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
...
@@ -304,6 +305,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
def
template
(
basedir
,
varname
,
vars
,
lookup_fatal
=
True
,
depth
=
0
,
expand_lists
=
True
,
convert_bare
=
False
,
fail_on_undefined
=
False
,
filter_fatal
=
True
):
def
template
(
basedir
,
varname
,
vars
,
lookup_fatal
=
True
,
depth
=
0
,
expand_lists
=
True
,
convert_bare
=
False
,
fail_on_undefined
=
False
,
filter_fatal
=
True
):
''' templates a data structure by traversing it and substituting for other data structures '''
''' templates a data structure by traversing it and substituting for other data structures '''
from
ansible
import
utils
try
:
try
:
if
convert_bare
and
isinstance
(
varname
,
basestring
):
if
convert_bare
and
isinstance
(
varname
,
basestring
):
...
@@ -314,6 +316,12 @@ def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=Tr
...
@@ -314,6 +316,12 @@ def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=Tr
if
isinstance
(
varname
,
basestring
):
if
isinstance
(
varname
,
basestring
):
if
'{{'
in
varname
or
'{
%
'
in
varname
:
if
'{{'
in
varname
or
'{
%
'
in
varname
:
varname
=
template_from_string
(
basedir
,
varname
,
vars
,
fail_on_undefined
)
varname
=
template_from_string
(
basedir
,
varname
,
vars
,
fail_on_undefined
)
if
(
varname
.
startswith
(
"{"
)
and
not
varname
.
startswith
(
"{{"
))
or
varname
.
startswith
(
"["
):
eval_results
=
utils
.
safe_eval
(
varname
,
locals
=
vars
,
include_exceptions
=
True
)
if
eval_results
[
1
]
is
None
:
varname
=
eval_results
[
0
]
if
not
'$'
in
varname
:
if
not
'$'
in
varname
:
return
varname
return
varname
...
...
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