# Module composition?

**URL:** <https://forum.ansible.com/t/module-composition/11788>\
**Category:** Ansible Project\
**Created:** [August 11, 2012, 1:47am UTC](https://forum.ansible.com/t/module-composition/11788 "2012-08-11T01:47:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chamberlain\_Darren](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Chamberlain\_Darren](https://forum.ansible.com/u/Chamberlain_Darren)\
**Post date:** [August 11, 2012, 1:47am UTC](https://forum.ansible.com/t/module-composition/11788/1 "2012-08-11T01:47:03Z")

</div>

Hello all.

I'm looking into writing some higher-level modules that would allow  
my group to do something like the following in a playbook:

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Install FooApp  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: foo vers=4.4 root=/srv/foo

Where the foo module would combine several calls to a package  
manager (using the apt, yum, or git modules), calling some custom  
scripts (using command), and installing a default config and an init  
script (the file or template modules), and with predetermined  
parameters. (Obviously these would not be intended for  
redistribution.)

What's the best way to go about this? My first thought was to use  
the ansible.runner.Runner class, but that looks like it manages the  
connection itself, which I don't want -- I want to do it all in the  
same connection.

Am I missing something obvious? Or perhaps approaching this the  
wrong way? I wanted something a little more self-contained and  
abstracted than include files, if only because using include doesn't  
honor ANSIBLE\_LIBRARY (I want to store and manage these separately  
from the plabooks).

Thanks for any ideas.

---

<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:** [August 11, 2012, 1:51am UTC](https://forum.ansible.com/t/module-composition/11788/2 "2012-08-11T01:51:45Z")

</div>

> Hello all.
> 
> I'm looking into writing some higher-level modules that would allow  
> my group to do something like the following in a playbook:
> 
> tasks:  
> - name: Install FooApp  
> action: foo vers=4.4 root=/srv/foo

ok...

> Where the foo module would combine several calls to a package  
> manager (using the apt, yum, or git modules), calling some custom  
> scripts (using command), and installing a default config and an init  
> script (the file or template modules), and with predetermined  
> parameters. (Obviously these would not be intended for  
> redistribution.)
> 
> What's the best way to go about this? My first thought was to use  
> the ansible.runner.Runner class, but that looks like it manages the  
> connection itself, which I don't want -- I want to do it all in the  
> same connection.

modules are executed on the remote host without round trips to the server, and the module cannot make requests for the server to do other things except in the case of 'daisy chained modules', which only let you get to pick one more module to run -- it's get\_url allows you to set the owner of the file. Basically modules are expected to be "done" once executed on the remote and entirely self contained.

However, that's not a bad thing. What you are speaking of is actually, whether it may not be obvious or not, a playbook!

Take a look at what Lorin wrote recently for deploying OpenStack or what Mark wrote for deploying a LAMP server. Apps don't get too much more complicated than this, and since in 0.6 and later, playbooks can include other playbooks at top level, there are a lot of options for how you organize.

I'd start by looking at those examples here:

[https://github.com/ansible/ansible-resources](https://github.com/ansible/ansible-resources)

---

<div class="post-metadata">

**Author:** ![Chamberlain\_Darren](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Chamberlain\_Darren](https://forum.ansible.com/u/Chamberlain_Darren)\
**Post date:** [August 11, 2012, 1:55am UTC](https://forum.ansible.com/t/module-composition/11788/3 "2012-08-11T01:55:02Z")

</div>

Thanks for the quick answer. I'll take a look at these now.

\* Michael DeHaan \<michael.dehaan at gmail.com\> [2012/08/10 21:51]:
