Skip to content

Commit

Permalink
opkg: add executable parameter (#6862)
Browse files Browse the repository at this point in the history
* opkg: add executable parameter

* add changelog frag

* Update plugins/modules/opkg.py

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
russoz and felixfontein authored Jul 6, 2023
1 parent 9d8bec1 commit 91a6818
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6862-opkg-exec.yml
Original file line number Diff line number Diff line change
@@ -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).
14 changes: 12 additions & 2 deletions plugins/modules/opkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
- 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
Expand Down Expand Up @@ -106,6 +111,7 @@
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

Expand All @@ -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"),
),
)

Expand All @@ -138,15 +145,18 @@ def _force(value):
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:
Expand Down

0 comments on commit 91a6818

Please sign in to comment.