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
959a1561
Commit
959a1561
authored
Feb 05, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly count newlines appearing at the end of templates after rendering
Fixes #4633
parent
cda3f061
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
lib/ansible/utils/string_functions.py
+8
-0
lib/ansible/utils/template.py
+10
-2
No files found.
lib/ansible/utils/string_functions.py
View file @
959a1561
...
...
@@ -5,3 +5,11 @@ def isprintable(instring):
isprintable
=
set
(
instring
)
.
issubset
(
printset
)
return
isprintable
def
count_newlines_from_end
(
str
):
i
=
len
(
str
)
while
i
>
0
:
if
str
[
i
-
1
]
!=
'
\n
'
:
break
i
-=
1
return
len
(
str
)
-
i
lib/ansible/utils/template.py
View file @
959a1561
...
...
@@ -32,6 +32,8 @@ import pwd
import
ast
import
traceback
from
ansible.utils.string_functions
import
count_newlines_from_end
class
Globals
(
object
):
FILTERS
=
None
...
...
@@ -495,8 +497,14 @@ def template_from_file(basedir, path, vars):
except
jinja2
.
exceptions
.
UndefinedError
,
e
:
raise
errors
.
AnsibleUndefinedVariable
(
"One or more undefined variables:
%
s"
%
str
(
e
))
if
data
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
res
=
res
+
'
\n
'
# The low level calls above do not preserve the newline
# characters at the end of the input data, so we use the
# calculate the difference in newlines and append them
# to the resulting output for parity
res_newlines
=
count_newlines_from_end
(
res
)
data_newlines
=
count_newlines_from_end
(
data
)
if
data_newlines
>
res_newlines
:
res
+=
'
\n
'
*
(
data_newlines
-
res_newlines
)
if
isinstance
(
res
,
unicode
):
# do not try to re-template a unicode string
...
...
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