#!/usr/bin/env/python # # import os to get fundamentals import os # # First things first, we need to import the csv module import csv # and for debugging , I like my pprint functions import pprint # let's initialize my variables csvFile = 'config-data.csv' j2_env = {} configs = {} config = {} data = {} template = {} item = {} from jinja2 import Environment, FileSystemLoader # Capture our current directory THIS_DIR = os.path.dirname(os.path.abspath(__file__)) j2_env = Environment(loader=FileSystemLoader(THIS_DIR)) # open my jinja template config files (*.jinja) configs = ['shadow', 'network', 'wireless'] with open(csvFile, 'rU') as tf: data = csv.DictReader(tf, delimiter=',') # render the templates to output files in their own subdirectory for config in configs: template = j2_env.get_template('%s.jinja' % config) for item in data: with open('%s-%s' % (config, item['AP_Name'])) as rf: rf.write(template.render(item))