From 605523f4809302feea325eedb24755c4b943a661 Mon Sep 17 00:00:00 2001 From: agardner Date: Wed, 26 Apr 2017 13:48:59 +0200 Subject: Takes a template file and feeds it values Values come from a pod config file. This is just an example, only ipmi_ips are templated at this time. eg: address: {{ config['global_details']['ipmi_ips'][0] }} test like this: ./utils/generate_config.py -y labs/intel/pod5/pod.yaml -j installers/joid/labconfig.jinja2 releng should have a new job, validate-templates that looks for pattern: 'utils/generate_config.yml' pattern: '**/*.jinja2' and tests that templating does not error. Change-Id: I7f781abb702afcfccf7ed17674378cffe4a7177d Signed-off-by: agardner --- utils/generate_config.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 utils/generate_config.py (limited to 'utils') diff --git a/utils/generate_config.py b/utils/generate_config.py new file mode 100755 index 0000000..2a2f20d --- /dev/null +++ b/utils/generate_config.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +"""This module does blah blah.""" +import argparse +import yaml +from jinja2 import Environment, FileSystemLoader + +parser = argparse.ArgumentParser() +parser.add_argument("--yaml", "-y", type=str, required=True) +parser.add_argument("--jinja2", "-j", type=str, required=True) +args = parser.parse_args() + + +ENV = Environment(loader=FileSystemLoader('./')) + +with open(args.yaml) as _: + dict = yaml.safe_load(_) + +# Print dictionary generated from yaml (uncomment for debug) +#print dict + +# Render template and print generated config to console +template = ENV.get_template(args.jinja2) +print template.render(config=dict) -- cgit 1.2.3-korg