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]
> <javascript:>> 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].
For more options, visit https://groups.google.com/d/optout.