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
8c370645
Commit
8c370645
authored
Sep 28, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1122 from dhozac/varreplace-no-repr
Revert pull request #1091
parents
06cfc52a
4b29c2cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
70 deletions
+4
-70
lib/ansible/runner/__init__.py
+1
-1
lib/ansible/utils.py
+3
-10
test/TestUtils.py
+0
-59
No files found.
lib/ansible/runner/__init__.py
View file @
8c370645
...
@@ -323,7 +323,7 @@ class Runner(object):
...
@@ -323,7 +323,7 @@ class Runner(object):
new_args
=
new_args
+
"
%
s='
%
s' "
%
(
k
,
v
)
new_args
=
new_args
+
"
%
s='
%
s' "
%
(
k
,
v
)
module_args
=
new_args
module_args
=
new_args
conditional
=
utils
.
template
(
self
.
basedir
,
self
.
conditional
,
inject
,
do_repr
=
True
)
conditional
=
utils
.
template
(
self
.
basedir
,
self
.
conditional
,
inject
)
if
not
utils
.
check_conditional
(
conditional
):
if
not
utils
.
check_conditional
(
conditional
):
result
=
utils
.
jsonify
(
dict
(
skipped
=
True
))
result
=
utils
.
jsonify
(
dict
(
skipped
=
True
))
self
.
callbacks
.
on_skipped
(
host
,
inject
.
get
(
'item'
,
None
))
self
.
callbacks
.
on_skipped
(
host
,
inject
.
get
(
'item'
,
None
))
...
...
lib/ansible/utils.py
View file @
8c370645
...
@@ -289,7 +289,7 @@ def varLookup(varname, vars):
...
@@ -289,7 +289,7 @@ def varLookup(varname, vars):
except
VarNotFoundException
:
except
VarNotFoundException
:
return
None
return
None
def
varReplace
(
raw
,
vars
,
d
o_repr
=
False
,
d
epth
=
0
):
def
varReplace
(
raw
,
vars
,
depth
=
0
):
''' Perform variable replacement of $variables in string raw using vars dictionary '''
''' Perform variable replacement of $variables in string raw using vars dictionary '''
# this code originally from yum
# this code originally from yum
...
@@ -315,13 +315,6 @@ def varReplace(raw, vars, do_repr=False, depth=0):
...
@@ -315,13 +315,6 @@ def varReplace(raw, vars, do_repr=False, depth=0):
replacement
=
raw
[
m
[
'start'
]:
m
[
'end'
]]
replacement
=
raw
[
m
[
'start'
]:
m
[
'end'
]]
start
,
end
=
m
[
'start'
],
m
[
'end'
]
start
,
end
=
m
[
'start'
],
m
[
'end'
]
if
do_repr
:
replacement
=
repr
(
replacement
)
if
(
start
>
0
and
((
raw
[
start
-
1
]
==
"'"
and
raw
[
end
]
==
"'"
)
or
(
raw
[
start
-
1
]
==
'"'
and
raw
[
end
]
==
'"'
))):
start
-=
1
end
+=
1
done
.
append
(
raw
[:
start
])
# Keep stuff leading up to token
done
.
append
(
raw
[:
start
])
# Keep stuff leading up to token
done
.
append
(
unicode
(
replacement
))
# Append replacement value
done
.
append
(
unicode
(
replacement
))
# Append replacement value
raw
=
raw
[
end
:]
# Continue with remainder of string
raw
=
raw
[
end
:]
# Continue with remainder of string
...
@@ -363,7 +356,7 @@ def varReplaceFilesAndPipes(basedir, raw):
...
@@ -363,7 +356,7 @@ def varReplaceFilesAndPipes(basedir, raw):
return
''
.
join
(
done
)
return
''
.
join
(
done
)
def
template
(
basedir
,
text
,
vars
,
do_repr
=
False
):
def
template
(
basedir
,
text
,
vars
):
''' run a text buffer through the templating engine until it no longer changes '''
''' run a text buffer through the templating engine until it no longer changes '''
prev_text
=
''
prev_text
=
''
...
@@ -371,7 +364,7 @@ def template(basedir, text, vars, do_repr=False):
...
@@ -371,7 +364,7 @@ def template(basedir, text, vars, do_repr=False):
text
=
text
.
decode
(
'utf-8'
)
text
=
text
.
decode
(
'utf-8'
)
except
UnicodeEncodeError
:
except
UnicodeEncodeError
:
pass
# already unicode
pass
# already unicode
text
=
varReplace
(
unicode
(
text
),
vars
,
do_repr
)
text
=
varReplace
(
unicode
(
text
),
vars
)
text
=
varReplaceFilesAndPipes
(
basedir
,
text
)
text
=
varReplaceFilesAndPipes
(
basedir
,
text
)
return
text
return
text
...
...
test/TestUtils.py
View file @
8c370645
...
@@ -202,65 +202,6 @@ class TestUtils(unittest.TestCase):
...
@@ -202,65 +202,6 @@ class TestUtils(unittest.TestCase):
assert
res
==
'hello world'
assert
res
==
'hello world'
def
test_varReplace_repr_basic
(
self
):
vars
=
{
'color'
:
'$favorite_color'
,
'favorite_color'
:
'blue'
,
}
template
=
'$color == "blue"'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
do_repr
=
True
)
assert
eval
(
res
)
def
test_varReplace_repr_varinvar
(
self
):
vars
=
{
'foo'
:
'foo'
,
'bar'
:
'bar'
,
'foobar'
:
'$foo$bar'
,
'var'
:
{
'foo'
:
'foo'
,
'foobar'
:
'$foo$bar'
,
},
}
template
=
'$foobar == "foobar"'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
do_repr
=
True
)
assert
eval
(
res
)
def
test_varReplace_repr_varindex
(
self
):
vars
=
{
'foo'
:
'foo'
,
'var'
:
{
'foo'
:
'bar'
,
},
}
template
=
'${var.$foo} == "bar"'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
do_repr
=
True
)
assert
eval
(
res
)
def
test_varReplace_repr_varpartindex
(
self
):
vars
=
{
'foo'
:
'foo'
,
'var'
:
{
'foobar'
:
'foobar'
,
},
}
template
=
'${var.${foo}bar} == "foobar"'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
do_repr
=
True
)
assert
eval
(
res
)
def
test_varReplace_repr_nonstr
(
self
):
vars
=
{
'foo'
:
True
,
'bar'
:
1L
,
}
template
=
'${foo} == $bar'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
do_repr
=
True
)
assert
res
==
'True == 1L'
def
test_varReplace_consecutive_vars
(
self
):
def
test_varReplace_consecutive_vars
(
self
):
vars
=
{
vars
=
{
'foo'
:
'foo'
,
'foo'
:
'foo'
,
...
...
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