Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ inventory_ignore_extensions = ~, .orig, .bak, .ini, .retry, .pyc, .pyo, .html, .
# Helps determine what's running slowly
callback_whitelist = profile_tasks

# Additional plugins
callback_plugins = ./plugins/callback

# Performance options
[ssh_connection]
pipelining = True
39 changes: 39 additions & 0 deletions ansible/plugins/callback/error_if_no_hosts_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://gist.github.com/jjshoe/ace3070906e5bc5cc432
# https://github.com/ansible/ansible/pull/14742
# https://github.com/ansible/ansible/issues/14693

# Make coding more python3-ish

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import time
import sys

from ansible.plugins.callback import CallbackBase


class CallbackModule(CallbackBase):
"""
This callback module exits with non-zero if no hosts match
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'no_hosts_match_exit_non_zero'
CALLBACK_NEEDS_WHITELIST = False

def __init__(self):
super(CallbackModule, self).__init__()

def playbook_on_stats(self, stats):
found_stats = False

for key in ['ok', 'failures', 'dark', 'changed', 'skipped']:
if len(getattr(stats, key)) > 0:
found_stats = True
break

if found_stats == False:
print('ERROR: No hosts matched')
sys.exit(10)