Jaime Gago Condensing Information Systems From the Vapor Of Data

15Oct/133

Plain Text Based Configuration Files Management with Ansible

Screen Shot 2013-03-30 at 6.07.36 PMAnsible, the configuration management and command orchestration tool I use currently, has several modules and ways one can use to push plain text based configuration.  I got a lot of help from the Ansible community, the guys on IRC are quite a model when it comes to the S of CAMS and I thought I would share back the knowledge I've gained.

The template module  is very powerful and can deal with most use cases,  I -now- try to stick to it as much as possible with the intent of having all text files "templated" with the ansible managed headers in them (properly commented e.g. <!-- {{ ansible_managed }} --> for XML files).

  • Don't use copy

When dealing with several plain text configuration files one pitfall (I've felt into) is to use "drop style" directories and recursive copying leveraging the "copy" module. While this works it prevents Ansible from interpreting the ansible managed var which if you've followed I try to add to all my text files.

  • "Recursive templating" syntax

If for some reason, like me, you still need a "drop style" templating task to render a directory filled with templates here a syntax that works in Ansible 1.3.x

 

- name: "Recursive templating"
 template: >
         src={{ item }}
         dest=/some/destination/dir/
         with_lines: find /absolute/path/to/templates/dir/ -name '*.some_extension'

 

A couple of caveats on this syntax, I haven't been able to use a relative path in conjunction with "with_lines", also the trailing slash in the destination directory has revealed to be mandatory.

Comments (3) Trackbacks (0)
  1. Nice Article. How it help to developer in terms of balance the day to day life.

  2. Great post, most informative, didn’t realise devops were into this.

  3. That’s a great article. Thanks for sharing! realise devops were into this.


Leave a comment

No trackbacks yet.