Skip to content
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

Return data formatted as YAML #15618

Open
4 of 9 tasks
markfaine opened this issue Nov 6, 2024 · 1 comment
Open
4 of 9 tasks

Return data formatted as YAML #15618

markfaine opened this issue Nov 6, 2024 · 1 comment

Comments

@markfaine
Copy link

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that AWX is open source software provided for free and that I might not receive a timely response.

Feature type

New Feature

Feature Summary

When retrieving data like the following:

vars = client.hosts.get(name=hostname).results[0].get_related('variable_data')

The resulting data is return as a json structure:

{
    "node_availability": "active",
    "node_labels": {
        "ansible": "true"
    },
    "node_role": "worker",
    "remote_host_enabled": "true",
    "remote_host_id": 2504,
    "remote_tower_enabled": "true",
    "remote_tower_id": 2504,
}

However, when attempting to convert it to yaml using ruamel.yaml and the 'rt' or 'safe' dumper, this results in an error:

   vars = client.hosts.get(name=hostname).results[0].get_related('variable_data')
   yaml.dump(vars, sys.stdout)
raise RepresenterError(f'cannot represent an object: {data!s}')
ruamel.yaml.representer.RepresenterError: cannot represent an object: {

The 'unsafe' dumper will dump the objects but that data is not useful as yaml output.

Select the relevant components

  • UI
  • API
  • Docs
  • Collection
  • CLI
  • Other

Steps to reproduce

   vars = client.hosts.get(name=hostname).results[0].get_related('variable_data')
   yaml.dump(vars, sys.stdout)

Current results

ruamel.yaml.representer.RepresenterError: cannot represent an object: {

Sugested feature result

It would be nice if there was a way to indicate that yaml output was desired or a utility function that could convert the objects back to regular python data structures.

Additional information

No response

@markfaine
Copy link
Author

FYI, I still think it's a good idea but I was able to work around it by converting the entire output to a string and feeding the string to yaml.dump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant