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 may be able to use some of the common methods in the AnsibleModule base class to avoid duplicating common code:
https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L1045
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.
https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/init.py#L721
If you look at how the template action plugin works, it uses the slurp, copy and file modules internally:
https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/template.py
The template “module” is nothing but a placeholder for the docs; all of the logic is handled in the action plugin:
https://github.com/ansible/ansible/blob/devel/library/files/template
Depending on your use case, you may find a custom action plugin a better fit than a custom module.
I hope that helps!
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.
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
You can configure the module search path in ansible.cfg, or also embed it in a role in a “./library” directory under a role.