Debian Codegraph @

ansible_collections/community/general/plugins/callback/tasks_only.py

raw
1 # Copyright (c) 2025, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import annotations
6
7 DOCUMENTATION = r"""
8 author: Felix Fontein (@felixfontein)
9 name: tasks_only
10 type: stdout
11 version_added: 11.1.0
12 short_description: Only show tasks
13 description:
14 - Removes play start and stats marker from P(ansible.builtin.default#callback)'s output.
15 - Can be used to generate output for documentation examples.
16 For this, the O(number_of_columns) option should be set to an explicit value.
17 extends_documentation_fragment:
18 - ansible.builtin.default_callback
19 - ansible.builtin.result_format_callback
20 options:
21 number_of_columns:
22 description:
23 - Sets the number of columns for Ansible's display.
24 type: int
25 env:
26 - name: ANSIBLE_COLLECTIONS_TASKS_ONLY_NUMBER_OF_COLUMNS
27 result_format:
28 # Part of the ansible.builtin.result_format_callback doc fragment
29 version_added: 11.2.0
30 pretty_results:
31 # Part of the ansible.builtin.result_format_callback doc fragment
32 version_added: 11.2.0
33 """
34
35 EXAMPLES = r"""
36 ---
37 # Enable callback in ansible.cfg:
38 ansible_config: |-
39 [defaults]
40 stdout_callback = community.general.tasks_only
41
42 ---
43 # Enable callback with environment variables:
44 environment_variable: |-
45 ANSIBLE_STDOUT_CALLBACK=community.general.tasks_only
46 """
47
48 from ansible.plugins.callback.default import CallbackModule as Default
49
50
51 class CallbackModule(Default):
52 CALLBACK_VERSION = 2.0
53 CALLBACK_TYPE = "stdout"
54 CALLBACK_NAME = "community.general.tasks_only"
55
56 def v2_playbook_on_play_start(self, play):
57 pass
58
59 def v2_playbook_on_stats(self, stats):
60 pass
61
62 def set_options(self, *args, **kwargs):
63 result = super().set_options(*args, **kwargs)
64 self.number_of_columns = self.get_option("number_of_columns")
65 if self.number_of_columns is not None:
66 self._display.columns = self.number_of_columns
67 return result