Module local action.

Hi,

I’m trying to understand Ansible internal process flow, especially on how it performs the actions.

What I dont understand is how it differentiates between a local action vs remote action.
I’ve read the ‘copy’ module, but there’s no logic there that check whether its for remote action or local action;
yet the ‘src’ takes a file on the local and ‘dest’ is on the remote.

Appreciate a pointer on this because currently I’m developing a module that requires some tasks to be done on local and remote at the same time.
Ie, updating local db, generate stuff on remote and update db again. I know ordering tasks in playbook can do it, but it does not seem elegent to me.

Thanks for the helps.

Hafiz

Modules themselves only execute in one place or the other: local or remote. Local actions are determined by prefacing the module call with the “local_action:” command, which means the module is executed locally no matter what the hosts list may be. The same effect can be accomplished by setting “hosts:” to just localhost (under the hood, local_action just sets the delegate_to option for the task to localhost).

The action plugins (found in lib/ansible/runner/action_plugins/) are what handles the logic of where things happen or how they’re called. For instance, copy.py is the action plugin that handles copy actions (and abstracts out some of the other actions, like slurp). So, if you’re wanting your module to execute both locally and remotely at the same time, you’ll need to look into writing your own action plugin as well as the module.

Thanks for the clarification.
That brings another question. I checked the ‘fetch’ module and there’s nothing there. It seems that all the logic are put into the ‘action_plugins’. The module itself just has the documentation.
My question is, how do you draw the line between putting stuff into module+action plugin where you can simply put everything into the ‘action_plugins’, like what ‘fetch’ does?

Thanks.

Fetch didn’t need a remote component because it was relying on on various SSH code that already existed, plus also slurp.

Thus what it has in there is to auto-generate the docs.

There are other examples like template that also utilize a plugin of the same name, though template also uses the file module in some cases.

We didn’t want to name the ‘fetch’ action_plugin ‘slurp’ because slurp is usable seperately and has some different semantics.

Ok, understood. Thank you very much for the clear explanation.