Hi,
Few months after dropping the idea, I finally come back to Ansible to
solve my conf management needs. The '-l' switch probably brought me
back. Ansible came a long way since then. Congrat guys.
I'm facing a problem and I wonder if I'm on the right path to solve it.
I want to distribute ~/.bashrc files on remote nodes.
This .bashrc depends on many other parts of the setup : aliases
pertaining to git, rbenv/RVM setup, etc...
Of course, in the ~/.bashrc template, I could use
{% if have_git %}
.. some git related conf ...
{% endif %}
(note : I set `have_git` for the hosts I want to install git on).
However, this approach would introduce a lot of coupling between plays :
the play that takes care of installing .bashrc would depend on git play,
ruby play, etc..., which is not desirable for a truly modular (and thus
shareable) setup.
I solved this by having a ~/.bash.d directory containing specific
customization files (one for git in 10_git.bash, one for ruby in
20_ruby.bash, etc...) and adding this line at the end of the deployed
~/.bashrc :
for i in `ls ~/.bash.d/*.bash`; do source $i; done
While this 'dependency injection' approach seems elegant at first, it
falls short solving similar problems in situations where config files
are just... config files, and not programs you can bend to fit your
purpose like .bashrc is.
For instance, imagine you want to build /etc/sysconfig/iptables based on
what is installed on the node. Of course, you could do :
... some rules
{% if 'web' in group_names %}
-A INPUT -p tcp -m tcp --dport {{ web_port }} -j ACCEPT
{% endif %}
...rest of rules
This works, but it depends on your group name ('web'), and gets
complicated and redundant if you have multiple web-like groups.
What whould be nice could be some kind of 'accumulator' that adds new
content to a pre-existing variable (e.g. if a node is in 'web' and 'ftp'
groups, it will cumulate `iptable_rules` of both groups).
There is probably a way to do this already, or a way to handle this
properly.
If you have any clue or tip on this, I'd be glad to hear it.
Thanks for reading, and sorry for being long.
M