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 plugin to pretty print Ansible msg output #544

Merged
merged 1 commit into from
Apr 2, 2016

Conversation

fullyint
Copy link
Contributor

@fullyint fullyint commented Apr 2, 2016

This PR proposes a new 'stdout_callback' named output.py to augment Ansible's default.py. It extracts and displays the msg attribute, interpreting newline characters and applying textwrap.

This PR adds a couple .py files, still mirroring Ansible project's structure.

lib/
  trellis/
    modules/
      deploy_helper.py
    plugins/
      callback/         <-- new
        output.py       <-- new
      filter/
        filters.py
    utils/              <-- new
      output.py         <-- new

Run the playbook below on Trellis master then again on this PR's branch to see the different formatting.

- name: Output demo 
  gather_facts: false
  hosts: localhost
  vars_files:
    - group_vars/staging/wordpress_sites.yml
  tasks:
    - debug:
        msg: If `with_dict`, `item` below displays dict key only (unless `-v`)
      register: results
      with_dict: "{{ wordpress_sites }}"

    - debug:
        msg: If `with_items` based on dict, attempts to display only key (unless `-v`)
      with_items: "{{ results.results }}"

    - assert:
        that: "{{ item.name == 'bar' }}"
        msg: |
          {{ item.msg }}

          {{ item.msg }}

          {{ item.msg*2 }}
      with_items:
        - {'name': 'foo', 'msg': 'Fail for item zero.  '}
        - {'name': 'bar', 'msg': 'Example ok/skipped item'}
        - {'name': 'foo', 'msg': 'The horizontal rule between hosts/items helps distinguish between multiple hosts/items, especially when messages have blank lines. Blank lines would no longer clearly mark the start/end of the message per host/item.  '}

This is an improved piece of #531.

@swalkinshaw
Copy link
Member

So much better 👍

New 'stdout_callback' `output.py` augments Ansible's `default.py`.
Displays `msg` attribute, interpreting newline characters
and applying textwrap.
@swalkinshaw swalkinshaw merged commit b2b57d1 into roots:master Apr 2, 2016
@fullyint fullyint deleted the wrap-output branch April 3, 2016 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants