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
cef2a879
Commit
cef2a879
authored
Oct 02, 2014
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make dynamic inventory return byte str, not unicode
parent
32309e37
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
+22
-1
lib/ansible/inventory/script.py
+3
-1
lib/ansible/utils/__init__.py
+19
-0
No files found.
lib/ansible/inventory/script.py
View file @
cef2a879
...
@@ -26,6 +26,7 @@ from ansible import utils
...
@@ -26,6 +26,7 @@ from ansible import utils
from
ansible
import
errors
from
ansible
import
errors
import
sys
import
sys
class
InventoryScript
(
object
):
class
InventoryScript
(
object
):
''' Host inventory parser for ansible using external inventory scripts. '''
''' Host inventory parser for ansible using external inventory scripts. '''
...
@@ -53,6 +54,7 @@ class InventoryScript(object):
...
@@ -53,6 +54,7 @@ class InventoryScript(object):
# not passing from_remote because data from CMDB is trusted
# not passing from_remote because data from CMDB is trusted
self
.
raw
=
utils
.
parse_json
(
self
.
data
)
self
.
raw
=
utils
.
parse_json
(
self
.
data
)
self
.
raw
=
utils
.
json_dict_unicode_to_bytes
(
self
.
raw
)
all
=
Group
(
'all'
)
all
=
Group
(
'all'
)
groups
=
dict
(
all
=
all
)
groups
=
dict
(
all
=
all
)
...
@@ -141,7 +143,7 @@ class InventoryScript(object):
...
@@ -141,7 +143,7 @@ class InventoryScript(object):
if
out
.
strip
()
==
''
:
if
out
.
strip
()
==
''
:
return
dict
()
return
dict
()
try
:
try
:
return
utils
.
parse_json
(
out
)
return
utils
.
json_dict_unicode_to_bytes
(
utils
.
parse_json
(
out
)
)
except
ValueError
:
except
ValueError
:
raise
errors
.
AnsibleError
(
"could not parse post variable response:
%
s,
%
s"
%
(
cmd
,
out
))
raise
errors
.
AnsibleError
(
"could not parse post variable response:
%
s,
%
s"
%
(
cmd
,
out
))
lib/ansible/utils/__init__.py
View file @
cef2a879
...
@@ -1215,6 +1215,25 @@ def to_unicode(value):
...
@@ -1215,6 +1215,25 @@ def to_unicode(value):
return
value
return
value
return
value
.
decode
(
"utf-8"
)
return
value
.
decode
(
"utf-8"
)
def
json_dict_unicode_to_bytes
(
d
):
''' Recursively convert dict keys and values to byte str
Specialized for json return because this only handles, lists, tuples,
and dict container types (the containers that the json module returns)
'''
if
isinstance
(
d
,
unicode
):
return
d
.
encode
(
'utf-8'
)
elif
isinstance
(
d
,
dict
):
return
dict
(
map
(
json_dict_unicode_to_bytes
,
d
.
iteritems
()))
elif
isinstance
(
d
,
list
):
return
list
(
map
(
json_dict_unicode_to_bytes
,
d
))
elif
isinstance
(
d
,
tuple
):
return
tuple
(
map
(
json_dict_unicode_to_bytes
,
d
))
else
:
return
d
def
get_diff
(
diff
):
def
get_diff
(
diff
):
# called by --diff usage in playbook and runner via callbacks
# called by --diff usage in playbook and runner via callbacks
# include names in diffs 'before' and 'after' and do diff -U 10
# include names in diffs 'before' and 'after' and do diff -U 10
...
...
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