|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (C) 2023, Red Hat, Inc. |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +from __future__ import absolute_import, division, print_function |
| 6 | + |
| 7 | +__metaclass__ = type |
| 8 | + |
| 9 | +DOCUMENTATION = """ |
| 10 | + author: Rich Megginson |
| 11 | + name: dump_packages |
| 12 | + type: aggregate |
| 13 | + short_description: dump arguments to package module |
| 14 | + description: |
| 15 | + - Dump arguments to package module to get list of packages. |
| 16 | + - Used in conjunction with CI testing to get the packages used |
| 17 | + - with all combinations of: distribution/version/role arguments |
| 18 | + - Used to generate lists of packages for ostree image builds. |
| 19 | + requirements: |
| 20 | + - None |
| 21 | +""" |
| 22 | + |
| 23 | +from ansible.plugins.callback import CallbackBase # noqa: E402 |
| 24 | + |
| 25 | + |
| 26 | +class CallbackModule(CallbackBase): |
| 27 | + """ |
| 28 | + Dump packages. |
| 29 | + """ |
| 30 | + |
| 31 | + CALLBACK_VERSION = 2.0 |
| 32 | + CALLBACK_TYPE = "aggregate" |
| 33 | + CALLBACK_NAME = "dump_packages" |
| 34 | + # needed for 2.9 compatibility |
| 35 | + CALLBACK_NEEDS_WHITELIST = False # wokeignore:rule=whitelist |
| 36 | + CALLBACK_NEEDS_ENABLED = False |
| 37 | + |
| 38 | + def __init__(self, *args, **kwargs): |
| 39 | + super(CallbackModule, self).__init__(*args, **kwargs) |
| 40 | + |
| 41 | + def v2_runner_on_ok(self, result): |
| 42 | + fields = result._task_fields |
| 43 | + if fields["action"] == "package" and fields["args"].get("state") != "absent": |
| 44 | + if isinstance(fields["args"]["name"], list): |
| 45 | + packages = " ".join(fields["args"]["name"]) |
| 46 | + else: |
| 47 | + packages = fields["args"]["name"] |
| 48 | + self._display.display("lsrpackages: " + packages) |
0 commit comments