Feb 2018

Creating a sysV initlike ansible setup

I am fiercely lazy (I bet you were expecting loyal - nope) and because of that I often come up with weird half backwards ways of making sure I can do the least work possible so I can do the least work possible and play. Recently, yet another weird situation resulted in something possibly of interest to others but definitely falls into the realm of whatever this website is supposed to be.

The Problem

I have a new parallel compute environment I am setting up for work and I wrote a script to do network installs using kickstart (I do believe there is a text laying around here about the fun of kickstart somewhere - check it out if you need to give yourself a headache). Basically the last step of the postinstall is run a bunch of ansible playbooks to do things like (but not limited to):

  • package postinstall
  • setup NFS and fstab
  • configure ntp, snmp, whatever other daemons
  • sudo make me a sandwhich
  • ....

You get the idea ... but, some of those are repeatables that might get called again later, like NFS, there is about a 100% chance those mounts will change (especially where I work) and I am crafting ansible to be the gatekeeper of configuration changes on the cluster. It seems practically invented for the task. In addition to that, I want to keep all the playbooks, whether needed for postinstall or not, in the same directory. Last and not least they have to be executed in a particular order after the base install is completed.

Alt Solutions

I could be stupid and create a database that has names and smartlinks to them.... but there aren't enough to care and that means I would have to take care of yet another database. I don't like databases as it is so that is out. The most obvious solution is script it, and in the script file keep a list of the names and the order to execute them in. The main problem with having the scripts kept inside a script is I would have to modify the script everytime I added, moved or deleted one. Yes that is still too much work. Finally, I could create an rcfile that I scoop up and populate a list with. Using an rcfile is probably the second best idea. But the best idea was to rip off sys V.

Thievery is always best

Basically all I came up with was putting a numeric prefix by groups of playbooks, even better I made them symlinks so something like this:


nfs_mounts.yml -> 07_nfs_mounts.yml

Not exactly earth shattering but it does th job perfectly. The script was relatively simple too:

...

cd $INITDIR || bomb "Cannot reach nodectl dir"
for e in `ls *.yml|grep [00-99]`; do
        $PLAYBOOK $e || bomb "Playbook $e failed"
done
...

Where INITDIR is where they are and PLAYBOOK is the location of the ansible-playbook command.

Summary

Solutions do not always have to be overthought, complex or even all that systemic. Sometimes the simple solution is something old and borrowed.