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
46776995
Commit
46776995
authored
Oct 02, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1195 from jpmens/jtempl
Feature: file info on templates accessible to Jinja2 templates
parents
6616fba1
5f04ef8b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletions
+16
-1
lib/ansible/utils.py
+16
-1
No files found.
lib/ansible/utils.py
View file @
46776995
...
...
@@ -36,6 +36,8 @@ import stat
import
termios
import
tty
from
multiprocessing
import
Manager
import
datetime
import
pwd
VERBOSITY
=
0
...
...
@@ -389,14 +391,27 @@ def template(basedir, text, vars):
def
template_from_file
(
basedir
,
path
,
vars
):
''' run a file through the templating engine '''
realpath
=
path_dwim
(
basedir
,
path
)
environment
=
jinja2
.
Environment
(
loader
=
jinja2
.
FileSystemLoader
(
basedir
),
trim_blocks
=
True
)
environment
.
filters
[
'to_json'
]
=
json
.
dumps
environment
.
filters
[
'from_json'
]
=
json
.
loads
environment
.
filters
[
'to_yaml'
]
=
yaml
.
dump
environment
.
filters
[
'from_yaml'
]
=
yaml
.
load
data
=
codecs
.
open
(
path_dwim
(
basedir
,
path
)
,
encoding
=
"utf8"
)
.
read
()
data
=
codecs
.
open
(
realpath
,
encoding
=
"utf8"
)
.
read
()
t
=
environment
.
from_string
(
data
)
vars
=
vars
.
copy
()
try
:
template_uid
=
pwd
.
getpwuid
(
os
.
stat
(
realpath
)
.
st_uid
)
.
pw_name
except
:
template_uid
=
os
.
stat
(
realpath
)
.
st_uid
vars
[
'template_host'
]
=
os
.
uname
()[
1
]
vars
[
'template_path'
]
=
realpath
vars
[
'template_mtime'
]
=
datetime
.
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
realpath
))
vars
[
'template_uid'
]
=
template_uid
vars
[
'ansible_managed'
]
=
"
%
s on
%
s, modified
%
s by
%
s"
%
(
vars
[
'template_path'
],
vars
[
'template_host'
],
vars
[
'template_mtime'
],
vars
[
'template_uid'
]
)
res
=
t
.
render
(
vars
)
if
data
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
res
=
res
+
'
\n
'
...
...
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