When running complex Ansible playbooks, skipped tasks can flood your output with unnecessary noise. This makes it difficult to spot actual changes or failures in your automation workflows. The default behavior displays both the task name and "skipping" status for every conditional that evaluates to false.
Ansible provides several ways to manage this output:
# Method 1: Global configuration in ansible.cfg
[defaults]
display_skipped_hosts = False
# Method 2: Environment variable
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
# Method 3: Command-line flag
ansible-playbook playbook.yml --display-skipped=False
While suppressing skipped tasks cleans up output, be aware that:
- The task name will still appear in the output
- This affects all playbooks run with these settings
- Might make debugging conditional logic harder
For more granular control, consider using tags:
- name: Conditional task example
debug:
msg: "This only runs when needed"
tags:
- important
when: some_condition
Then run with:
ansible-playbook playbook.yml --tags important
Here's how to modify your original playbook for cleaner output:
- name: Stopping Puppet Agent
service:
name: pe-puppet
state: stopped
ignore_errors: true
register: result
tags: always_run
- name: Rollback operations
include_tasks: rollback/restart-pe-puppet.yml
when: result|failed
tags: rollback
Now execute with:
ansible-playbook playbook.yml --tags always_run --skip-tags rollback
When working with conditional includes or complex playbooks, Ansible's default behavior of displaying all skipped tasks can create significant noise in your execution logs. While the display_skipped_hosts
setting helps somewhat, it still leaves task headers visible.
Here are three effective approaches to clean up your output:
# Option 1: Global ansible.cfg configuration
[defaults]
display_skipped_hosts = no
# Option 2: Environment variable
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false
# Option 3: Per-playbook callback plugin (requires Ansible 2.0+)
- name: Custom output example
hosts: all
gather_facts: no
callback_whitelist: minimal
For finer control, create a custom callback plugin:
from ansible.plugins.callback import CallbackBase
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'stdout'
CALLBACK_NAME = 'quiet_skips'
def v2_runner_on_skipped(self, result):
pass # Completely suppresses skipped task output
Consider this optimized version of your original playbook:
- name: Manage Puppet Service
hosts: all
vars:
suppress_skips: true
tasks:
- name: Stop Puppet Agent
ansible.builtin.service:
name: pe-puppet
state: stopped
ignore_errors: true
register: puppet_stop_result
no_log: "{{ suppress_skips }}"
- name: Include rollback tasks
ansible.builtin.include_tasks: rollback/restart-pe-puppet.yml
when: puppet_stop_result is failed
This combination of no_log
and proper task organization significantly reduces output clutter while maintaining all critical information.
While suppressing output improves readability, remember that:
- Task headers still consume some processing overhead
- Debugging becomes slightly harder without full context
- Consider maintaining verbose logs in CI/CD pipelines while suppressing them in production runs