mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
Modules don't have to return JSON, key=value pairs is ok.
This commit is contained in:
parent
40fd778e2c
commit
4bde4926c3
4 changed files with 29 additions and 21 deletions
|
@ -19,6 +19,9 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
import shlex
|
||||
from ansible.errors import *
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
|
@ -183,4 +186,26 @@ def async_poll_status(jid, host, clock, result):
|
|||
else:
|
||||
return "<job %s> polling on %s, %s remaining" % (jid, host, clock)
|
||||
|
||||
def parse_json(data):
|
||||
try:
|
||||
return json.loads(data)
|
||||
except:
|
||||
# not JSON, but try "Baby JSON" which allows many of our modules to not
|
||||
# require JSON and makes writing modules in bash much simpler
|
||||
results = {}
|
||||
tokens = shlex.split(data)
|
||||
for t in tokens:
|
||||
if t.find("=") == -1:
|
||||
raise AnsibleException("failed to parse: %s" % data)
|
||||
(key,value) = t.split("=", 1)
|
||||
if key == 'changed' or 'failed':
|
||||
if value.lower() in [ 'true', '1' ] :
|
||||
value = True
|
||||
elif value.lower() in [ 'false', '0' ]:
|
||||
value = False
|
||||
if key == 'rc':
|
||||
value = int(value)
|
||||
results[key] = value
|
||||
return results
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue