Ansible Acton Plugins

318 views
Skip to first unread message

Monty

unread,
Apr 15, 2016, 8:41:15 AM4/15/16
to Ansible Project
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. 

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.)

Mike Biancaniello

unread,
Apr 15, 2016, 9:46:22 AM4/15/16
to Ansible Project
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?

Vyacheslav

unread,
Jul 21, 2016, 9:07:49 AM7/21/16
to Ansible Project
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?

Mike Biancaniello

unread,
Jul 21, 2016, 10:06:34 AM7/21/16
to Ansible Project
Vyacheslav, I'm not sure I understand your question?

Vyacheslav Voronenko

unread,
Jul 21, 2016, 10:24:37 AM7/21/16
to ansible...@googlegroups.com
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.




--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/AIzW4z3dEL4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5659a1f3-0c44-4a28-9bde-ab47d529881d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Best Regards,
  Vyacheslav Voronenko

Mike Biancaniello

unread,
Jul 22, 2016, 11:02:16 AM7/22/16
to Ansible Project
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.

Vyacheslav Voronenko

unread,
Jul 22, 2016, 11:14:08 AM7/22/16
to ansible...@googlegroups.com
Where should the library/ be present?  Could it be also directory under playbook?

On Fri, Jul 22, 2016 at 6:02 PM, Mike Biancaniello <chep...@gmail.com> wrote:
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.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/AIzW4z3dEL4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mike Biancaniello

unread,
Jul 22, 2016, 11:25:38 AM7/22/16
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages