Skip to content

Commit b4c3b5e

Browse files
committed
add a callback to print verbatim output
1 parent b1902f0 commit b4c3b5e

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
host_key_checking = False
33
roles_path = ./roles
44
filter_plugins = ./filter_plugins
5+
callback_plugins = ./callback_plugins
56
callback_result_format = yaml
7+
stdout_callback = foremanctl

src/callback_plugins/foremanctl.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
DOCUMENTATION = """
2+
name: foremanctl
3+
type: stdout
4+
short_description: default Ansible screen output
5+
description:
6+
- This is the default output callback for ansible-playbook.
7+
extends_documentation_fragment:
8+
- default_callback
9+
- result_format_callback
10+
requirements:
11+
- set as stdout in configuration
12+
"""
13+
14+
from ansible.plugins.callback.default import CallbackModule as DefaultCallbackModule
15+
from os.path import basename
16+
17+
18+
class CallbackModule(DefaultCallbackModule):
19+
CALLBACK_NAME = 'foremanctl'
20+
FALLBACK_TO_DEFAULT = True
21+
22+
def v2_playbook_on_start(self, playbook):
23+
playbook_filename = basename(playbook._file_name)
24+
if playbook_filename == 'features.yaml':
25+
self.FALLBACK_TO_DEFAULT = False
26+
if self.FALLBACK_TO_DEFAULT:
27+
super().v2_playbook_on_start(playbook)
28+
29+
def v2_playbook_on_play_start(self, play):
30+
if self.FALLBACK_TO_DEFAULT:
31+
super().v2_playbook_on_play_start(play)
32+
33+
def v2_playbook_on_task_start(self, task, is_conditional):
34+
if self.FALLBACK_TO_DEFAULT:
35+
super().v2_playbook_on_task_start(task, is_conditional)
36+
37+
def v2_runner_on_ok(self, result):
38+
if self.FALLBACK_TO_DEFAULT:
39+
super().v2_runner_on_ok(result)
40+
else:
41+
if msg := result.result.get('msg'):
42+
self._display.display(msg)
43+
44+
def v2_playbook_on_stats(self, stats):
45+
if self.FALLBACK_TO_DEFAULT:
46+
super().v2_playbook_on_stats(stats)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- hosts: quadlet
3+
gather_facts: false
4+
tasks:
5+
- name: print features
6+
ansible.builtin.debug:
7+
msg: "Whoa, nice"

0 commit comments

Comments
 (0)