Discussion:
[ansible-project] A logging plugin
Dave Thomas
2015-07-25 21:33:14 UTC
Permalink
I took Cliffano Subagio's "human_logging" gist and made the output a lot
more compact—I think it's easier to read:

https://gist.github.com/pragdave/4b984557676d2d6c92a6

# 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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d9dd5baa-1123-47ce-a03b-e45ee4ad9630%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Baraa Basata
2015-07-28 18:14:25 UTC
Permalink
Looks nice. I'll try this out for, e.g., Rails migrations output. Thanks
for sharing this, Dave.

-Baraa
Post by Dave Thomas
I took Cliffano Subagio's "human_logging" gist and made the output a lot
https://gist.github.com/pragdave/4b984557676d2d6c92a6
# 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
#
# 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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bf4bc997-5662-40ef-a72d-954490a2ee6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chris McDonald
2015-07-30 13:24:55 UTC
Permalink
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
Post by Dave Thomas
I took Cliffano Subagio's "human_logging" gist and made the output a lot
https://gist.github.com/pragdave/4b984557676d2d6c92a6
# 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
#
# 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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c3085e2c-e0a9-472a-9169-a3cd5abf0d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Dave Thomas
2015-07-30 15:21:47 UTC
Permalink
Chris:

You're right. Fixed.

Thanks


Dave
Post by Chris McDonald
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
output = "\n ".join(output.split("\n"))
print(stringc(" " + output, color))
Best regards
chris
Post by Dave Thomas
I took Cliffano Subagio's "human_logging" gist and made the output a lot
https://gist.github.com/pragdave/4b984557676d2d6c92a6
# 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
#
# 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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF3B_oTxsgnP1nHNnME9M6uzc_rPHjzAu%2Bou5DkiHUyjhHXq1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...