|
| 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) |
0 commit comments