Is it possible to call a module from a module?

1,987 views
Skip to first unread message

Sean Cavanaugh

unread,
May 16, 2014, 3:59:07 PM5/16/14
to ansibl...@googlegroups.com
I am new to developing modules, I am writing a module that will license our switches (Cumulus Linux) and I see that there are other modules that I could potentially leverage.  Rather than copying and pasting their code into my module, is there a standard way of just utilizing the module like a playbook?  Let me know if further explanation is needed. 

Chris Church

unread,
May 16, 2014, 5:49:36 PM5/16/14
to Sean Cavanaugh, ansibl...@googlegroups.com
You may be able to use some of the common methods in the AnsibleModule base class to avoid duplicating common code:



Another option would be an action plugin.  When modules are called, ansible first looks for an action plugin with the same name, defaulting to the normal (or async) action plugin if nothing else can be found.


If you look at how the template action plugin works, it uses the slurp, copy and file modules internally:


The template "module" is nothing but a placeholder for the docs; all of the logic is handled in the action plugin:


Depending on your use case, you may find a custom action plugin a better fit than a custom module.

I hope that helps!



On Fri, May 16, 2014 at 3:59 PM, Sean Cavanaugh <sean.e.c...@gmail.com> wrote:
I am new to developing modules, I am writing a module that will license our switches (Cumulus Linux) and I see that there are other modules that I could potentially leverage.  Rather than copying and pasting their code into my module, is there a standard way of just utilizing the module like a playbook?  Let me know if further explanation is needed. 

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
May 17, 2014, 9:02:01 PM5/17/14
to Chris Church, Sean Cavanaugh, ansibl...@googlegroups.com
If you look at the "basic" common code, you'll see some others in the same directory -- for instance ec2 and rackspace support code.

If it it made sense, you could have a common one called "cumulus".

While an action plugin can call other modules, it doesn't really make sense for cumulus plugins to have action plugins -- that's usually reserved for when deeper magic is required... but the "module_utils" infrastructure will serve you well.


Sean Cavanaugh

unread,
May 19, 2014, 1:59:53 PM5/19/14
to Michael DeHaan, Chris Church, ansibl...@googlegroups.com
Where do I test my module out?  Do I just slap it into /usr/share/ansible/ and a python file then try to call it in a playbook?  Don't quite understand what it is talking about here->http://docs.ansible.com/developing_modules.html#building-testing

-S

Michael DeHaan

unread,
May 25, 2014, 5:20:47 PM5/25/14
to Sean Cavanaugh, Chris Church, ansibl...@googlegroups.com
You can configure the module search path in ansible.cfg, or also embed it in a role in a "./library" directory under a role.




Reply all
Reply to author
Forward
0 new messages