-1

We are using Ansible to deploy components and, in writing the jinja2 templates, it occurs to me that keeping my .config in sync with my .config.j2 is going to be something I need to "remember" going forward.

Are there better tools than "remembering" to keep the j2 in sync with the latest config files? I am open to all ideas... merge checks? Tests?

Cyndi Baker
  • 670
  • 8
  • 15

1 Answers1

1

There are several things that you can do. Here are some of my ideas about how to do that.

  1. Using a Makefile. With the help of that, instead of doing ansible-playbook -i BLAH BLAH BLAH playbok.yml, you just need to set few rules for that and with a simple command, something like make run-ansible all the steps from sync to apply ansible playbook works well for you.

    Take a look at this pseudo make file:
.PHONY : run-ansible run sync
sync:
    cp .config.j2 .confg
run:
    ansible-playbook -i host -u user playbook.yml
run-ansible: sync run
  1. Use pre_tasks before running your role to update/sync .config file from .config.j2
  2. Using conditional include. In case the .config is not updated, run another tasks which generate .config from .config.j2. Doing such a thing is so simple. This link could help you.
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Numb95
  • 103
  • 2