Konpile is a tool for generating configuration files from data files. This is useful for generating large and complex configuration files for network and security devices. Konpile is written in Python and uses the Jinja2 templating language. Konpile can be used as a web service, a Docker container, or a Python script.
For your immediate use, a Konpile web service is hosted by The Dyntek Labs and is made available at https://konpile.dynteklabs.com. The web service will allow you to upload data files and write a template. The template can be rendered and the output will be downloaded. This method will not allow you to use translation files, but will allow you to use multiple data files and explore your variables before rendering.
Often times, you'd like the peace of mind from processing your configurations on your own infrastructure. The easiest way to get started with Konpile yourself is via the Docker container. Konpile is available as a stateless and portable web service from a Docker image. Install Docker from here and then pull and start the container:
docker pull dyntek/konpile
docker run -d -p 80:80 dyntek/konpile
In this example, the web service will be available at http://localhost:80 as well as any other IP address that is available to your Docker host.
Install Git from here and clone the repository:
git clone https://github.com/dyntek-services-inc/konpile.git
Install Python3 from here and then install the dependencies:
pip install -r requirements.txt
python konpile.py -h
usage: konpile.py [-h] [--translation TRANSLATION [TRANSLATION ...]] template_file data_file
Use an Excel file to fill a Jinja2 template.
positional arguments:
template_file Jinja2 template file
data_file File with data
options:
-h, --help show this help message and exit
--translation TRANSLATION [TRANSLATION ...], -t TRANSLATION [TRANSLATION ...]
Translation CSV files
The translation files can be used to translate values from the Excel file to values used in the template. This is useful for translating values from one format to another without altering the original document. For example, translating a VLAN name to a VLAN ID.
You may use JSON, CSV, and Excel files to provide data to Konpile. When JSON is used, the data is pulled directly from the JSON file and is made available in the same format as the JSON file.
When CSV is used, the data is pulled from the CSV file into a list of key-value pairs. The first row of the CSV file, the header, defines variable names for the template.
When Excel is used, data is pulled from the Excel file sheet by sheet. Like with CSV, the first row of each sheet is used as the variable names to be passed along to the template. However, unlike CSV, fields containing comma separated values in the Excel document are split into a list of values. This is useful for defining multiple values for a single variable.
Konpile uses the Jinja2 templating language. Jinja2 is a powerful industry standard templating language used in a variety of applications. Konpile uses Jinja2 to render a template file with the data provided from the data files. The template file is a plain text file with the .j2
extension.
An example template file:
{% for line in sheet_name %}
{{ line.column_name1 }}
{% endfor %}
In the above example, this template will render a value column_name1
for each row, or line
, in the specified sheet, sheet_name
.
Learning to write a good template, one which can leverage the power of the Jinja2 templating language, is the most difficult part of using Konpile. The Jinja2 Template Designer Documentation is a great place to learn about the Jinja2 templating language. To aid you in learning Jinja2, Konpile is shipped with a few example templates. These templates can be found in the samples
directory.
This project is sponsored by Dyntek and maintained by their working group, The Dyntek Labs. Dyntek is a leading provider of professional services and managed solutions for advanced IT infrastructure, data center, cloud, and security.
The Dyntek Labs is a research and development group within Dyntek that focuses on developing new and innovative solutions to enable ourselves, our customers, and the community to be more efficient and secure.