Skip to content

Instantly share code, notes, and snippets.

@krushik
Last active October 15, 2023 14:36
Show Gist options
  • Save krushik/751f7a7abc6515c0eeee41a1c5409ab2 to your computer and use it in GitHub Desktop.
Save krushik/751f7a7abc6515c0eeee41a1c5409ab2 to your computer and use it in GitHub Desktop.
ansible callback plugin that warns you of --check mode
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
callback: check_mode_indicator
type: aggregate
short_description: shows a warning if you run ansible in check mode
description:
- This callback module shows a big WARNING when you run ansible in check mode.
'''
from ansible.plugins.callback import CallbackBase
from ansible import context
class CallbackModule(CallbackBase):
"""
This callback module shows a big WARNING when you run ansible in check mode.
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'check_mode_indicator'
CALLBACK_NEEDS_WHITELIST = False
def __init__(self):
super(CallbackModule, self).__init__()
def v2_playbook_on_stats(self, stats):
#print(context.CLIARGS)
if context.CLIARGS['check']:
self._display.warning("*** THIS WAS ONLY A CHECK MODE RUN ***")
@krushik
Copy link
Author

krushik commented Sep 14, 2017

you need to include its path into your .ansible.cfg like this:

[defaults]
callback_plugins = /usr/share/ansible_plugins/callback_plugins:~/ansible/callback_plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment