Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PaNOSC
Data Analysis Services
packme
Commits
601b4817
Commit
601b4817
authored
Feb 03, 2020
by
eric pellegrini
Browse files
better code for checking missing jinja 2 templates
parent
e3daea1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/packme/PackerTemplate.py
View file @
601b4817
...
...
@@ -272,20 +272,23 @@ class PackerTemplate:
node
[
"provisioners"
]
=
self
.
_provisioners
node
[
"post-processors"
]
=
self
.
_postprocessors
env
=
jinja2
.
Environment
(
undefined
=
jinja2
.
DebugUndefined
)
template
=
env
.
from_string
(
repr
(
node
))
rendered
=
template
.
render
(
**
self
.
_environment
)
stringified_node
=
repr
(
node
)
# Create a jinja evironment for parsing the manifest
env
=
jinja2
.
Environment
()
# Parse the string with jinja templates in unrendered state in order to get te set of all jinja templates
ast
=
env
.
parse
(
stringified_node
)
jinja_templates
=
jinja2
.
meta
.
find_undeclared_variables
(
ast
)
# Retrieve those templates which are not declared in the environment. These are the undefined templates.
undefined
=
jinja_templates
.
difference
(
self
.
_environment
.
keys
())
# Check if rendering was done correctly
ast
=
env
.
parse
(
rendered
)
undefined
=
jinja2
.
meta
.
find_undeclared_variables
(
ast
)
# If there are some undefined templates, stop here.
if
undefined
:
print
(
f
'The following variables are undefined:
{
undefined
!
r
}
'
)
sys
.
exit
(
1
)
# Replace back %< .* %> to {{ .* }}
rendered
=
rendered
.
replace
(
"%<"
,
"{{"
)
rendered
=
rendered
.
replace
(
">%"
,
"}}"
)
template
=
env
.
from_string
(
stringified_node
)
rendered
=
template
.
render
(
**
self
.
_environment
)
# Dump to the output file
with
open
(
output_file
,
"w"
)
as
fout
:
...
...
templates/base-ill/manifest.yml
View file @
601b4817
...
...
@@ -24,7 +24,7 @@ packer:
boot_wait
:
5s
boot_command
:
-
"
<tab>
"
-
"
preseed/url=http://
%<
.HTTPIP
>%:%<
.HTTPPort
>%
/{{
preseed_file_name
}}
"
-
"
preseed/url=http://
{%
raw
%}{{
.HTTPIP
}}:{{
.HTTPPort
}}{%
endraw
%}
/{{
preseed_file_name
}}
"
-
"
auto-install/enable=true
"
-
"
net.ifnames=0
"
-
"
netcfg/get_hostname={{
vm_name
}}
"
...
...
@@ -38,7 +38,7 @@ packer:
-
"
passwd/user-password-again=
{{
user_password
}}
"
-
"
passwd/root-password={{
root_password
}}
"
-
"
passwd/root-password-again={{
root_password
}}
"
-
"
no_proxy=
%<
.HTTPIP
>%
,{{
no_proxy
}}
"
-
"
no_proxy=
{%
raw
%}{{
.HTTPIP
}}{%
endraw
%}
,{{
no_proxy
}}
"
-
"
<enter>"
disk_size
:
"
{{
disk_size
}}"
http_directory
:
"
http"
...
...
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