Don't fail for mixed typed keys (#73726)
* Don't fail for mixed typed keys but warn that content cound not be sorted because of this * added tests
This commit is contained in:
parent
6514027957
commit
527bff6b79
4 changed files with 16 additions and 1 deletions
2
changelogs/fragments/inv_json_sort_types_fix.yml
Normal file
2
changelogs/fragments/inv_json_sort_types_fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Deal with failures when sorting JSON and you have incompatible key types.
|
|
@ -183,7 +183,11 @@ class InventoryCLI(CLI):
|
|||
else:
|
||||
import json
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
try:
|
||||
results = json.dumps(stuff, cls=AnsibleJSONEncoder, sort_keys=True, indent=4, preprocess_unsafe=True)
|
||||
except TypeError as e:
|
||||
results = json.dumps(stuff, cls=AnsibleJSONEncoder, sort_keys=False, indent=4, preprocess_unsafe=True)
|
||||
display.warning("Could not sort JSON output due to issues while sorting keys: %s" % to_native(e))
|
||||
|
||||
return results
|
||||
|
||||
|
|
6
test/integration/targets/inventory/inv_with_int.yml
Normal file
6
test/integration/targets/inventory/inv_with_int.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
all:
|
||||
hosts:
|
||||
testing123:
|
||||
x:
|
||||
a: 1
|
||||
0: 2
|
|
@ -85,3 +85,6 @@ if ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=True ansible -m ping localhost -i "$
|
|||
echo "Empty directory should cause failure when ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=True"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ensure we don't traceback on inventory due to variables with int as key
|
||||
ansible-inventory -i inv_with_int.yml --list "$@"
|
||||
|
|
Loading…
Reference in a new issue