Skip to content

Commit bd9006a

Browse files
author
Arvind Jangir
committed
Add custom tag to skip the default callback
1 parent 3730961 commit bd9006a

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/ansible.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ roles_path = ./roles
44
filter_plugins = ./filter_plugins
55
callback_plugins = ./callback_plugins
66
callback_result_format = yaml
7-
stdout_callback = foremanctl
7+
stdout_callback = foremanctl

src/callback_plugins/foremanctl.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from ansible.plugins.callback.default import CallbackModule as DefaultCallbackModule
2-
from os.path import basename
32

43
DOCUMENTATION = """
54
name: foremanctl
@@ -22,12 +21,11 @@ class CallbackModule(DefaultCallbackModule):
2221
CALLBACK_NAME = 'foremanctl'
2322

2423
FALLBACK_TO_DEFAULT = True
25-
PLAYBOOKS_TO_SKIP_DEFAULT = ['features.yaml']
2624

2725
def v2_playbook_on_start(self, playbook):
28-
playbook_filename = basename(playbook._file_name)
29-
30-
if playbook_filename in self.PLAYBOOKS_TO_SKIP_DEFAULT:
26+
plays = playbook.get_plays()
27+
tags = plays[0].tags
28+
if 'foremanctl_suppress_default_output' in tags:
3129
self.FALLBACK_TO_DEFAULT = False
3230
if self.FALLBACK_TO_DEFAULT:
3331
super().v2_playbook_on_start(playbook)
@@ -49,4 +47,4 @@ def v2_runner_on_ok(self, result):
4947

5048
def v2_playbook_on_stats(self, stats):
5149
if self.FALLBACK_TO_DEFAULT:
52-
super().v2_playbook_on_stats(stats)
50+
super().v2_playbook_on_stats(stats)

src/filter_plugins/foremanctl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def known_foreman_plugins(_value):
3030
plugins = [FEATURE_MAP.get(feature).get('foreman', {}).get('plugin_name') for feature in FEATURE_MAP.keys()]
3131
return compact_list(plugins)
3232

33-
def feature_list(value):
33+
def list_all_features(enabled_features):
3434
enabled_list = []
3535
available_list = []
3636
for name, meta in FEATURE_MAP.items():
3737
if meta.get('internal', False):
3838
continue
3939
description = meta.get('description', '')
40-
if name in value:
40+
if name in enabled_features:
4141
enabled_list.append((name, 'enabled', description))
4242
else:
4343
available_list.append((name, 'available', description))
@@ -57,5 +57,5 @@ def filters(self):
5757
return {
5858
'features_to_foreman_plugins': foreman_plugins,
5959
'known_foreman_plugins': known_foreman_plugins,
60-
'feature_list': feature_list,
60+
'list_all_features': list_all_features,
6161
}

src/playbooks/features/features.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
- name: List features
33
hosts: quadlet
44
gather_facts: false
5+
tags:
6+
- foremanctl_suppress_default_output
57
vars_files:
68
- "../../vars/defaults.yml"
79
- "../../vars/flavors/{{ flavor }}.yml"
810
- "../../vars/base.yaml"
911
tasks:
1012
- name: Print features
1113
ansible.builtin.debug:
12-
msg: "{{ enabled_features | feature_list }}"
14+
msg: "{{ enabled_features | list_all_features }}"

tests/features_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import os
1+
import subprocess
22

3-
def test_foremanctl_features(capfd):
4-
result = os.system('./foremanctl features')
3+
def test_foremanctl_features():
4+
command = ['./foremanctl', 'features']
5+
result = subprocess.run(command, capture_output=True, text=True)
56

6-
captured = capfd.readouterr()
7-
assert result == 0
7+
assert result.returncode == 0
88

99
for noise in ['PLAY [', 'TASK [', 'ok:', 'changed:', 'PLAY RECAP']:
10-
assert noise not in captured.out, f"Ansible output not suppressed: found '{noise}'"
10+
assert noise not in result.stdout, f"Ansible output not suppressed: found '{noise}'"
1111

1212
for feature in ['foreman', 'foreman-proxy', 'azure_rm']:
13-
assert feature in captured.out, f"Expected feature '{feature}' in output"
13+
assert feature in result.stdout, f"Expected feature '{feature}' in output"

0 commit comments

Comments
 (0)