# Two questions related to action\_plugins

**URL:** <https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059>\
**Category:** Ansible Developer\
**Created:** [July 16, 2018, 5:40pm UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059 "2018-07-16T17:40:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcus\_B](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Marcus\_B](https://forum.ansible.com/u/Marcus_B)\
**Post date:** [July 16, 2018, 5:40pm UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059/1 "2018-07-16T17:40:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 16, 2018, 5:45pm UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059/2 "2018-07-16T17:45:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marcus\_B](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Marcus\_B](https://forum.ansible.com/u/Marcus_B)\
**Post date:** [July 16, 2018, 7:55pm UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059/3 "2018-07-16T19:55:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marcus\_B](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Marcus\_B](https://forum.ansible.com/u/Marcus_B)\
**Post date:** [July 17, 2018, 10:36am UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059/4 "2018-07-17T10:36:08Z")

</div>

> 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…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 17, 2018, 1:19pm UTC](https://forum.ansible.com/t/two-questions-related-to-action-plugins/28059/5 "2018-07-17T13:19:39Z")

</div>

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