Re: [ansible-project] Can a developed Ansible module include or extend an Ansible Core module?

830 views
Skip to first unread message

Michael DeHaan

unread,
Apr 5, 2013, 4:54:18 PM4/5/13
to ansible...@googlegroups.com
Generally speaking, ansible allows sharing code through "lib/ansible/module_common.py" to make writing functionality easier.

It does not, however, make it possible for one module to call another, which has not, to date, really been needed -- that's not entirely true, we used to have something like this for file and copy until we got smart and moved the file attribute code into common :)

It seems like since url access is frequent enough we could make a common function in module common for url downloads -- IF we modify the get_url code to also use it so we aren't repeating ourselves.




On Fri, Apr 5, 2013 at 2:35 PM, Matt Ferrante <mferr...@gmail.com> wrote:
I am developing an Ansible module in Python that generates a url, fetches (like get_url) the tarball at that url from my internal artifactory and then extracts it. I am wondering if there is a way to include or extend the get_url Ansible core module in my module. I can't have this in multiple steps because the url being used is generated from a git hash and requires a multi-step search.

I'd like to do something like:
module_json_response = module.get_module('get_url').issue_command('url=http://myartifactory.com/artifact.tar.gz dest=/path/to/local/artifact.tar.gz');

My understanding is that Ansible uploads the module in use and executes it, including another module during execution wouldn't work. If there isn't a way, I will probably just copy the whole get_url module and use it in my module, but I would like to avoid that.

Thanks in advance for any help.

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



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Asad Khan

unread,
Apr 6, 2013, 8:51:44 AM4/6/13
to ansible...@googlegroups.com
Just to chip in, I've looked for something like this as well.
We have some specific needs for yum that the current yum module doesn't quite provide (downgrade, exact version upgrade)
My choices were:

1) Write our own proprietary localyum module and maintain it ourself (use current yum as a reference)
2) Enhance ansible's yum, and lobby to have our changes/enhancements accepted
3) Try to express our incremental needs in Ansible itself, i.e. use Ansible's yum, surround it with just enough Ansible logic to achieve our needs

1) is a fair amount of effort given how comprehensive Ansible's yum already is. It will be relatively high maintenance, and fails to leverage Ansible's yum (or entails keeping constant tabs on Ansible's yum on a regular basis to down-merge)
2) Our needs may not align with the community's needs
3) is the path I experimented with, but Ansible is expressly not Python, so it's cumbersome to express decision/logic

Long story short, an Option 4) "Ability to write a new module that uses an existing module" would have helped.

Antonio Messina

unread,
Apr 6, 2013, 8:56:16 AM4/6/13
to ansible...@googlegroups.com
On Sat, Apr 6, 2013 at 2:51 PM, Asad Khan <asad....@gmail.com> wrote:
> Long story short, an Option 4) "Ability to write a new module that uses an
> existing module" would have helped.

I have similar use cases too. In one of them, for instance, I just
need to produce a template at runtime and replace some variables.
Being able to reuse the code of the template module would be
wonderful.

.a.

--
GC3: Grid Computing Competence Center
http://www.gc3.uzh.ch/
University of Zurich
Winterthurerstrasse 190
CH-8057 Zurich Switzerland

Michael DeHaan

unread,
Apr 6, 2013, 2:22:48 PM4/6/13
to ansible...@googlegroups.com
On Sat, Apr 6, 2013 at 8:51 AM, Asad Khan <asad....@gmail.com> wrote:
Just to chip in, I've looked for something like this as well.
We have some specific needs for yum that the current yum module doesn't quite provide (downgrade, exact version upgrade)
My choices were:

2) Enhance ansible's yum, and lobby to have our changes/enhancements accepted

I would recommend this.

Matt Ferrante

unread,
Apr 8, 2013, 11:02:37 AM4/8/13
to ansible...@googlegroups.com
So, seems like the short answer is no, this is not currently supported.

Changing the get_url functionality to be in module_common seems like it would be worth it, as this could be relatively common. Extending a module would be ideal, but would probably be a bigger change.

I already wrote my module, copying the get_url module. When I get a chance, I'll move the get_url functionality to module_common and submit a pull request. If it gets accepted, when we upgrade our Ansible version, I'll just refactor my module to use that.

Thanks for the help and advice.

On Friday, April 5, 2013 4:54:18 PM UTC-4, Michael DeHaan wrote:

Michael DeHaan

unread,
Apr 8, 2013, 11:10:12 AM4/8/13
to ansible...@googlegroups.com
Well, you can access the way template works by writing an action plugin, but it's more involved than writing a simple client module.

+1 to moving get_url code into common, that's come up a few times.


seth vidal

unread,
Apr 8, 2013, 11:16:19 AM4/8/13
to ansible...@googlegroups.com, asad....@gmail.com
On Sat, 6 Apr 2013 05:51:44 -0700 (PDT)
Asad Khan <asad....@gmail.com> wrote:

> Just to chip in, I've looked for something like this as well.
> We have some specific needs for yum that the current yum module
> doesn't quite provide (downgrade, exact version upgrade)
> My choices were:
>
> 1) Write our own proprietary localyum module and maintain it ourself
> (use current yum as a reference)
> 2) Enhance ansible's yum, and lobby to have our changes/enhancements
> accepted

If you want downgrade in yum then you'll want to have that behave in
the face of rhel5. So check your versions of yum and have the downgrade
command error out appropriately.

Other than that - I don't think that will be difficult

-sv
Reply all
Reply to author
Forward
0 new messages