Fill in Ansible template on a Windows system

Viewed 88

I have a number of file templates that I'm deploying using Ansible and the ansible.builtin.template module. These are a bunch of JSON-files with Jinja-placeholders where variables are filled in. Default variable values are placed within a YAML-file called defaults.yml.

Now I've gotten the requirement to have the templates executed on the local system, which on Linux systems is not a problem running ansible -e @defaults.yml localhost -m ansible.builtin.template -a "src=config.json.template dest=config.json".

The issue is with Windows systems. It's not really possible to run the Ansible client on a Windows machine besides having to fall back on Cygwin, WSL2 or Docker as far as I've learned from this issue. All of these aren't really options for me.

I've already checked whether I could run Jinja by itself, but that seems not to be that easy.

My question is if there's a way to fill in the templates without having to install a full Ansible client. Perhaps it's possible to run a templating submodule from Ansible or something similar?

1 Answers

I've found that there are several Jinja CLI packages available. I've tried a few and stuck with j2cli. Filling the templates is as easy as j2 -f yaml -o config.json config.json.template defaults.yml.

I also tried jinja-cli, but found the documentation was lacking. With the docs from j2cli I was able to run my usecase successfully by executing jinja -d defaults.yml -f yaml -o config.json config.json.template.

Hope this helps someone with a similar issue.

Related