diff --git a/changelogs/fragments/9067-gio-mime-version.yml b/changelogs/fragments/9067-gio-mime-version.yml new file mode 100644 index 0000000000..9e2fb76082 --- /dev/null +++ b/changelogs/fragments/9067-gio-mime-version.yml @@ -0,0 +1,3 @@ +minor_changes: + - gio_mime module utils - add argument formatter ``version`` (https://github.com/ansible-collections/community.general/pull/9067). + - gio_mime - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9067). diff --git a/plugins/module_utils/gio_mime.py b/plugins/module_utils/gio_mime.py index e01709487d..132981a339 100644 --- a/plugins/module_utils/gio_mime.py +++ b/plugins/module_utils/gio_mime.py @@ -16,6 +16,7 @@ def gio_mime_runner(module, **kwargs): arg_formats=dict( mime_type=cmd_runner_fmt.as_list(), handler=cmd_runner_fmt.as_list(), + version=cmd_runner_fmt.as_fixed('--version'), ), **kwargs ) diff --git a/plugins/modules/gio_mime.py b/plugins/modules/gio_mime.py index 20ccb22329..587aaec427 100644 --- a/plugins/modules/gio_mime.py +++ b/plugins/modules/gio_mime.py @@ -75,6 +75,12 @@ stderr: returned: failure type: str sample: 'gio: Failed to load info for handler "never-existed.desktop"' +version: + description: Version of gio. + type: str + returned: always + sample: "2.80.0" + version_added: 10.0.0 """ from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper @@ -94,6 +100,9 @@ class GioMime(ModuleHelper): def __init_module__(self): self.runner = gio_mime_runner(self.module, check_rc=True) + with self.runner("version") as ctx: + rc, out, err = ctx.run() + self.vars.version = out.strip() self.vars.set_meta("handler", initial_value=gio_mime_get(self.runner, self.vars.mime_type), diff=True, change=True) def __run__(self): diff --git a/tests/unit/plugins/modules/test_gio_mime.yaml b/tests/unit/plugins/modules/test_gio_mime.yaml index 75e5554c7c..f71e595701 100644 --- a/tests/unit/plugins/modules/test_gio_mime.yaml +++ b/tests/unit/plugins/modules/test_gio_mime.yaml @@ -13,9 +13,14 @@ changed: true mocks: run_command: - - command: [/testbin/gio, mime, x-scheme-handler/http] + - command: [/testbin/gio, mime, --version] environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} rc: 0 + out: "2.80.0\n" + err: "" + - command: [/testbin/gio, mime, x-scheme-handler/http] + environ: *env-def + rc: 0 out: "" err: > No default applications for “x-scheme-handler/http” @@ -35,6 +40,11 @@ skip: test helper does not support check mode yet mocks: run_command: + - command: [/testbin/gio, mime, --version] + environ: *env-def + rc: 0 + out: "2.80.0\n" + err: "" - command: [/testbin/gio, mime, x-scheme-handler/http] environ: *env-def rc: 0 @@ -55,6 +65,11 @@ changed: false mocks: run_command: + - command: [/testbin/gio, mime, --version] + environ: *env-def + rc: 0 + out: "2.80.0\n" + err: "" - command: [/testbin/gio, mime, x-scheme-handler/http] environ: *env-def rc: 0