New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ansible-inventory --list
JSON output shows unsafe values as dictionaries with __ansible_unsafe
key
#82999
Comments
__ansible_unsafe
keyansible-inventory --list
JSON output shows unsafe values as dictionaries with __ansible_unsafe
key
Files identified in the description: If these files are incorrect, please update the |
This is not a bug. That is the correct JSON representation of an unsafe value. See 5941e4c |
Hmm, interesting. As a user I find the output somewhat confusing, but I now see why it's there. But according to #47295, YAML and TOML output should then also indicate unsafe values, shouldn't they? Right now they do not. (I'm not sure how this should work in TOML, but in YAML |
Hmm, yes. I suspect this hasn't been noticed because people mainly use the YAML from this tool for visual inspection (not round-tripping data through) and hardly anyone uses TOML for anything. TOML would require a convention similar to the JSON one, which I don't think is currently implemented for either dumping or loading. YAML should be straightforward; for some reason diff --git a/lib/ansible/parsing/yaml/dumper.py b/lib/ansible/parsing/yaml/dumper.py
index 11a1431b94..a9c990f1e6 100644
--- a/lib/ansible/parsing/yaml/dumper.py
+++ b/lib/ansible/parsing/yaml/dumper.py
@@ -44,6 +44,10 @@ def represent_vault_encrypted_unicode(self, data):
return self.represent_scalar(u'!vault', data._ciphertext.decode(), style='|')
+def represent_unsafe(self, data):
+ return self.represent_scalar(u'!unsafe', text_type(data))
+
+
def represent_unicode(self, data):
return yaml.representer.SafeRepresenter.represent_str(self, text_type(data))
@@ -66,7 +70,7 @@ AnsibleDumper.add_representer(
AnsibleDumper.add_representer(
AnsibleUnsafeText,
- represent_unicode,
+ represent_unsafe,
)
AnsibleDumper.add_representer(
@@ -111,7 +115,7 @@ AnsibleDumper.add_representer(
AnsibleDumper.add_representer(
NativeJinjaUnsafeText,
- represent_unicode,
+ represent_unsafe,
)
AnsibleDumper.add_representer(
|
vault is the other thing that you'll see 'strangely represented'. Sadly JSON and TOML do not have a way to create custom types like |
I'm wondering whether the change above is a good idea - |
I might need to add a toggle |
I played around a bit and created a I also added another commit to add a new What do you think of the |
That it might all be redundant with data tagging, also i would not create a new dumper but use the existing one and just have 'feature parity'. |
@bcoca just modifying the existing one is a huge breaking change. Every time someone templates some data structure to YAML that contains unsafe strings - for example strings returned by a module -, these strings will now be marked as |
why i think that if we implement this at all, it has to have switches |
But how do you make the behavior switchable without having two dumpers? Or do you want to make this a global setting (so either all parts of ansible-core dump unsafe as |
According to #83003 (comment) the current state (JSON has this information, YAML and TOML not) is intentional. Closing this. |
Summary
When running
ansible-inventory --list
(JSON output, i.e. not--yaml
or--toml
) for an inventory plugin which marks variables as unsafe, these variables' values are shown as dictionaries with a single__ansible_unsafe
key and the actual value as a value.Issue Type
Bug Report
Component Name
ansible-inventory --list
Ansible Version
devel, probably also older ones
Configuration
-
OS / Environment
Steps to Reproduce
Use an inventory plugin which marks variables such as
ansible_host
as unsafe.Expected Results
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: