Hi,
I’m a fresher in Ansible(actually all kinds of CMS), and trying to know how the modules works. I can easily understand the “time” example and even some more complex ones. However those involving operations over network,.e.g., copy module, confuse me a bit.
To my understanding, modules, who are pushed out of the ansible machine(A) to remote machines(B), are pieces of code running on B(hence obey the rules of the environment of B). It reports results back to A, and get deleted from B afterward. This means any operations over network in a modules are actually initiated on B, which also means, operation like copy, template, synchronize,etc, are all pull-style operations, from the standpoint of the B. Is my understanding correct?
If the above understanding is correct. How that works on network operation in modules? I’ve checked the code of the copy module, but find no such kind of code there, e.g., something like “scp foo@A:/the/src /dest/on/B” . There is a call on AnsibleModule.run_command() which seems do the trick, but it looks like just a simple local copy. I think my understanding has gone awry, but have no idea what it is. So I come here.
Thanks and Regards
John
The network-related operations can all be found in the connection plugins (e.g. https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/connection_plugins/ssh.py). Each module is only concerned with its particular logic, and not how it is copied and executed on the remote machines.
Modules like copy are made up of code that runs on the control machine (implemented as action plugins, e.g. https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/copy.py) combined with code that runs on the remote machines (implemented in the modules themselves, e.g. https://github.com/ansible/ansible/blob/devel/library/files/copy). Most modules, however, are implemented without action plugins.
Runner (https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/init.py) is responsible for pushing the module, running it and cleaning up afterward.
Ooh, That’s clear, I see. Thank you very much, Chris.
BTW, I guess those kind of information are in somewhere in the official document. Could you do me one more favor to point it out? I’d like to go through it thoroughly.
“BTW, I guess those kind of information are in somewhere in the official document.”
There are some good things to read about modules and action_plugins in http://docs.ansible.com/developing.html – it’s not comprehensive, but it’s a start.
Thanks, Micheal,
I’ve gone through the modules part of the document, will head on the action parts. Chris has unveiled that there must be a cooperation between code running on control machine(i.e., plugin) and code running on remote machine(module itself) for some kind of modules(e.g., copy ) to function properly. I’ve not found any elaboration on this cooperation in the development document though. Anyway, Ansible has been good enough for most of work. I’m just curious on that development part.
Easiest would be to just read the ‘action_plugins’ directory in the source tree, particularly how copy moves the file and the calls the ‘copy’ remote module, etc.
Thanks Michael.
Isn’t this a good practice on developing modules? I mean implementing a module by two parts(i.e., plugin and remote module) working together. A plugin is like kernel thing to me, which should be avoided in most case when developing a module I guess. Maybe for a new guy like me,I’ve gone way too far from the common cases.
Anyway I should read the source first. Thanks all you guys and don’t bother answer my question any more.
action_plugins are most always not needed except for things that have some local behavior.
95% (approx) of our modules do not have or need them, and most people don’t even know they exist 