Two questions related to action_plugins

I’m currently developing a fairly involved action_plugin (which ideally would be shipped with a role, but could also be added to the appropriate path in ansible.cfg), and it seems there are a few limitations.

  1. is it possible for action_plugins and modules to share some code? I’d like to re-use the same constants that is used in an action_plugin in an (unrelated) module.

  2. is it possible to execute some sort of task-list from an action_plugin? I’ve tried all of import_tasks, include_tasks, import_role and include_role, but none of them seem to work, probably due to their ‘special’ non-module nature. I’m not too optimistic that there is something I can do, but maybe somebody on here can think of a workaround?

In a pinch I guess I can just execute the task-lists from a playbook using conditionals, but that’s going to be ugly, and ideally I’d like to just hide everything that is going on from the user.

1) yes, action plugins can use code in module_utils

2) no, only strategy plugins deal with task lists, action plugins
execute ONE action but cannot modify the list of tasks for the play.

  1. yes, action plugins can use code in module_utils

Even if that code is in a module_utils folder within a role? I tried that but couldn’t get it to work. That might have very well been my own fault though, will try again…

  1. no, only strategy plugins deal with task lists, action plugins
    execute ONE action but cannot modify the list of tasks for the play.

Ok, thanks for the confirmation. Much appreciated.

  1. yes, action plugins can use code in module_utils

Right, so I tried to do that, but I’m having trouble. This is my layout:

`

  • roles
    … etc
  • plays
  • ansible.cfg
  • playbook.yml
  • action_plugins
  • my_module_1.py
  • library
  • my_module_1.py
  • my_module_2.py
  • module_utils
  • my_module_utils.py
    `

I can do an import like this in any of the modules:

from ansible.module_utils.my_module_utils import TEST

That works fine.

But if I do the same thing in the action plugin, I’m getting an import error ala:

ImportError: No module namedmy_module_utils

Do I need to import it differently in an action plugin? I also tried to add an init.py file at the root of the module_utils folder, to no avail…

you can use “shipped” module utils, but the user supplied ones ONLY eork for modules.