Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
4bde4926
Commit
4bde4926
authored
Mar 14, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modules don't have to return JSON, key=value pairs is ok.
parent
40fd778e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
21 deletions
+29
-21
lib/ansible/runner.py
+2
-7
lib/ansible/utils.py
+25
-0
library/copy
+2
-13
test/TestRunner.py
+0
-1
No files found.
lib/ansible/runner.py
View file @
4bde4926
...
...
@@ -18,11 +18,6 @@
################################################
try
:
import
json
except
ImportError
:
import
simplejson
as
json
import
fnmatch
import
multiprocessing
import
signal
...
...
@@ -209,7 +204,7 @@ class Runner(object):
try
:
# try to parse the JSON response
return
[
host
,
True
,
json
.
loads
(
result
)
]
return
[
host
,
True
,
parse_json
(
result
)
]
except
Exception
,
e
:
# it failed, say so, but return the string anyway
return
[
host
,
False
,
"
%
s/
%
s"
%
(
str
(
e
),
result
)
]
...
...
@@ -324,7 +319,7 @@ class Runner(object):
if
self
.
module_name
==
'setup'
:
host
=
conn
.
host
try
:
var_result
=
json
.
loads
(
result
)
var_result
=
parse_json
(
result
)
except
:
var_result
=
{}
...
...
lib/ansible/utils.py
View file @
4bde4926
...
...
@@ -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
library/copy
View file @
4bde4926
...
...
@@ -22,11 +22,6 @@ import sys
import
os
import
shlex
try
:
import
json
except
ImportError
:
import
simplejson
as
json
# ===========================================
# convert arguments of form a=b c=d
# to a dictionary
...
...
@@ -51,10 +46,7 @@ dest = params['dest']
# raise an error if there is no src file
if
not
os
.
path
.
exists
(
src
):
print
json
.
dumps
({
"failed"
:
1
,
"msg"
:
"Source
%
s failed to transfer"
%
src
})
print
"failed=1 msg='Source
%
s failed to transfer'"
%
src
sys
.
exit
(
1
)
md5sum
=
None
...
...
@@ -70,9 +62,6 @@ if md5sum != md5sum2:
changed
=
True
# mission accomplished
print
json
.
dumps
({
"md5sum"
:
md5sum2
,
"changed"
:
changed
})
print
"md5sum=
%
s changed=
%
s"
%
(
md5sum2
,
changed
)
test/TestRunner.py
View file @
4bde4926
...
...
@@ -148,7 +148,6 @@ class TestRunner(unittest.TestCase):
result
=
self
.
_run
(
'shell'
,
[
"/bin/echo"
,
"$HOME"
])
assert
'failed'
not
in
result
assert
result
[
'rc'
]
==
0
raise
Exception
(
result
[
'stdout'
])
def
test_setup
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment