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
On Wednesday, August 9, 2017 at 4:02:00 PM UTC-4, Adrian Likins wrote:
>
> 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.
>
> On Wed, Aug 9, 2017 at 2:52 PM, Adam Shantz <[email protected]
> <javascript:>> wrote:
>
>> 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
>> }
>>
>> On Wednesday, August 9, 2017 at 2:13:17 PM UTC-4, Adrian Likins wrote:
>>>
>>> comments inl
>>>
>>>
>>> On Wed, Aug 9, 2017 at 1:40 PM, Adam Shantz <[email protected]> wrote:
>>>
>>>> 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})
>>>>
>>>
>>>
>>>> <..>
>>>> File "<unknown>", line 162
>>>> SyntaxError: non-keyword arg after keyword arg (<unknown>, line 162)
>>>>
>>>>
>>> Ah, sorry I should have said:
>>>
>>> module.exit_json(changed=True, failed=False, queueslist=queuesList)
>>>
>>> The adds 'queueslist' item to the return data dict with a value of the
>>> queuesList object.
>>>
>>> The module will try to serialize the keyword args as a dict, add it to
>>> the rest of the return
>>> object, and print the JSON to stdout. ansible will wrap that up in but
>>> the module by
>>> itself will do that (ie, as invoked by 'test-module')
>>>
>>> The module output should look something roughly like:
>>>
>>>
>>> {
>>> "invocation": {
>>> "module_args": {
>>> "src": "/home/ec2-user/ansible/routerconfig.xml"
>>> }
>>> },
>>> "failed": false,
>>> "changed": true,
>>> "queueslist": ["whatever_a_queuesList_serializes_to_item1",
>>> "another_item_in_queueslist"]
>>> }
>>>
>>>
>>>
>>> If I change that line to be:
>>>> module.exit_json(changed=True, failed=False, {'queueslist': output})
>>>>
>>> SyntaxError: non-keyword arg after keyword arg (<unknown>, line 163)
>>>
>>>
>>> Same issue as above (ie, my bad example)
>>>
>>> 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.
>>>>
>>>
>>> The next issue will be if queuesList is json serializable or not. If you
>>> get an error about that, you will likely need to
>>> build a simpler object (like a dict) from queuesList to serialize.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.