diff --git a/changelogs/fragments/9086-gio-mime-version.yml b/changelogs/fragments/9086-gio-mime-version.yml new file mode 100644 index 0000000000..46c3e6cec8 --- /dev/null +++ b/changelogs/fragments/9086-gio-mime-version.yml @@ -0,0 +1,2 @@ +minor_changes: + - opkg - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9086). diff --git a/plugins/modules/opkg.py b/plugins/modules/opkg.py index 2f9794ab86..da51755efb 100644 --- a/plugins/modules/opkg.py +++ b/plugins/modules/opkg.py @@ -75,6 +75,7 @@ requirements: - opkg - python ''' + EXAMPLES = ''' - name: Install foo community.general.opkg: @@ -111,6 +112,15 @@ EXAMPLES = ''' force: overwrite ''' +RETURN = """ +version: + description: Version of opkg. + type: str + returned: always + sample: "2.80.0" + version_added: 10.0.0 +""" + import os from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper @@ -156,10 +166,15 @@ class Opkg(StateModuleHelper): state=cmd_runner_fmt.as_map(state_map), force=cmd_runner_fmt.as_func(_force), update_cache=cmd_runner_fmt.as_bool("update"), + version=cmd_runner_fmt.as_fixed("--version"), ), path_prefix=dir, ) + with self.runner("version") as ctx: + rc, out, err = ctx.run() + self.vars.version = out.strip().replace("opkg version ", "") + if self.vars.update_cache: rc, dummy, dummy = self.runner("update_cache").run() if rc != 0: @@ -186,13 +201,12 @@ class Opkg(StateModuleHelper): pkg_name, pkg_version = self.split_name_and_version(package) if not self._package_in_desired_state(pkg_name, want_installed=True, version=pkg_version) or self.vars.force == "reinstall": ctx.run(package=package) + self.vars.set("run_info", ctx.run_info, verbosity=4) if not self._package_in_desired_state(pkg_name, want_installed=True, version=pkg_version): self.do_raise("failed to install %s" % package) self.vars.install_c += 1 - if self.verbosity >= 4: - self.vars.run_info = ctx.run_info if self.vars.install_c > 0: - self.vars.msg = "installed %s package(s)" % (self.vars.install_c) + self.vars.msg = "installed %s package(s)" % self.vars.install_c else: self.vars.msg = "package(s) already present" @@ -202,13 +216,12 @@ class Opkg(StateModuleHelper): package, dummy = self.split_name_and_version(package) if not self._package_in_desired_state(package, want_installed=False): ctx.run(package=package) + self.vars.set("run_info", ctx.run_info, verbosity=4) if not self._package_in_desired_state(package, want_installed=False): self.do_raise("failed to remove %s" % package) self.vars.remove_c += 1 - if self.verbosity >= 4: - self.vars.run_info = ctx.run_info if self.vars.remove_c > 0: - self.vars.msg = "removed %s package(s)" % (self.vars.remove_c) + self.vars.msg = "removed %s package(s)" % self.vars.remove_c else: self.vars.msg = "package(s) already absent" diff --git a/tests/unit/plugins/modules/test_opkg.yaml b/tests/unit/plugins/modules/test_opkg.yaml index 0cef54ac08..090a72c20c 100644 --- a/tests/unit/plugins/modules/test_opkg.yaml +++ b/tests/unit/plugins/modules/test_opkg.yaml @@ -12,11 +12,16 @@ msg: installed 1 package(s) mocks: run_command: - - command: [/testbin/opkg, list-installed, zlib-dev] + - command: [/testbin/opkg, --version] environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} rc: 0 out: "" err: "" + - command: [/testbin/opkg, list-installed, zlib-dev] + environ: *env-def + rc: 0 + out: "" + err: "" - command: [/testbin/opkg, install, zlib-dev] environ: *env-def rc: 0 @@ -42,6 +47,11 @@ msg: package(s) already present mocks: run_command: + - command: [/testbin/opkg, --version] + environ: *env-def + rc: 0 + out: "" + err: "" - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 @@ -57,6 +67,11 @@ msg: installed 1 package(s) mocks: run_command: + - command: [/testbin/opkg, --version] + environ: *env-def + rc: 0 + out: "" + err: "" - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 @@ -85,6 +100,11 @@ msg: installed 1 package(s) mocks: run_command: + - command: [/testbin/opkg, --version] + environ: *env-def + rc: 0 + out: "" + err: "" - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 @@ -115,6 +135,11 @@ msg: installed 1 package(s) mocks: run_command: + - command: [/testbin/opkg, --version] + environ: *env-def + rc: 0 + out: "" + err: "" - command: [/testbin/opkg, update] environ: *env-def rc: 0