Jinja
Jump to navigation
Jump to search
$ export MYENVVAR=foo
$ nano example.py
from jinja2 import Template import os template = Template("Hello {{ env['MYENVVAR'] or 'DefaultVal' }}") r = template.render(env=os.environ, name='somethingelse') print(r)
Run template
$ python3 example.py
https://jinja.palletsprojects.com/en/2.11.x/intro/
Other Methods
targs = {} targs['MYENVVAR'] = os.getenv('MYENVVAR') with open('configMap.yml.jinja') as f_: template = Template(f_.read()) txt = template.render(targs) with open('configMap.yml', 'w') as f_: f_.write(txt)