do not display skipping tasks in ansible

Recently one of our developers complained the skipping tasks displayed in the ansible output. She insisted that the skipping tasks names and the skipping keyword should not be displayed, because these stuffs may confuse customers. I agree with her. Without the skipping task, the ansible output will be clean and tight.

Take the below ansible playbook demo.yml for example:

---
- name: demo play
  hosts: localhost
  remote_user: root
  gather_facts: False
  any_errors_fatal: True
  tasks:
    - name: task aa
      shell: echo task aa
      when: flag == 'aa'
    - name: task bb
      shell: echo task bb
      when: flag == 'bb'

if we run the playbook using the below command, the skipping task bb is still displayed in the output:

ansible-playbook -i /etc/ansible/hosts -e 'flag=aa' demo.yml

PLAY [demo play] **********************************************************************

TASK [task aa] ************************************************************************
changed: [localhost]

TASK [task bb] ************************************************************************
skipping: [localhost]

PLAY RECAP ****************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

I searched the solution using google, however, most of the answers don’t hit the key point. Some answers suggest using stdout_callback = skippy in ansible configuration, while some suggest using display_skipped_host = false. Some answer even suggest writing a customized plugin. However, the first two methods can only suppress the skipping keyword in the output, but couldn’t suppress the skipping task name as below:

ansible-playbook -i /etc/ansible/hosts -e 'flag=aa' demo.yml

PLAY [demo play] **********************************************************************

TASK [task aa] ************************************************************************
changed: [localhost]

TASK [task bb] ************************************************************************

PLAY RECAP ****************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

Writing a customized plugin requires a lot of effect! It seems that there is not a perfect solution…

In fact, there is one!! There is a callback plugin named full_skip, which can fully suppress the display of the skipping tasks in the ansible output. Take the below ansible.cfg for example:

[defaults]
stdout_callback = full_skip

Run the same playbook again. Let’s see the output:

ansible-playbook -i /etc/ansible/hosts -e 'flag=aa' demo.yml

PLAY [demo play] **********************************************************************

TASK [task aa] ************************************************************************
changed: [localhost]

PLAY RECAP ****************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

Wow. Using the full_skip callback plugin, we now can fully eliminate the output of the skipping tasks.