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
224e20ca
Commit
224e20ca
authored
Apr 25, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complex_arg templating should be smarter. Make it so!
parent
ee4a0fc6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
lib/ansible/runner/__init__.py
+15
-9
lib/ansible/utils/template.py
+8
-1
No files found.
lib/ansible/runner/__init__.py
View file @
224e20ca
...
...
@@ -239,9 +239,8 @@ class Runner(object):
if
not
self
.
environment
:
return
""
enviro
=
template
.
template
(
self
.
basedir
,
self
.
environment
,
inject
)
if
isinstance
(
enviro
,
basestring
)
and
enviro
in
inject
:
enviro
=
inject
[
enviro
]
enviro
=
template
.
template
(
self
.
basedir
,
self
.
environment
,
inject
,
convert_bare
=
True
)
enviro
=
utils
.
safe_eval
(
enviro
)
if
type
(
enviro
)
!=
dict
:
raise
errors
.
AnsibleError
(
"environment must be a dictionary, received
%
s"
%
enviro
)
result
=
""
...
...
@@ -406,15 +405,14 @@ class Runner(object):
# logic to replace complex args if possible
complex_args
=
self
.
complex_args
if
isinstance
(
complex_args
,
basestring
):
if
complex_args
in
inject
:
complex_args
=
inject
[
complex_args
]
else
:
complex_args
=
template
.
template
(
self
.
basedir
,
complex_args
,
inject
)
complex_args
=
utils
.
safe_eval
(
complex_args
)
# logic to decide how to run things depends on whether with_items is used
if
items
is
None
:
if
isinstance
(
complex_args
,
basestring
):
complex_args
=
template
.
template
(
self
.
basedir
,
complex_args
,
inject
,
convert_bare
=
True
)
complex_args
=
utils
.
safe_eval
(
complex_args
)
if
type
(
complex_args
)
!=
dict
:
raise
errors
.
AnsibleError
(
"args must be a dictionary, received
%
s"
%
complex_args
)
return
self
.
_executor_internal_inner
(
host
,
self
.
module_name
,
self
.
module_args
,
inject
,
port
,
complex_args
=
complex_args
)
elif
len
(
items
)
>
0
:
...
...
@@ -428,6 +426,14 @@ class Runner(object):
results
=
[]
for
x
in
items
:
inject
[
'item'
]
=
x
# TODO: this idiom should be replaced with an up-conversion to a Jinja2 template evaluation
if
isinstance
(
complex_args
,
basestring
):
complex_args
=
template
.
template
(
self
.
basedir
,
complex_args
,
inject
,
convert_bare
=
True
)
complex_args
=
utils
.
safe_eval
(
complex_args
)
if
type
(
complex_args
)
!=
dict
:
raise
errors
.
AnsibleError
(
"args must be a dictionary, received
%
s"
%
complex_args
)
result
=
self
.
_executor_internal_inner
(
host
,
self
.
module_name
,
...
...
lib/ansible/utils/template.py
View file @
224e20ca
...
...
@@ -266,9 +266,16 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
return
''
.
join
(
done
)
def
template
(
basedir
,
varname
,
vars
,
lookup_fatal
=
True
,
depth
=
0
,
expand_lists
=
True
):
# TODO: varname is misnamed here
def
template
(
basedir
,
varname
,
vars
,
lookup_fatal
=
True
,
depth
=
0
,
expand_lists
=
True
,
convert_bare
=
False
):
''' templates a data structure by traversing it and substituting for other data structures '''
if
convert_bare
and
isinstance
(
varname
,
basestring
):
first_part
=
varname
.
split
(
"."
)[
0
]
.
split
(
"["
)[
0
]
if
first_part
in
vars
and
'{{'
not
in
varname
and
'$'
not
in
varname
:
varname
=
"{{
%
s}}"
%
varname
if
isinstance
(
varname
,
basestring
):
if
'{{'
in
varname
or
'{
%
'
in
varname
:
varname
=
template_from_string
(
basedir
,
varname
,
vars
)
...
...
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