Ansible Acton Plugins

I am trying to write a ansible action plugin. The reason i am doing this is, I want to access my variables available in playbook (modules can only deal with args as far i understand, please correct me if i am wrong )

Now writing this plugin, what is the directory structure i should have? i tried (action_plugins/, library/, tests/ ) , library/action_plugins, tests/ ) they don’t work.
The moment i start using the 2nd dir structure all the imports fail, first one does not work at all.

I found a few examples, like this http://jpmens.net/2012/11/03/an-action-plugin-for-ansible-to-handle-ssh-host-keys/
But does not discuss about the dir structure.

I am planning to use this plugin by putting this into requirements.yml and installing it in the playbook. Can any one suggest what i am doing wrong.
(Ansible versions 1.9, i cannot really upgrade it.)

Action plugins need to be in the action_plugins/ dir (can be either a subdir of the playbook_dir or of a role that you include), however, ansible won’t recognize the plugin uless you also have a file of the same name in the library/ dir. All you need to do is ‘touch’ the library file, but you should at least use this to store the module documentation. Remember, though, that action_plugins are executed on localhost, so action_plugin is often used for local preprocessing before calling the module to do the remote work.

All of that being said, why can’t you just pass the module the args that you need?

Mike,

I think, I have similar issue.

Mine local lookup plugins from playbook_dir/lookup_plugins are loaded and executed fine, but the same manner implemented action plugins are not loaded from file like playbook_dir/action_plugins/action.py

Is there additional magic linked to library too ? Is there way I can distribute local action plugin with playbook?

Vyacheslav, I’m not sure I understand your question?

in my case actions plugins are not picked up from action_plugins/ folder, but lookup one do from lookup_plugins/ folder. Perhaps I missing smth obvious.

i.e. I have set of lookup plugins:

/deployment/boxes/lookup_plugins
➜ lookup_plugins git:(feature-standalone-gl-ee) ls *.py
aws_ec2_allocation_id_from_eip.py aws_secgroup_ids_from_names.py aws_subnet_ids_from_names.py aws_vpc_id_from_name.py sa_hashi_vault.py

and lookup plugins are picked just fine, I am able to use them in playbook

But the action plugins from /deployment/boxes/action_plugins are not loaded or detected by ansible.

action_plugins/ will not be picked up by ansible unless there is a file in library/ with the same name. This file in library/ can be empty, but it must exist.

Where should the library/ be present? Could it be also directory under playbook?

try creating /deployment/boxes/library/
and placing your files there.

Usually, unless you change your ansible.cfg, the plugins, roles, libraries, etc are all subdirs of your playbook dir.