# File generation and coupling between plays

**URL:** <https://forum.ansible.com/t/file-generation-and-coupling-between-plays/12123>\
**Category:** Ansible Project\
**Created:** [December 6, 2012, 2:08pm UTC](https://forum.ansible.com/t/file-generation-and-coupling-between-plays/12123 "2012-12-06T14:08:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michel\_Blanc1](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@Michel\_Blanc1](https://forum.ansible.com/u/Michel_Blanc1)\
**Post date:** [December 6, 2012, 2:08pm UTC](https://forum.ansible.com/t/file-generation-and-coupling-between-plays/12123/1 "2012-12-06T14:08:21Z")

</div>

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

&nbsp;&nbsp;{% if have\_git %}  
&nbsp;&nbsp;.. some git related conf ...  
&nbsp;&nbsp;{% 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 :

&nbsp;&nbsp;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 :

&nbsp;&nbsp;... some rules  
&nbsp;&nbsp;{% if 'web' in group\_names %}  
&nbsp;&nbsp;-A INPUT -p tcp -m tcp --dport {{ web\_port }} -j ACCEPT  
&nbsp;&nbsp;{% endif %}  
&nbsp;&nbsp;...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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [December 7, 2012, 4:17pm UTC](https://forum.ansible.com/t/file-generation-and-coupling-between-plays/12123/2 "2012-12-07T16:17:24Z")

</div>

Take a look at the 'assemble' module.
