Skip to main content

Convert config files into Ansible defaults and Jinja2 templates.

Project description

JinjaTurtle

JinjaTurtle logo

JinjaTurtle is a command-line tool to help you generate Jinja2 templates and Ansible defaults/main.yml files from a native configuration file of a piece of software.

How it works

  • The config file is examined
  • Parameter key names are generated based on the parameter names in the config file. In keeping with Ansible best practices, you pass a prefix for the key names, which should typically match the name of your Ansible role.
  • A Jinja2 file is generated from the file with those parameter key names injected as the {{ variable }} names.
  • A defaults/main.yml is generated with those key names and the values taken from the original config file as the defaults.

By default, the Jinja2 template and the defaults/main.yml are printed to stdout. However, it is possible to output the results to new files.

What sort of config files can it handle?

TOML, YAML, INI, JSON and XML-style config files should be okay. There are always going to be some edge cases in very complex files that are difficult to work with, though, so you may still find that you need to tweak the results.

For XML and YAML files, JinjaTurtle will attempt to generate 'for' loops and lists in the Ansible yaml if the config file looks homogenous enough to support it. However, if it lacks the confidence in this, it will fall back to using scalar-style flattened attributes.

You may need or wish to tidy up the config to suit your needs.

The goal here is really to speed up converting files into Ansible/Jinja2, but not necessarily to make it perfect.

How to install it

From PyPi

pip install jinjaturtle

From this git repository

Clone the repo and then run inside the clone:

poetry install

AppImage

Download the AppImage from the Releases and make it executable, and put it on your $PATH.

How to run it

Say you have a php.ini file and you are in a directory structure like an Ansible role (with subfolders defaults and templates):

jinjaturtle php.ini \
  --role-name php \
  --defaults-output defaults/main.yml \
  --template-output templates/php.ini.j2

Full usage info

usage: jinjaturtle [-h] -r ROLE_NAME [-f {json,ini,toml,yaml,xml}] [-d DEFAULTS_OUTPUT] [-t TEMPLATE_OUTPUT] config

Convert a config file into an Ansible defaults file and Jinja2 template.

positional arguments:
  config                Path to the source configuration file (TOML or INI-style).

options:
  -h, --help            show this help message and exit
  -r, --role-name ROLE_NAME
                        Ansible role name, used as variable prefix (e.g. cometbft).
  -f, --format {ini,toml}
                        Force config format instead of auto-detecting from filename.
  -d, --defaults-output DEFAULTS_OUTPUT
                        Path to write defaults/main.yml. If omitted, defaults YAML is printed to stdout.
  -t, --template-output TEMPLATE_OUTPUT
                        Path to write the Jinja2 config template. If omitted, template is printed to stdout.

Found a bug, have a suggestion?

You can e-mail me (see the pyproject.toml for details) or contact me on the Fediverse:

https://goto.mig5.net/@mig5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinjaturtle-0.3.2.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinjaturtle-0.3.2-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file jinjaturtle-0.3.2.tar.gz.

File metadata

  • Download URL: jinjaturtle-0.3.2.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.5 Linux/6.12.54-1.qubes.fc37.x86_64

File hashes

Hashes for jinjaturtle-0.3.2.tar.gz
Algorithm Hash digest
SHA256 18b5e61d6ed05efdca6886e5757545952e0de8479785cfd9b9c30e3c5aea2156
MD5 7370791a9f11e6ec0121eb8b1ac6eb76
BLAKE2b-256 39a3dc25ba39999b2c135b089950cbe295fedef4dd1a8aa0ebe4496288824584

See more details on using hashes here.

File details

Details for the file jinjaturtle-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: jinjaturtle-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 41.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.5 Linux/6.12.54-1.qubes.fc37.x86_64

File hashes

Hashes for jinjaturtle-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 650b115793bfa83ade960f84fb8c2189c45cf4e0ebbc2f61008741c9bfbda69b
MD5 96c8d6a1e7803aa2d457b94757b4cde8
BLAKE2b-256 92e651ff981c6396ed3cb425ae7899ae25f1a4e3723ca74c2aef1e5d13c5e976

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page