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

Add yaml output plugin #32246

Merged
merged 5 commits into from Nov 8, 2017
Merged

Add yaml output plugin #32246

merged 5 commits into from Nov 8, 2017

Conversation

leedm777
Copy link
Contributor

SUMMARY

Using YAML instead of JSON for detailed output can (IMO) improve
readability; especially for tasks with either lots of output, or
multi-line output.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

yaml callback plugin

ANSIBLE VERSION
ansible 2.5.0 (yaml-output b385c7d57a) last updated 2017/10/27 07:25:14 (GMT -500)
  config file = /Users/dlee/.ansible.cfg
  configured module search path = [u'/Users/dlee/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/dlee/prj/ansible/lib/ansible
  executable location = /Users/dlee/prj/ansible/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
ADDITIONAL INFORMATION

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 feature_pull_request needs_triage Needs a first human triage before being processed. plugins/callback support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 27, 2017
@ansibot
Copy link
Contributor

ansibot commented Oct 27, 2017

The test ansible-test sanity --test ansible-var-precedence-check [?] failed with the following error:

Command "test/sanity/code-smell/ansible-var-precedence-check.py" returned exit status 1.
>>> Standard Output
CHECKING: extra_vars (var passed via the cli)
ERROR !!!
playbook failed (rc=250), stdout: 'b'ansible-playbook 2.5.0 (detached HEAD b385c7d57a) last updated 2017/10/27 12:27:23 (GMT +000)\n  config file = /root/ansible/test/sanity/ansible.cfg\n  configured module search path = [\'/root/.ansible/plugins/modules\', \'/usr/share/ansible/plugins/modules\']\n  ansible python module location = /root/ansible/lib/ansible\n  executable location = /root/ansible/bin/ansible-playbook\n  python version = 3.6.3 (default, Oct  4 2017, 02:55:45) [GCC 5.4.0 20160609]\nUsing /root/ansible/test/sanity/ansible.cfg as config file\nsetting up inventory plugins\nParsed /tmp/tmp3debmzpt/inventory/hosts inventory source with ini plugin\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nRead vars_file \'varsfile.yml\'\nstatically imported: /tmp/tmp3debmzpt/included_tasks.yml\nLoading callback plugin default of type stdout, v2.0 from /root/ansible/lib/ansible/plugins/callback/__init__.py\nthe full traceback was:\n\nTraceback (most recent call last):\n  File "/root/ansible/bin/ansible-playbook", line 109, in <module>\n    exit_code = cli.run()\n  File "/root/ansible/lib/ansible/cli/playbook.py", line 130, in run\n    results = pbex.run()\n  File "/root/ansible/lib/ansible/executor/playbook_executor.py", line 90, in run\n    self._tqm.load_callbacks()\n  File "/root/ansible/lib/ansible/executor/task_queue_manager.py", line 190, in load_callbacks\n    for callback_plugin in callback_loader.all(class_only=True):\n  File "/root/ansible/lib/ansible/plugins/loader.py", line 455, in all\n    self._update_object(obj, name, path)\n  File "/root/ansible/lib/ansible/plugins/loader.py", line 346, in _update_object\n    self._load_config_defs(name, path)\n  File "/root/ansible/lib/ansible/plugins/loader.py", line 214, in _load_config_defs\n    dstring = read_docstring(path, verbose=False, ignore_errors=False)\n  File "/root/ansible/lib/ansible/parsing/plugin_docs.py", line 68, in read_docstring\n    data[\'metadata\'] = extract_metadata(module_ast=M)[0]\n  File "/root/ansible/lib/ansible/parsing/metadata.py", line 194, in extract_metadata\n    if target.id == \'ANSIBLE_METADATA\':\nAttributeError: \'Attribute\' object has no attribute \'id\'\n'' stderr: 'b" [WARNING]: Failed to assign id for <_ast.Attribute object at 0x7f8e3a0dcc88>\non /root/ansible/lib/ansible/plugins/callback/yaml.py, skipping\nERROR! Unexpected Exception, this is probably a bug: 'Attribute' object has no attribute 'id'\n"'
feature: extra_vars failed

The test ansible-test sanity --test pep8 [?] failed with the following error:

lib/ansible/plugins/callback/yaml.py:11:73: W291 trailing whitespace

click here for bot help

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Oct 27, 2017
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Oct 27, 2017
@gundalow gundalow added the ci_verified Changes made in this PR are causing tests to fail. label Oct 27, 2017
@@ -0,0 +1,118 @@
# Make coding more python3-ish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license/copyright headers

# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

CHANGELOG.md Outdated
@@ -28,6 +28,7 @@ Ansible Changes By Release
* Updated the bundled copy of the six library to 1.11.0
* Added support to `become` `NT AUTHORITY\System`, `NT AUTHORITY\LocalService`, and `NT AUTHORITY\NetworkService` on Windows hosts
* Added `aws_ssm` lookup plugin
* Added `yaml` output plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugins get their own section, should not be under 'minor'


if abridged_result:
dumped += '\n'
dumped += yaml.safe_dump(json.loads(json.dumps(abridged_result, ensure_ascii=False)), width=1000, default_flow_style=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an ansible specific dumper we create, not sure if pertinent to this plugin, but worth looking into as i think it can save you work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this now

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Nov 5, 2017
Using YAML instead of JSON for detailed output can (IMO) improve
readability; especially for tasks with either lots of output, or
multi-line output.
 * Added copyright header to yaml.py
 * Moved mention of yaml output plugin to `New Modules` section
Also moved the `represent_scalar` setup into the init method. As a
global statement, it was causing exceptions trying to get an `id`
field that does not exist.
@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Nov 6, 2017

if abridged_result:
dumped += '\n'
dumped += yaml.dump(json.loads(json.dumps(abridged_result, ensure_ascii=False)), width=1000, Dumper=AnsibleDumper, default_flow_style=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the json load + dump? this is effectively a noop, you can just use yaml.dump directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@bcoca bcoca merged commit 1fd454e into ansible:devel Nov 8, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. plugins/callback support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants