Let’s say you don’t want to trawl through all the skipped tasks in your Ansible output. The skippy stdout callback comes to mind. However, if you’re already using another stdout callback you’re out of lack as the callbacks can’t be chained or stacked.

awk can help you out here. mawk and gawk both did the job when used on various Debian and Ubuntu Ansible hosts. Although with mawk I had to wait until the playbook played out in it’s entirety :

ANSIBLE_FORCE_COLOR=1 ansible-playbook my_playbook.yaml \
  | tee my.log \
  | awk 'BEGIN { RS="\n\n"; ORS="\n\n"; } !/skipping|skip_reason/ { print $0; fflush(); }'

We’re basically telling awk to divide the input into sections seperated by double newlines, have awk then filter out sections which contain either the text skipping or skip_reason.

You’ll end up with a colorized unfiltered my.log file and stdout without the skipped tasks.

In case you’re wondering about the fflush(): -W interactive doesn’t work as it forces RS to a single line, and stdbuf -o0 doesn’t seem to work with (m)awk.

If you want to strip the coloring from the logfile: sed 's/\x1B\[[0-9;]*m//g' my.log

I think the awk version is (way) easier to grok then a sed version, but I’ll let you decide :

ansible-playbook my_playbook.yaml -v \
 | tee my.log \
 | stdbuf -o0 sed -nr '/^TASK/{h;n;/^skipping:/{n;b};H;x};p' | sed 'N;/^\n$/D;P;D;'

And to add some color, we need to change the sed version into:

ANSIBLE_FORCE_COLOR=1 ansible-playbook my_playbook.yaml -v \
 | sed -nr "/^TASK/{h;n;/^\x1B\[0;36mskipping:/{n;b};H;x};p"