From 5f36fc9a469cd13c0c21222982b0f76459015db6 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Thu, 4 Apr 2024 21:27:50 +0200 Subject: [PATCH] to_nice_json: document the indent option (#82973) Specifying indent as an option to `to_nice_json` has been possible in contrary to what documentation states. Follow-up to https://github.com/ansible/ansible/pull/82912 --- lib/ansible/plugins/filter/core.py | 2 ++ lib/ansible/plugins/filter/to_nice_json.yml | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 1c62dd569d7..79f78d728f3 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -75,6 +75,8 @@ def to_json(a, *args, **kw): def to_nice_json(a, indent=4, sort_keys=True, *args, **kw): '''Make verbose, human-readable JSON''' + # TODO separators can be potentially exposed to the user as well + kw.pop('separators', None) return to_json(a, indent=indent, sort_keys=sort_keys, separators=(',', ': '), *args, **kw) diff --git a/lib/ansible/plugins/filter/to_nice_json.yml b/lib/ansible/plugins/filter/to_nice_json.yml index fa31b269de6..abaeee0c071 100644 --- a/lib/ansible/plugins/filter/to_nice_json.yml +++ b/lib/ansible/plugins/filter/to_nice_json.yml @@ -40,12 +40,16 @@ DOCUMENTATION: default: False type: bool sort_keys: - description: Affects sorting of dictionary keys. + description: Affects sorting of dictionary keys. Passed to an underlying C(json.dumps) call. default: True - type: bool + type: bool + indent: + description: Specifies an indentation level. Passed to an underlying C(json.dumps) call. + default: 4 + type: int notes: - Both O(vault_to_text) and O(preprocess_unsafe) defaulted to V(False) between Ansible 2.9 and 2.12. - - 'These parameters to C(json.dumps) will be ignored, they are overridden for internal use: I(cls), I(default), I(indent), I(separators), I(sort_keys).' + - 'These parameters to C(json.dumps) will be ignored, they are overridden for internal use: I(cls), I(default), I(separators).' EXAMPLES: | # dump variable in a template to create a nicely formatted JSON document