From 91a681870ecf35c54665fe200709ce5498ffcf22 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Fri, 7 Jul 2023 07:15:17 +1200 Subject: [PATCH] opkg: add executable parameter (#6862) * opkg: add executable parameter * add changelog frag * Update plugins/modules/opkg.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/6862-opkg-exec.yml | 2 ++ plugins/modules/opkg.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/6862-opkg-exec.yml diff --git a/changelogs/fragments/6862-opkg-exec.yml b/changelogs/fragments/6862-opkg-exec.yml new file mode 100644 index 0000000000..a6bd8802c5 --- /dev/null +++ b/changelogs/fragments/6862-opkg-exec.yml @@ -0,0 +1,2 @@ +minor_changes: + - opkg - add ``executable`` parameter allowing to specify the path of the ``opkg`` command (https://github.com/ansible-collections/community.general/pull/6862). diff --git a/plugins/modules/opkg.py b/plugins/modules/opkg.py index 86dd5c9d80..757c88c5de 100644 --- a/plugins/modules/opkg.py +++ b/plugins/modules/opkg.py @@ -66,6 +66,11 @@ options: - Update the package DB first. default: false type: bool + executable: + description: + - The executable location for C(opkg). + type: path + version_added: 7.2.0 requirements: - opkg - python @@ -106,6 +111,7 @@ EXAMPLES = ''' force: overwrite ''' +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 @@ -118,6 +124,7 @@ class Opkg(StateModuleHelper): force=dict(choices=["", "depends", "maintainer", "reinstall", "overwrite", "downgrade", "space", "postinstall", "remove", "checksum", "removal-of-dependent-packages"]), update_cache=dict(default=False, type='bool'), + executable=dict(type="path"), ), ) @@ -138,15 +145,18 @@ class Opkg(StateModuleHelper): value = None return cmd_runner_fmt.as_optval("--force-")(value, ctx_ignore_none=True) + dir, cmd = os.path.split(self.vars.executable) if self.vars.executable else (None, "opkg") + self.runner = CmdRunner( self.module, - command="opkg", + command=cmd, arg_formats=dict( package=cmd_runner_fmt.as_list(), state=cmd_runner_fmt.as_map(state_map), force=cmd_runner_fmt.as_func(_force), - update_cache=cmd_runner_fmt.as_bool("update") + update_cache=cmd_runner_fmt.as_bool("update"), ), + path_prefix=dir, ) if self.vars.update_cache: