# Custom module error

**URL:** <https://forum.ansible.com/t/custom-module-error/25205>\
**Category:** Ansible Developer\
**Created:** [August 8, 2017, 5:28pm UTC](https://forum.ansible.com/t/custom-module-error/25205 "2017-08-08T17:28:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Adam](https://forum.ansible.com/u/Adam)\
**Post date:** [August 8, 2017, 5:28pm UTC](https://forum.ansible.com/t/custom-module-error/25205/1 "2017-08-08T17:28:17Z")

</div>

Hi all -

I’m working on a custom module in python that takes a subset of an XML config, and turns it into JSON so I can use it with an Ansible playbook & Jinja2 template.

My python code works fine to parse the output, but my module continually fails for reasons I can’t explain. Can someone give me a hint?

**Module code:**

#!/usr/bin/python

ANSIBLE\_METADATA = {  
‘metadata\_version’: ‘1.0’,  
‘status’: [‘preview’],  
‘supported\_by’: ‘curated’  
}

import os  
import shutil  
import tempfile  
import traceback  
import xml.etree.cElementTree as etree  
import json

from ansible.module\_utils.basic import AnsibleModule  
from ansible.module\_utils.\_text import to\_bytes, to\_native

from collections import defaultdict

class Xml2Dict(dict):  
def **init** (self, parent\_element):  
if parent\_element.items():  
self.updateDict( dict(parent\_element.items()) )  
for element in parent\_element:  
if len(element):  
aDict = Xml2Dict(element)  
self.updateDict({element.tag: aDict})  
elif element.items(): # items() is special for attributes  
elementattrib= element.items()  
if element.text:  
elementattrib.append((element.tag,element.text )) # add tag:text if exist  
self.updateDict({element.tag: dict(elementattrib)})  
else:  
self.updateDict({element.tag: element.text})

def updateDict (self, aDict ):  
for key in aDict.keys(): # keys() includes tag and attributes  
if key in self:  
value = self.pop(key)  
if type(value) is not list:  
listOfDicts =   
listOfDicts.append(value)  
listOfDicts.append(aDict[key])  
self.update({key: listOfDicts})  
else:  
value.append(aDict[key])  
self.update({key: value})  
else:  
self.update({key:aDict[key]}) # it was self.update(aDict)

def run\_module():

# define the available arguments/parameters that a user can pass to

# the module

module\_args = dict(  
src=dict(type=‘path’)  
)

# seed the result dict in the object

# we primarily care about changed and state

# change is if this module effectively modified the target

# state will include any data that you want your module to pass back

# for consumption, for example, in a subsequent task

result = dict(  
changed=False,  
original\_message=‘’,  
message=‘’,  
failed=‘’  
)

# the AnsibleModule object will be our abstraction working with Ansible

# this includes instantiation, a couple of common attr would be the

# args/params passed to the execution, as well as if the module

# supports check mode

module = AnsibleModule(  
argument\_spec=module\_args,  
supports\_check\_mode=True  
)

src = module.params[‘src’]

# b\_src = to\_bytes(src, errors=‘surrogate\_or\_strict’)

# if not os.path.exists(b\_src):

# module.fail\_json(msg=“Source %s not found” % (src))

# if not os.access(b\_src, os.R\_OK):

# module.fail\_json(msg=“Source %s not readable” % (src))

# if os.path.isdir(b\_src):

# module.fail\_json(msg=“Directory specified as the source instead of a file: %s” % (src))

# if os.path.exists(b\_src):

# b\_src = os.path.realpath(b\_src)

# src = to\_native(b\_src, errors=‘surrogate\_or\_strict’)

# if os.access(b\_src, os.R\_OK):

tree = etree.ElementTree(file=src)  
#print tree.getroot()  
root = tree.getroot()  
#print “tag=%s, attrib=%s” % (root.tag, root.attrib)

from pprint import pprint  
#router = pprint(etree\_to\_dict(root))  
router = Xml2Dict(root)

for key in router[‘swiftlet’][4].iteritems():  
if key[0] == ‘aliases’:  
for item in enumerate(key[1][‘alias’]):  
dest = str(item[1][‘map-to’])  
name = str(item[1][‘name’])

# print dest + “:” + name

queuesList =   
for key in router[‘swiftlet’][9].iteritems():  
if key[0] == ‘queues’:  
for item in enumerate(key[1][‘queue’]):  
name = str(item[1][‘name’])  
attrList = item[1]  
print attrList  
queueDict = {}

if len(attrList) == 1:  
queueDict[name] = {“propertyCount” : len(attrList)}  
else:  
for attrib, value in attrList.iteritems():  
if attrib != “name”:  
if name in queueDict:  
queueDict[name][attrib] = value  
else:  
queueDict[name] = {attrib : value}  
if name in queueDict:  
queueDict[name][“propertyCount”] = len(attrList)  
else:  
queueDict[name] = {“propertyCount” : len(attrList)}

queuesList.append(queueDict)

output = json.dumps(queuesList)

# if the user is working with this module in only check mode we do not

# want to make any changes to the environment, just return the current

# state with no modifications

# if module.check\_mode:

# return result

# manipulate or modify the state as needed (this is going to be the

# part where your module will do what it needs to do)

result[‘original\_message’] = module.params[‘src’]  
result[‘message’] = ‘goodbye’

# use whatever logic you need to determine whether or not this module

# made any modifications to your target

# if module.params[‘src’]:

# result[‘changed’] = True

# during the execution of the module, if there is an exception or a

# conditional state that effectively causes a failure, run

# AnsibleModule.fail\_json() to pass in the message and the result

# if module.params[‘src’] == ‘fail me’:

# module.fail\_json(msg=‘You requested this to fail’, \*\*result)

# in the event of a successful module execution, you will want to

# simple AnsibleModule.exit\_json(), passing the key/value results

module.exit\_json(  
changed=True,  
failed=False)

def main():  
run\_module()

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

**Results:**

TASK [test module] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ec2-user/ansible/testmod.yml:7  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/\_text.py  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/basic.py  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/six/ **init**.py  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/parsing/convert\_bool.py  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/parsing/ **init**.py  
Using module\_utils file /home/ec2-user/ansible/lib/ansible/module\_utils/pycompat24.py  
Using module file /home/ec2-user/ansible/lib/ansible/modules/messaging/new\_module.py  
\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: ec2-user  
\<127.0.0.1\> EXEC /bin/sh -c ‘echo ~ && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224`” && echo ansible-tmp-1502132102.2-141765875120224=“`echo /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224`” ) && sleep 0’  
\<127.0.0.1\> PUT /tmp/tmpHHjMUg TO /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224/new\_module.py  
\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224/ /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224/new\_module.py && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘/home/ec2-user/ansible/venv/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224/new\_module.py; rm -rf “/home/ec2-user/.ansible/tmp/ansible-tmp-1502132102.2-141765875120224/” \> /dev/null 2\>&1 && sleep 0’  
fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “”,  
“module\_stdout”: “{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q1’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q2’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q3’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘name’: ‘test’}\n\n{"invocation": {"module\_args": {"src": "/home/ec2-user/ansible/routerconfig.xml"}}, "failed": false, "changed": true}\n”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0  
}  
to retry, use: --limit @/home/ec2-user/ansible/testmod.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=1 changed=0 unreachable=0 failed=1

**My playbook is below:**

- name: test  
gather\_facts: yes  
hosts: localhost  
connection: local

tasks:

- name: test module  
new\_module:  
src: /home/ec2-user/ansible/routerconfig.xml  
register: testout

- name: debug  
debug:  
msg: ‘{{testout}}’

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [August 8, 2017, 7:12pm UTC](https://forum.ansible.com/t/custom-module-error/25205/2 "2017-08-08T19:12:33Z")

</div>

First glance, looks like quoting issue. Module output seems to include a mix of single and double quotes. module output should be json with double quotes.

Looks like:

output = json.dumps(queuesList)

is going to make output a string with json in it. If you want the

structured data in the result, you will want to include queuesList

as a value to exit\_json()

# assumes queuesList object can be json serialized. If not, you will need to wrap it or transform it

# to something that is (eg, a dict with string keys and values)

module.exit\_json(changed=True, failed=False, {‘queueslist’: queuesList})

(your pasted code also doesn’t include ‘output’ in it’s returns in exit\_json or fail\_json. Those need to include the data to be returned)

Can you post the stdout output from the module called directly?

a couple of ways to do that:

1. use hacking/test-module

# from ansible src checkout, assuming custom module is at ~/new\_module

$ hacking/test-module -m ~/new\_module -a ‘src=/home/ec2-user/ansible/routerconfig.xml’

1. use ad hoc mode

# assumes new\_module is somewhere on ansible module library path

$ ansible -v localhost -m new\_module -a ‘src=/home/ec2-user/ansible/routerconfig.xml’

---

<div class="post-metadata">

**Author:** ![Adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Adam](https://forum.ansible.com/u/Adam)\
**Post date:** [August 9, 2017, 5:40pm UTC](https://forum.ansible.com/t/custom-module-error/25205/3 "2017-08-09T17:40:43Z")

</div>

Hi Adrian -

I think you’re right about the quoting. Here’s the ouput without any modifications to my module:

ansible -v localhost -m new\_module -a ‘src=/home/ec2-user/ansible/routerconfig.xml’  
Using /etc/ansible/ansible.cfg as config file  
[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

localhost | FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “”,  
“module\_stdout”: “{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q1’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q2’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q3’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘name’: ‘test’}\n\n{"invocation": {"module\_args": {"src": "/home/ec2-user/ansible/routerconfig.xml"}}, "failed": false, "changed": true}\n”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0  
}

When I add:  
module.exit\_json(changed=True, failed=False, {‘queueslist’: queuesList})

I get the following output:

ansible -vvv localhost -m new\_module -a ‘src=/home/ec2-user/ansible/routerconfig.xml’  
ansible 2.4.0 (devel ca7ce4459d) last updated 2017/08/07 10:33:25 (GMT -400)  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/home/ec2-user/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /home/ec2-user/ansible/lib/ansible  
executable location = /home/ec2-user/ansible/bin/ansible  
python version = 2.6.6 (r266:84292, Nov 21 2013, 10:50:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]  
Using /etc/ansible/ansible.cfg as config file  
Parsed /etc/ansible/hosts inventory source with ini plugin  
[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

META: ran handlers  
The full traceback is:  
Traceback (most recent call last):  
File “/home/ec2-user/ansible/lib/ansible/executor/task\_executor.py”, line 125, in run  
res = self.\_execute()  
File “/home/ec2-user/ansible/lib/ansible/executor/task\_executor.py”, line 526, in \_execute  
result = self.\_handler.run(task\_vars=variables)  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/normal.py”, line 45, in run  
results = merge\_hash(results, self.\_execute\_module(tmp=tmp, task\_vars=task\_vars, wrap\_async=wrap\_async))  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/ **init**.py”, line 629, in \_execute\_module  
(module\_style, shebang, module\_data, module\_path) = self.\_configure\_module(module\_name=module\_name, module\_args=module\_args, task\_vars=task\_vars)  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/ **init**.py”, line 164, in \_configure\_module  
environment=final\_environment)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 869, in modify\_module  
environment=environment)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 695, in \_find\_module\_utils  
recursive\_finder(module\_name, b\_module\_data, py\_module\_names, py\_module\_cache, zf)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 466, in recursive\_finder  
tree = ast.parse(data)  
File “/usr/lib64/python2.6/ast.py”, line 37, in parse  
return compile(expr, filename, mode, PyCF\_ONLY\_AST)  
File “”, line 162  
SyntaxError: non-keyword arg after keyword arg (, line 162)

localhost | FAILED! =\> {  
“failed”: true,  
“msg”: “Unexpected failure during module execution.”,  
“stdout”: “”  
}

If I change that line to be:  
module.exit\_json(changed=True, failed=False, {‘queueslist’: output})

I get the following output:

ansible -vvv localhost -m new\_module -a ‘src=/home/ec2-user/ansible/routerconfig.xml’  
ansible 2.4.0 (devel ca7ce4459d) last updated 2017/08/07 10:33:25 (GMT -400)  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/home/ec2-user/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /home/ec2-user/ansible/lib/ansible  
executable location = /home/ec2-user/ansible/bin/ansible  
python version = 2.6.6 (r266:84292, Nov 21 2013, 10:50:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]  
Using /etc/ansible/ansible.cfg as config file  
Parsed /etc/ansible/hosts inventory source with ini plugin  
[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

META: ran handlers  
The full traceback is:  
Traceback (most recent call last):  
File “/home/ec2-user/ansible/lib/ansible/executor/task\_executor.py”, line 125, in run  
res = self.\_execute()  
File “/home/ec2-user/ansible/lib/ansible/executor/task\_executor.py”, line 526, in \_execute  
result = self.\_handler.run(task\_vars=variables)  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/normal.py”, line 45, in run  
results = merge\_hash(results, self.\_execute\_module(tmp=tmp, task\_vars=task\_vars, wrap\_async=wrap\_async))  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/ **init**.py”, line 629, in \_execute\_module  
(module\_style, shebang, module\_data, module\_path) = self.\_configure\_module(module\_name=module\_name, module\_args=module\_args, task\_vars=task\_vars)  
File “/home/ec2-user/ansible/lib/ansible/plugins/action/ **init**.py”, line 164, in \_configure\_module  
environment=final\_environment)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 869, in modify\_module  
environment=environment)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 695, in \_find\_module\_utils  
recursive\_finder(module\_name, b\_module\_data, py\_module\_names, py\_module\_cache, zf)  
File “/home/ec2-user/ansible/lib/ansible/executor/module\_common.py”, line 466, in recursive\_finder  
tree = ast.parse(data)  
File “/usr/lib64/python2.6/ast.py”, line 37, in parse  
return compile(expr, filename, mode, PyCF\_ONLY\_AST)  
File “”, line 163  
SyntaxError: non-keyword arg after keyword arg (, line 163)

localhost | FAILED! =\> {  
“failed”: true,  
“msg”: “Unexpected failure during module execution.”,  
“stdout”: “”  
}

Sorry if I’m being dense here. I’m sure it’s something I’m doing wrong, but I don’t know how to tell what it is.

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [August 9, 2017, 6:13pm UTC](https://forum.ansible.com/t/custom-module-error/25205/4 "2017-08-09T18:13:10Z")

</div>

comments inl

---

<div class="post-metadata">

**Author:** ![Adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Adam](https://forum.ansible.com/u/Adam)\
**Post date:** [August 9, 2017, 6:52pm UTC](https://forum.ansible.com/t/custom-module-error/25205/5 "2017-08-09T18:52:05Z")

</div>

Thanks. I changed my module & the result is below. I guess since queuesList is technically a list of dicts, it can’t be automatically serialized? If I change it from a list to a dict, then I assume things should be easier to handle automatically? I guess I need to do more research on how to serialize things.

localhost | FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “”,  
“module\_stdout”: “{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q1’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q2’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q3’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}\n{‘name’: ‘test’}\n\n{"invocation": {"module\_args": {"src": "/home/ec2-user/ansible/routerconfig.xml"}}, "failed": false, "changed": true, "queueslist": [{"q1": {"cache-size": "5000", "flowcontrol-start-queuesize": "-1", "propertyCount": 5, "cleanup-interval": "-1", "persistence-mode": "non\_persistent"}}, {"q2": {"cache-size": "5000", "flowcontrol-start-queuesize": "-1", "propertyCount": 5, "cleanup-interval": "-1", "persistence-mode": "non\_persistent"}}, {"q3": {"cache-size": "5000", "flowcontrol-start-queuesize": "-1", "propertyCount": 5, "cleanup-interval": "-1", "persistence-mode": "non\_persistent"}}, {"test": {"propertyCount": 1}}]}\n”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0  
}

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [August 9, 2017, 7:51pm UTC](https://forum.ansible.com/t/custom-module-error/25205/6 "2017-08-09T19:51:08Z")

</div>

comments inl

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [August 9, 2017, 8:01pm UTC](https://forum.ansible.com/t/custom-module-error/25205/7 "2017-08-09T20:01:55Z")

</div>

A list should be fine, and looking at how queuesList is populated, I don’t see any obvious that would not be json serializable.

But to diagnose/debug further, really need the stdout output from invoking the module directly. ie:

# cd to your ansible src checkout

$ cd ~/src/ansible

$ source hacking/env-setup

$ hacking/test-module -m /path/to/your/new\_module.py -a ‘src=/home/ec2-user/ansible/routerconfig.xml’

Looks like your module is writing to stdout from somewhere other than module.exit\_json(), likely via print() in the module code.

The module output has to be _just_ valid json on stdout (the data that exit\_json() writes to stdout). Anything else will cause

failures.

ie, the module stdout is:

"{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q1’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}  
{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q2’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}  
{‘cache-size’: ‘5000’, ‘flowcontrol-start-queuesize’: ‘-1’, ‘name’: ‘q3’, ‘cleanup-interval’: ‘-1’, ‘persistence-mode’: ‘non\_persistent’}  
{‘name’: ‘test’}

{“invocation”: {“module\_args”: {“src”: “/home/ec2-user/ansible/routerconfig.xml”}}, “failed”: false, “changed”: true, “queueslist”: [{“q1”: {“cache-size”: “5000”, “flowcontrol-start-queuesize”: “-1”, “propertyCount”: 5, “cleanup-interval”: “-1”, “persistence-mode”: “non\_persistent”}}, {“q2”: {“cache-size”: “5000”, “flowcontrol-start-queuesize”: “-1”, “propertyCount”: 5, “cleanup-interval”: “-1”, “persistence-mode”: “non\_persistent”}}, {“q3”: {“cache-size”: “5000”, “flowcontrol-start-queuesize”: “-1”, “propertyCount”: 5, “cleanup-interval”: “-1”, “persistence-mode”: “non\_persistent”}}, {“test”: {“propertyCount”: 1}}]}

That first blob looks like debug output to stdout, which is confusing the module runner. rm it, or write debug info to stderr to avoid the problem.

---

<div class="post-metadata">

**Author:** ![Adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Adam](https://forum.ansible.com/u/Adam)\
**Post date:** [August 17, 2017, 12:07am UTC](https://forum.ansible.com/t/custom-module-error/25205/8 "2017-08-17T00:07:32Z")

</div>

Hey Adrian -

It’s taken me a few days to get back to this, but I wanted to thank you for your advice. You were right about me having an extra print statement in my python & it throwing things off. I finally went through it slowly & figured it out (much simpler than I was making it out to be). Thanks again!

-Adam
