add initial callback plugin poc draft; add simple debug.yml play to test easier

This commit is contained in:
Chris Hammer 2023-06-23 17:08:03 -04:00
parent 77dee41ab4
commit 136ebfd001
4 changed files with 175 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
collections
facts.d
.vscode
callback_plugins/__pycache__

View File

@ -0,0 +1,139 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.callback import CallbackBase
from ansible import constants as C
from ansible.utils.color import colorize, hostcolor
from ansible.utils.display import Display
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'hello_bob'
def __init__(self, *args, **kwargs):
super(CallbackModule, self).__init__()
def v2_playbook_on_start(self, playbook):
self._display.display("Custom commands for <v2_playbook_on_start> go here", color=C.COLOR_OK)
def v2_playbook_on_task_start(self, task, is_conditional):
self._display.display("Custom commands for <v2_playbook_on_task_start> go here", color=C.COLOR_OK)
def v2_playbook_on_stats(self, stats):
self._display.display("Custom commands for <v2_playbook_on_stats> go here", color=C.COLOR_OK)
###################################################################################################################
def v2_on_any(self, *args, **kwargs):
self._display.display("Custom commands for <v2_on_any> go here", color=C.COLOR_OK)
def v2_runner_on_failed(self, result, ignore_errors=False):
self._display.display("Custom commands for <v2_runner_on_failed> go here", color=C.COLOR_OK)
def v2_runner_on_ok(self, result):
self._display.display("Custom commands for <v2_runner_on_ok> go here", color=C.COLOR_OK)
def v2_runner_on_skipped(self, result):
self._display.display("Custom commands for <v2_runner_on_skipped> go here", color=C.COLOR_OK)
def v2_runner_on_unreachable(self, result):
self._display.display("Custom commands for <v2_runner_on_unreachable> go here", color=C.COLOR_OK)
def v2_runner_on_async_poll(self, result):
self._display.display("Custom commands for <v2_runner_on_async_poll> go here", color=C.COLOR_OK)
def v2_runner_on_async_ok(self, result):
self._display.display("Custom commands for <v2_runner_on_async_ok> go here", color=C.COLOR_OK)
def v2_runner_on_async_failed(self, result):
self._display.display("Custom commands for <v2_runner_on_async_failed> go here", color=C.COLOR_OK)
def v2_playbook_on_start(self, playbook):
self._display.display("Custom commands for <v2_playbook_on_start> go here", color=C.COLOR_OK)
def v2_playbook_on_notify(self, handler, host):
self._display.display("Custom commands for <v2_playbook_on_notify> go here", color=C.COLOR_OK)
def v2_playbook_on_no_hosts_matched(self):
self._display.display("Custom commands for <v2_playbook_on_no_hosts_matched> go here", color=C.COLOR_OK)
def v2_playbook_on_no_hosts_remaining(self):
self._display.display("Custom commands for <v2_playbook_on_no_hosts_remaining> go here", color=C.COLOR_OK)
def v2_playbook_on_task_start(self, task, is_conditional):
self._display.display("Custom commands for <v2_playbook_on_task_start> go here", color=C.COLOR_OK)
def v2_playbook_on_cleanup_task_start(self, task):
self._display.display("Custom commands for <v2_playbook_on_cleanup_task_start> go here", color=C.COLOR_OK)
def v2_playbook_on_handler_task_start(self, task):
self._display.display("Custom commands for <v2_playbook_on_handler_task_start> go here", color=C.COLOR_OK)
def v2_playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None, unsafe=None):
self._display.display("Custom commands for <v2_playbook_on_vars_prompt> go here", color=C.COLOR_OK)
def v2_playbook_on_import_for_host(self, result, imported_file):
self._display.display("Custom commands for <v2_playbook_on_import_for_host> go here", color=C.COLOR_OK)
def v2_playbook_on_not_import_for_host(self, result, missing_file):
self._display.display("Custom commands for <v2_playbook_on_not_import_for_host> go here", color=C.COLOR_OK)
def v2_playbook_on_play_start(self, play):
self._display.display("Custom commands for <v2_playbook_on_play_start> go here", color=C.COLOR_OK)
def v2_playbook_on_stats(self, stats):
self._display.display("Custom commands for <v2_playbook_on_stats> go here", color=C.COLOR_OK)
def v2_on_file_diff(self, result):
self._display.display("Custom commands for <v2_on_file_diff> go here", color=C.COLOR_OK)
def v2_playbook_on_include(self, included_file):
self._display.display("Custom commands for <v2_playbook_on_include> go here", color=C.COLOR_OK)
def v2_runner_item_on_ok(self, result):
self._display.display("Custom commands for <v2_runner_item_on_ok> go here", color=C.COLOR_OK)
def v2_runner_item_on_failed(self, result):
self._display.display("Custom commands for <v2_runner_item_on_failed> go here", color=C.COLOR_OK)
def v2_runner_item_on_skipped(self, result):
self._display.display("Custom commands for <v2_runner_item_on_skipped> go here", color=C.COLOR_OK)
def v2_runner_retry(self, result):
self._display.display("Custom commands for <v2_runner_retry> go here", color=C.COLOR_OK)
def v2_runner_on_start(self, host, task):
self._display.display("Custom commands for <v2_runner_on_start> go here", color=C.COLOR_OK)

11
debug.yml Normal file
View File

@ -0,0 +1,11 @@
- name: "Simple Test"
hosts: localhost
connection: local
gather_facts: false
become: false
tasks:
- name: Say hello, Bob
ansible.builtin.debug:
msg: Hi.

24
test.py Normal file
View File

@ -0,0 +1,24 @@
import requests,urllib.error, json, re
#################
# Webhook Vars: #
#################
#webhook_endpoint = "https://webhooks.thezengarden.net/web/webhook-callback-poc"
#webhook_token = "5S2OtSb9KXWDyV8xYl4_Rvucz2KZHyFDRkFbRzLj78yP"
webhook_endpoint = "https://webhooks.thezengarden.net/web/webhook-callback-poc?token=5S2OtSb9KXWDyV8xYl4_Rvucz2KZHyFDRkFbRzLj78yP"
print("sending webhook payload...")
# webhook_auth_header = {'Token': webhook_token }
webhook_payload = {'webhook-callback-poc': "This is a sample message sent to a webhook."}
resp = requests.post(webhook_endpoint,
headers=webhook_auth_header,
json = webhook_payload)
print("payload sent!")
print(resp)
print(webhook_endpoint)
print(webhook_auth_header)
print(webhook_payload)