# starting to port modules over to the new common code stuff, need help … fire in the hole

**URL:** <https://forum.ansible.com/t/starting-to-port-modules-over-to-the-new-common-code-stuff-need-help-fire-in-the-hole/11712>\
**Category:** Ansible Project\
**Created:** [July 21, 2012, 9:20pm UTC](https://forum.ansible.com/t/starting-to-port-modules-over-to-the-new-common-code-stuff-need-help-fire-in-the-hole/11712 "2012-07-21T21:20:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 21, 2012, 9:20pm UTC](https://forum.ansible.com/t/starting-to-port-modules-over-to-the-new-common-code-stuff-need-help-fire-in-the-hole/11712/1 "2012-07-21T21:20:11Z")

</div>

I just ported the copy module over, as well as added the md5 function to the core API (because it is useful), saving about 40 lines of code.

See the source of library/copy for how it looks now -- this is the pattern to follow.

Who wants to help with others?

Here are the basic steps:

(1) Put the main body of the code for the module in a main() function if it does not already have one

(2) Put the magic import code at the bottom of the file

(3) At the top of the main function, instantiate the AnsibleModule class with a variable spec

(4) Replace any exit or fail methods with calls to module.exit\_json or module.fail\_json as appropriate. In fail\_json  
methods you may remove any setting of variables called "failed" as that is done for you. Replace any exit\_json  
calls that set "failed" with fail\_json calls.

(5) test the module using ./hacking/test-module, like this:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./hacking/test-module ./library/copy src=/tmp/alpha dest=/tmp/beta

As we port things, we may create bugs. This is why the development branch is exciting. Report them when you find them. Or better, fix them!

That's it! I am giving out double ansible bonus points to anyone helping with this. They can be redeemed at your local systems management software  
amusement park on Tuesdays for discounts on selected merchandise.

--Michael
