Skip to content

Commit 2650402

Browse files
author
Clayton O'Neill
committed
Add support for overriding params from environment
If a matching environment variable is found, then the value will be replaced when generating the output from the template. This matching occurs both on the parameter name in uppercase (NOTIFICATION_INTERVAL) or the resource name + the parameter name (HOST_NOTIFICATION_INTERVAL)
1 parent c330b6b commit 2650402

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

examples/nagios_.jinja2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ define {{object_name}} {
88
{{object_name}}_name {{resource.name}}
99
{% endif %}
1010
{% for key,value in resource.parameters.items() %}
11+
{% set name_key = (object_name ~ '_' ~ key)|upper %}
1112
{% if key not in metaparams or key in allowed_metaparams %}
1213
{% if value is iterable and value is not string %}
1314
{{key}} {{value|join(", ")}}
1415
{% else %}
16+
{% if name_key in env %}
17+
{{key}} {{env[name_key]}}
18+
{% elif key|upper in env %}
19+
{{key}} {{env[key|upper]}}
20+
{% else %}
1521
{{key}} {{value}}
1622
{% endif %}
1723
{% endif %}
24+
{% endif %}
1825
{% endfor %}
1926
}
2027
{% endfor %}

puppetdb_stencil.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
import logging
11+
import os
1112
import pypuppetdb
1213
import jinja2
1314

@@ -36,7 +37,8 @@ def render_resources(database, resource_type, template_names):
3637
LOG.error('No template found for {0}'.format(resource_type))
3738
else:
3839
return template.render(resource_type=resource_type,
39-
resources=resources, metaparams=METAPARAMS)
40+
resources=resources, metaparams=METAPARAMS,
41+
env=os.environ)
4042

4143

4244
def main():

0 commit comments

Comments
 (0)