# subclassing ActionModule classes

**URL:** <https://forum.ansible.com/t/subclassing-actionmodule-classes/16905>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [November 27, 2014, 6:44pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905 "2014-11-27T18:44:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 27, 2014, 6:44pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/1 "2014-11-27T18:44:22Z")

</div>

Hello

I’m working on versions of file copy and template for windows.  
I’ve push a ‘first pass’ PR here [https://github.com/ansible/ansible/pull/9611](https://github.com/ansible/ansible/pull/9611) and here [https://github.com/ansible/ansible-modules-core/pull/384](https://github.com/ansible/ansible-modules-core/pull/384) but there’s things I want to improve, specifically the action plugins, which at the  
moment are pretty much copy ‘n’ pasted versions of their non-windows counterparts.

So obvious thing to do is subclass ActionModule and just have the windows versions doing windows things.  
I notice there’s no precedent for this at the moment. Is this just because the need hasn’t really arisen or a desire to keep  
things simple.

Thought it was worth asking before I plunged in.

BTW I’m also going to move the file hash functions to use SHA1

Jon

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 1, 2014, 11:44pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/2 "2014-12-01T23:44:40Z")

</div>

module\_utils/ has a good place to put shared code, and has a common library of powershell things therein.

There is no provision for subclassing, but this will get you the capabilities you want, I think.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [December 3, 2014, 11:35am UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/3 "2014-12-03T11:35:41Z")

</div>

Thanks, that’s a good idea I’ll look into using module\_utils/ - I was more thinking along the lines of reusing the python logic used for templates (where most of the good stuff is happening on the controller not in the actual powershell modules), but no reason I couldn’t pull some of that into module\_utils.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [December 3, 2014, 3:31pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/4 "2014-12-03T15:31:31Z")

</div>

Also, for what it’s worth, using a base class for each individual plugin type is something I’m actively working on in the v2 branch of code. For example, all action plugins, connection plugins, etc. will have their own base class to share code and remove these redundancies.

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 3, 2014, 3:45pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/5 "2014-12-03T15:45:58Z")

</div>

>

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [December 3, 2014, 9:04pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/6 "2014-12-03T21:04:14Z")

</div>

I like it. It only adds a little complexity in return for some good reuse.

For what it’s worth I have a windows unarchive module which I’m working on which where I’d like to reuse the unarchive action plugin in the same way.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 3, 2014, 11:04pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/7 "2014-12-03T23:04:23Z")

</div>

Seems like a good idea to me - I’m open to exploring it under the v2 subtree once we fold it in, and should keep track of this idea for now.

Right now, I’m trying to lock down core changes on the old branch, and we’d likely have to repeat efforts slightly as this moves over.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [December 9, 2014, 11:53pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/8 "2014-12-09T23:53:50Z")

</div>

I have updated [https://github.com/ansible/ansible/pull/9611](https://github.com/ansible/ansible/pull/9611) with the ‘copy and paste’ implementations for now. Sounds like it is just the wrong time for this particular idea, but people can at least try out the modules now even if v2 subtree needs to be ready to go before it actually gets merged in.

Jon

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 11, 2014, 11:50pm UTC](https://forum.ansible.com/t/subclassing-actionmodule-classes/16905/9 "2014-12-11T23:50:59Z")

</div>

Thanks – we’re going to plow through things though this should be easier soon. Appreciate your bearing with us.
