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
af959630
Commit
af959630
authored
Mar 19, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move templating into a utils function. Reuse is our friend.
parent
c1fe0dd7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
11 deletions
+17
-11
lib/ansible/playbook.py
+2
-7
lib/ansible/runner.py
+1
-3
lib/ansible/utils.py
+14
-1
No files found.
lib/ansible/playbook.py
View file @
af959630
...
...
@@ -24,7 +24,6 @@ from ansible import errors
import
yaml
import
shlex
import
os
import
jinja2
import
time
# used to transfer variables to Runner
...
...
@@ -111,19 +110,15 @@ class PlayBook(object):
if
x
.
find
(
"="
)
!=
-
1
:
(
k
,
v
)
=
x
.
split
(
"="
)
inject_vars
[
k
]
=
v
included
=
file
(
path
)
.
read
()
template
=
jinja2
.
Template
(
included
)
included
=
template
.
render
(
inject_vars
)
included
=
utils
.
template_from_file
(
path
,
inject_vars
)
included
=
yaml
.
load
(
included
)
for
x
in
included
:
new_tasks
.
append
(
x
)
def
_include_handlers
(
self
,
play
,
handler
,
dirname
,
new_handlers
):
path
=
utils
.
path_dwim
(
dirname
,
handler
[
'include'
])
included
=
file
(
path
)
.
read
()
inject_vars
=
self
.
_get_vars
(
play
,
dirname
)
template
=
jinja2
.
Template
(
included
)
included
=
template
.
render
(
inject_vars
)
included
=
utils
.
template_from_file
(
path
,
inject_vars
)
included
=
yaml
.
load
(
included
)
for
x
in
included
:
new_handlers
.
append
(
x
)
...
...
lib/ansible/runner.py
View file @
af959630
...
...
@@ -24,7 +24,6 @@ import signal
import
os
import
Queue
import
random
import
jinja2
import
traceback
import
tempfile
import
subprocess
...
...
@@ -326,8 +325,7 @@ class Runner(object):
else
:
args
=
"
%
s metadata=~/.ansible/setup"
%
args
template
=
jinja2
.
Template
(
args
)
args
=
template
.
render
(
inject_vars
)
args
=
utils
.
template
(
args
,
inject_vars
)
argsfile
=
self
.
_transfer_argsfile
(
conn
,
tmp
,
args
)
if
async_jid
is
None
:
...
...
lib/ansible/utils.py
View file @
af959630
...
...
@@ -20,13 +20,15 @@
import
sys
import
os
import
shlex
from
ansible
import
errors
import
jinja2
try
:
import
json
except
ImportError
:
import
simplejson
as
json
from
ansible
import
errors
###############################################################
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
###############################################################
...
...
@@ -222,4 +224,15 @@ def parse_json(data):
return
{
"failed"
:
True
,
"parsed"
:
False
,
"msg"
:
data
}
return
results
def
template
(
text
,
vars
):
''' run a text buffer through the templating engine '''
template
=
jinja2
.
Template
(
text
)
return
template
.
render
(
vars
)
def
template_from_file
(
path
,
vars
):
''' run a file through the templating engine '''
data
=
file
(
path
)
.
read
()
return
template
(
data
,
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