Very Basic Module

Hi all,

I’m a module developer newbie, so have started trying to write a very small module that will decrypt a file onto a target machine. I began by copying the ‘copy’ module:

#!/usr/bin/python

-- coding: utf-8 --

import os

def main():
module = AnsibleModule(
argument_spec = dict(
src = dict(required=False),
),
)
src = os.path.expanduser(module.params[‘src’])

if not os.path.exists(src):
module.fail_json(msg=“Source %s failed to transfer” % (src))

module.exit_json(changed=True)

from ansible.module_utils.basic import *
main()

This immediately fails in my playbook: msg: Source mytest.des3 failed to transfer

Further digging in the Ansible source suggests that copy is an action_plugin, and this somehow makes the copy module work.

Is there somewhere that I can read more about this, or am I missing something very basic?

All the best,
Craig

Further digging in the Ansible source suggests that* copy* is an
action_plugin, and this somehow makes the copy module work.

"​copy" is actually both an action_plugin​ and a module

Is there somewhere that I can read more about this, or am I missing

something very basic?

​Not really, except the source itself. (*Seems like action_plugins are not
covered in http://docs.ansible.com/developing_modules.html)

* Modules and action plugins always ​work in pair.
* Most modules do not have a specific action plugin and are handled by the
normal (or async) action plugin.
* Some action modules do not have a module counterpart (e.g. the pause,
debug, group_by module, ..)
* And some modules have their own specific action plugin, like synchronize,
or copy.

I guess your best optiojns are to have a look at the code in the various
action plugins, and possibly the code in Runner._executor_internal_inner()
that drives them.

HTH,

  Serge

Thank you - that helps a lot. Ah, some digging to be done!

All the best,
Craig