A logging plugin

71 views
Skip to first unread message

Dave Thomas

unread,
Jul 25, 2015, 5:33:14 PM7/25/15
to Ansible Project
I took Cliffano Subagio's "human_logging" gist and made the output a lot more compact—I think it's easier to read:


# Interpret the Ansible log for humans. In particular, we
# look for command executions and format their content
#
#     - name: list files
#       shell: "ls -lrt *e*"
#
# Might produce
#
#       TASK: [1] ***********************************************************
#       changed: [localhost]
#       2015-07-25 09:41:03: ls -lrt *e*
#           -rw-r--r--  1 dave  staff  1696 Jul 11 11:54 ansible.pem
#           -rw-r--r--  1 dave  staff   106 Jul 22 10:10 fix-sudoers.sh
#           -rw-r--r--  1 dave  staff    20 Jul 22 20:06 fred.yml
#           -rw-r--r--  1 dave  staff   345 Jul 23 14:48 ansible.cfg
#           -rw-r--r--  1 dave  staff    68 Jul 25 09:35 site.yml
#
#           filter_plugins:
#           total 16
#           -rw-r--r--  1 dave  staff  247 Jul 24 18:06 to_instance_tags.py
#           -rw-r--r--  1 dave  staff  859 Jul 24 20:55 to_instance_tags.pyc
#           (took .008240s)
#
# The start time appears as the prompt for the command, and the result
# is shown indented. The output ends with the elapsed time.

Baraa Basata

unread,
Jul 28, 2015, 2:14:25 PM7/28/15
to Ansible Project, da...@pragprog.org
Looks nice. I'll try this out for, e.g., Rails migrations output. Thanks for sharing this, Dave.

-Baraa

Chris McDonald

unread,
Jul 30, 2015, 9:34:02 AM7/30/15
to Ansible Project, da...@pragprog.org
Hi

Thanks very much for this. Its just what I'm looking for.

I wonder however, might it contain a small bug? stdout and stderr are both being output in yellow always rather than stderr being output in bright red which is preferable. I think that the following fixes this:

def display_output(output, color='yellow'):
    if output:
        output = "\n    ".join(output.split("\n"))
        print(stringc("    " + output, color))

Best regards

chris

Dave Thomas

unread,
Jul 30, 2015, 11:22:01 AM7/30/15
to Chris McDonald, Ansible Project
Chris:

You're right. Fixed.

Thanks


Dave
Reply all
Reply to author
Forward
0 new messages