I’m still experimenting with container orchestration. Currently I’m in the process of building a three node CoreOS cluster with Kubernetes on top of it, connected over the Internet. One problem I was constantly struggling with was keeping my cloud-configs in sync. Most of the configuration settings were identical or nearly identical on all three nodes. Still, when adding a small change, I needed to apply this change to all three files. Forgetting one or mistyping led to errors and unnecessary debugging sessions.
This weekend I decided I’ve had enough of it. I created a small Python script to simplify working on several nearly identical configuration files, cloud-config-creator. By iterating over a set of node values and one master template the script creates the cloud-configs for all nodes. It’s little more than a wrapper for the Jinja2 templating engine, but I still find this incredibly useful. That’s why I want to add a bit more explanation around it.
You will need Python. I used Python 3, never tested it with 2.x. Furthermore you need to install the
Before starting to use
cloud-config-creator you should have basic knowledge of how to use templates. If you ever worked with a templating engine (e.g. for consul-template or Jekyll), you’ll quickly feel at home. Otherwise I recommend the Jinja2 documentation.
Furthermore you should know how to format YAML. My script uses PyYAML, which isn’t YAML 1.2 compatible (yet), so you’ll need to use YAML 1.1.
./cloud-config --templatefile master.tmpl --valuesfile values.yml --outpath out/ --includepath includes/
--templatefilefor the path to the template. I didn’t bother to handle relative pathes properly yet, so either use absolute paths or paths below the current working directory. This applies to all paths.
--valuesfilefor the path to the values. The script expects this to be a YAML formatted sequence of mappings.
--outpathfor the path where all the cloud-configs are created in.
--includepathis optional. If you have a lot of includes, you can put the files into a dedicated directory and specify it.