# Unable to use test-module to develop modules under Arch Linux

**URL:** <https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [December 16, 2016, 9:06am UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272 "2016-12-16T09:06:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Klaus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Andrew\_Klaus](https://forum.ansible.com/u/Andrew_Klaus)\
**Post date:** [December 16, 2016, 9:06am UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272/1 "2016-12-16T09:06:51Z")

</div>

Hi guys, I’m trying to write some modules for Ansible, but getting stumped on this error below…

OS: Arch Linux  
Linux laps 4.4.37-1-lts #1 SMP Thu Dec 8 22:29:57 CET 2016 x86\_64 GNU/Linux

I git cloned the ansible repo and ran the env-setup successfully:

$ source ansible/hacking/env-setup  
running egg\_info  
creating lib/ansible.egg-info  
writing top-level names to lib/ansible.egg-info/top\_level.txt  
writing requirements to lib/ansible.egg-info/requires.txt  
writing lib/ansible.egg-info/PKG-INFO  
writing dependency\_links to lib/ansible.egg-info/dependency\_links.txt  
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’  
reading manifest file ‘lib/ansible.egg-info/SOURCES.txt’  
reading manifest template ‘MANIFEST.in’  
no previously-included directories found matching ‘v2’  
no previously-included directories found matching ‘docsite’  
no previously-included directories found matching ‘ticket\_stubs’  
no previously-included directories found matching ‘packaging’  
no previously-included directories found matching ‘test’  
no previously-included directories found matching ‘hacking’  
warning: no previously-included files found matching ‘lib/ansible/modules/core/.git\*’  
warning: no previously-included files found matching ‘lib/ansible/modules/extras/.git\*’  
no previously-included directories found matching ‘lib/ansible/modules/core/.git’  
no previously-included directories found matching ‘lib/ansible/modules/extras/.git’  
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’

Setting up Ansible to run out of checkout…

PATH=/home/user/git/ansible/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site\_perl:/usr/bin/vendor\_perl:/usr/bin/core\_perl  
PYTHONPATH=/home/user/git/ansible/lib:  
MANPATH=/home/user/git/ansible/docs/man:

Remember, you may wish to specify your host file with -i

Done!

I created a bare minimum module file to use (confirmed it works on Ubuntu 16.04):

$ cat test.py  
from ansible.module\_utils.basic import AnsibleModule

def main():  
module = AnsibleModule(  
argument\_spec = dict(  
state = dict(default=‘present’, choices=[‘present’, ‘absent’]),  
name = dict(required=True),  
enabled = dict(required=True, type=‘bool’),  
something = dict(aliases=[‘whatever’])  
)  
)

module.exit\_json(changed=True, something\_else=12345)

if **name** == ‘ **main** ’:  
main()

Running the test-module asks for options (as expected)

$ ./ansible/hacking/test-module  
Usage: test-module -[options] (-h for help)

Options:  
-h, --help show this help message and exit  
-m MODULE\_PATH, --module-path=MODULE\_PATH  
REQUIRED: full path of module source to execute  
-a MODULE\_ARGS, --args=MODULE\_ARGS  
module argument string  
-D DEBUGGER, --debugger=DEBUGGER  
path to python debugger (e.g. /usr/bin/pdb)  
-I INTERPRETER\_TYPE=INTERPRETER\_PATH, --interpreter=INTERPRETER\_TYPE=INTERPRETER\_PATH  
path to interpreter to use for this module (e.g.  
ansible\_python\_interpreter=/usr/bin/python)  
-c, --check run the module in check mode  
-n, --noexecute do not run the resulting module  
-o FILENAME, --output=FILENAME  
Filename for resulting module

However, when running the module with test-module (with and without the --interpreter flag present), results in the following error:

$ ./ansible/hacking/test-module -m test.py --interpreter=ansible\_python\_interpreter=/usr/bin/python2  
Traceback (most recent call last):  
File “./ansible/hacking/test-module”, line 245, in   
main()  
File “./ansible/hacking/test-module”, line 227, in main  
(modfile, modname, module\_style) = boilerplate\_module(options.module\_path, options.module\_args, options.interpreter, options.check, options.filename)  
File “./ansible/hacking/test-module”, line 149, in boilerplate\_module  
if module\_style == ‘new’ and ‘ANSIBALLZ\_WRAPPER = True’ in module\_data:  
TypeError: a bytes-like object is required, not ‘str’

From what I read it sounds like it’s a python3-related error, but overriding the interpreter I would assume would use python2.

Any insight into fixing this would be great.

Andrew

---

<div class="post-metadata">

**Author:** ![James\_Pic](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@James\_Pic](https://forum.ansible.com/u/James_Pic)\
**Post date:** [December 16, 2016, 2:31pm UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272/2 "2016-12-16T14:31:29Z")

</div>

Hi Andrew,

Did you try something like b’ANSIBALLZ\_WRAPPER = True’ ?

Perhaps you can find more hints here: [http://www.diveintopython3.net/strings.html#byte-arrays](http://www.diveintopython3.net/strings.html#byte-arrays)

---

<div class="post-metadata">

**Author:** ![James\_Pic](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@James\_Pic](https://forum.ansible.com/u/James_Pic)\
**Post date:** [December 16, 2016, 2:34pm UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272/3 "2016-12-16T14:34:29Z")

</div>

PS: this is just to try, then for the fix that will support both python 2 & 3 you’ll have to use something like six, ie: [https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/source\_control/git.py#L242](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/source_control/git.py#L242)

Hope this helps

---

<div class="post-metadata">

**Author:** ![Andrew\_Klaus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Andrew\_Klaus](https://forum.ansible.com/u/Andrew_Klaus)\
**Post date:** [December 17, 2016, 6:12am UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272/4 "2016-12-17T06:12:54Z")

</div>

Thanks for the suggestions.

Changing it to b’ANSIBALLZ\_WRAPPER = True’ ended up giving me this error:

modfile2.write(module\_data)  
#!/usr/bin/env python  
TypeError: write() argument must be str, not bytes

Then changing it to modfile2.write(str(module\_data)) to see what would happen ended up with:

File “/usr/lib/python3.5/subprocess.py”, line 1551, in \_execute\_child  
raise child\_exception\_type(errno\_num, err\_msg)  
OSError: [Errno 8] Exec format error

I changed the shebang in the test-module from #!/usr/bin/env python to #!/usr/bin/env python2 seemed to do the trick though…

Andrew

---

<div class="post-metadata">

**Author:** ![Poojitha\_A](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@Poojitha\_A](https://forum.ansible.com/u/Poojitha_A)\
**Post date:** [February 15, 2017, 6:34am UTC](https://forum.ansible.com/t/unable-to-use-test-module-to-develop-modules-under-arch-linux/23272/5 "2017-02-15T06:34:20Z")

</div>

Hi Guys, can we use a test.pyo file instead of a test.py file to provide module-path?
