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
96e54080
Commit
96e54080
authored
Nov 12, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1607 from dhozac/j2-templated-vars
Templating fixes and features
parents
df458fb3
25a8787e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
91 deletions
+126
-91
lib/ansible/utils/template.py
+99
-64
test/TestPlayBook.py
+1
-1
test/TestUtils.py
+26
-26
No files found.
lib/ansible/utils/template.py
View file @
96e54080
This diff is collapsed.
Click to expand it.
test/TestPlayBook.py
View file @
96e54080
...
@@ -202,7 +202,7 @@ class TestPlaybook(unittest.TestCase):
...
@@ -202,7 +202,7 @@ class TestPlaybook(unittest.TestCase):
assert
utils
.
jsonify
(
expected
,
format
=
True
)
==
utils
.
jsonify
(
actual
,
format
=
True
)
assert
utils
.
jsonify
(
expected
,
format
=
True
)
==
utils
.
jsonify
(
actual
,
format
=
True
)
assert
len
(
EVENTS
)
==
44
assert
len
(
EVENTS
)
==
60
def
test_includes
(
self
):
def
test_includes
(
self
):
pb
=
os
.
path
.
join
(
self
.
test_dir
,
'playbook-includer.yml'
)
pb
=
os
.
path
.
join
(
self
.
test_dir
,
'playbook-includer.yml'
)
...
...
test/TestUtils.py
View file @
96e54080
...
@@ -15,14 +15,14 @@ class TestUtils(unittest.TestCase):
...
@@ -15,14 +15,14 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
def
test_varReplace_trailing_dollar
(
self
):
def
test_varReplace_trailing_dollar
(
self
):
template
=
'$what $who $'
template
=
'$what $who $'
vars
=
dict
(
what
=
'hello'
,
who
=
'world'
)
vars
=
dict
(
what
=
'hello'
,
who
=
'world'
)
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world $'
assert
res
==
'hello world $'
def
test_varReplace_multiple
(
self
):
def
test_varReplace_multiple
(
self
):
...
@@ -32,7 +32,7 @@ class TestUtils(unittest.TestCase):
...
@@ -32,7 +32,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -42,7 +42,7 @@ class TestUtils(unittest.TestCase):
...
@@ -42,7 +42,7 @@ class TestUtils(unittest.TestCase):
'whoVar'
:
'world'
,
'whoVar'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
print
res
print
res
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -52,7 +52,7 @@ class TestUtils(unittest.TestCase):
...
@@ -52,7 +52,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world!'
assert
res
==
'hello world!'
...
@@ -62,7 +62,7 @@ class TestUtils(unittest.TestCase):
...
@@ -62,7 +62,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -72,7 +72,7 @@ class TestUtils(unittest.TestCase):
...
@@ -72,7 +72,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world}'
assert
res
==
'hello world}'
...
@@ -82,7 +82,7 @@ class TestUtils(unittest.TestCase):
...
@@ -82,7 +82,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
template
assert
res
==
template
...
@@ -92,7 +92,7 @@ class TestUtils(unittest.TestCase):
...
@@ -92,7 +92,7 @@ class TestUtils(unittest.TestCase):
'who'
:
'world'
,
'who'
:
'world'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world }'
assert
res
==
'hello world }'
...
@@ -104,7 +104,7 @@ class TestUtils(unittest.TestCase):
...
@@ -104,7 +104,7 @@ class TestUtils(unittest.TestCase):
},
},
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
print
res
print
res
assert
res
==
template
assert
res
==
template
...
@@ -117,7 +117,7 @@ class TestUtils(unittest.TestCase):
...
@@ -117,7 +117,7 @@ class TestUtils(unittest.TestCase):
},
},
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -130,7 +130,7 @@ class TestUtils(unittest.TestCase):
...
@@ -130,7 +130,7 @@ class TestUtils(unittest.TestCase):
'what'
:
'hello'
,
'what'
:
'hello'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello 2'
assert
res
==
'hello 2'
...
@@ -140,7 +140,7 @@ class TestUtils(unittest.TestCase):
...
@@ -140,7 +140,7 @@ class TestUtils(unittest.TestCase):
'who'
:
u'wórld'
,
'who'
:
u'wórld'
,
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
u'hello wórld'
assert
res
==
u'hello wórld'
...
@@ -150,7 +150,7 @@ class TestUtils(unittest.TestCase):
...
@@ -150,7 +150,7 @@ class TestUtils(unittest.TestCase):
'data'
:
[
'no-one'
,
'world'
]
'data'
:
[
'no-one'
,
'world'
]
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -160,7 +160,7 @@ class TestUtils(unittest.TestCase):
...
@@ -160,7 +160,7 @@ class TestUtils(unittest.TestCase):
'data'
:
[
'no-one'
,
'world'
]
'data'
:
[
'no-one'
,
'world'
]
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
template
assert
res
==
template
...
@@ -170,7 +170,7 @@ class TestUtils(unittest.TestCase):
...
@@ -170,7 +170,7 @@ class TestUtils(unittest.TestCase):
'data'
:
[
'no-one'
,
'world'
]
'data'
:
[
'no-one'
,
'world'
]
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
template
assert
res
==
template
...
@@ -180,7 +180,7 @@ class TestUtils(unittest.TestCase):
...
@@ -180,7 +180,7 @@ class TestUtils(unittest.TestCase):
'data'
:
{
'no-one'
:
0
,
'world'
:
1
}
'data'
:
{
'no-one'
:
0
,
'world'
:
1
}
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
template
assert
res
==
template
...
@@ -190,7 +190,7 @@ class TestUtils(unittest.TestCase):
...
@@ -190,7 +190,7 @@ class TestUtils(unittest.TestCase):
'data'
:
[
'no-one'
,
{
'msg'
:
[
'world'
]
}
]
'data'
:
[
'no-one'
,
{
'msg'
:
[
'world'
]
}
]
}
}
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'hello world'
assert
res
==
'hello world'
...
@@ -201,7 +201,7 @@ class TestUtils(unittest.TestCase):
...
@@ -201,7 +201,7 @@ class TestUtils(unittest.TestCase):
}
}
template
=
'${foo}${bar}'
template
=
'${foo}${bar}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'foobar'
assert
res
==
'foobar'
def
test_varReplace_escape_dot
(
self
):
def
test_varReplace_escape_dot
(
self
):
...
@@ -214,7 +214,7 @@ class TestUtils(unittest.TestCase):
...
@@ -214,7 +214,7 @@ class TestUtils(unittest.TestCase):
}
}
template
=
'${hostvars.{test.example.com}.foo}'
template
=
'${hostvars.{test.example.com}.foo}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'bar'
assert
res
==
'bar'
def
test_varReplace_list_join
(
self
):
def
test_varReplace_list_join
(
self
):
...
@@ -227,7 +227,7 @@ class TestUtils(unittest.TestCase):
...
@@ -227,7 +227,7 @@ class TestUtils(unittest.TestCase):
}
}
template
=
'yum pkg=${list} state=installed'
template
=
'yum pkg=${list} state=installed'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
,
expand_lists
=
True
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
,
expand_lists
=
True
)
assert
res
==
'yum pkg=foo,bar,baz state=installed'
assert
res
==
'yum pkg=foo,bar,baz state=installed'
def
test_varReplace_escaped_var
(
self
):
def
test_varReplace_escaped_var
(
self
):
...
@@ -235,7 +235,7 @@ class TestUtils(unittest.TestCase):
...
@@ -235,7 +235,7 @@ class TestUtils(unittest.TestCase):
'foo'
:
'bar'
,
'foo'
:
'bar'
,
}
}
template
=
'action
\
$foo'
template
=
'action
\
$foo'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'action $foo'
assert
res
==
'action $foo'
def
test_varReplace_var_part
(
self
):
def
test_varReplace_var_part
(
self
):
...
@@ -246,7 +246,7 @@ class TestUtils(unittest.TestCase):
...
@@ -246,7 +246,7 @@ class TestUtils(unittest.TestCase):
'key'
:
'bar'
,
'key'
:
'bar'
,
}
}
template
=
'test ${foo.$key}'
template
=
'test ${foo.$key}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'test result'
assert
res
==
'test result'
def
test_varReplace_var_partial_part
(
self
):
def
test_varReplace_var_partial_part
(
self
):
...
@@ -257,7 +257,7 @@ class TestUtils(unittest.TestCase):
...
@@ -257,7 +257,7 @@ class TestUtils(unittest.TestCase):
'key'
:
'bar'
,
'key'
:
'bar'
,
}
}
template
=
'test ${foo.${key}baz}'
template
=
'test ${foo.${key}baz}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
res
=
ansible
.
utils
.
varReplace
(
None
,
template
,
vars
)
assert
res
==
'test result'
assert
res
==
'test result'
def
test_template_varReplace_iterated
(
self
):
def
test_template_varReplace_iterated
(
self
):
...
@@ -274,14 +274,14 @@ class TestUtils(unittest.TestCase):
...
@@ -274,14 +274,14 @@ class TestUtils(unittest.TestCase):
def
test_varReplace_include
(
self
):
def
test_varReplace_include
(
self
):
template
=
'hello $FILE(world) $LOOKUP(file, world)'
template
=
'hello $FILE(world) $LOOKUP(file, world)'
res
=
ansible
.
utils
.
template
(
"test"
,
template
,
{})
res
=
ansible
.
utils
.
template
(
"test"
,
template
,
{}
,
expand_lists
=
True
)
assert
res
==
u'hello world world'
assert
res
==
u'hello world world'
def
test_varReplace_include_script
(
self
):
def
test_varReplace_include_script
(
self
):
template
=
'hello $PIPE(echo world) $LOOKUP(pipe, echo world)'
template
=
'hello $PIPE(echo world) $LOOKUP(pipe, echo world)'
res
=
ansible
.
utils
.
template
(
"test"
,
template
,
{})
res
=
ansible
.
utils
.
template
(
"test"
,
template
,
{}
,
expand_lists
=
True
)
assert
res
==
u'hello world world'
assert
res
==
u'hello world world'
...
...
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