From d25554df9df54b9a248142cf7a9b350130a771a7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 14 Oct 2021 21:14:32 +0200 Subject: [PATCH] Improve opkg module (#3554) * Allow name to be a YAML list as well, and be more lenient when splitting strings by comma. * General docs improvements. --- changelogs/fragments/3554-opkg-name.yml | 2 ++ plugins/modules/packaging/os/opkg.py | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/3554-opkg-name.yml diff --git a/changelogs/fragments/3554-opkg-name.yml b/changelogs/fragments/3554-opkg-name.yml new file mode 100644 index 0000000000..a06255f26e --- /dev/null +++ b/changelogs/fragments/3554-opkg-name.yml @@ -0,0 +1,2 @@ +minor_changes: + - "opkg - allow ``name`` to be a YAML list of strings (https://github.com/ansible-collections/community.general/issues/572, https://github.com/ansible-collections/community.general/pull/3554)." diff --git a/plugins/modules/packaging/os/opkg.py b/plugins/modules/packaging/os/opkg.py index 07b99bf4f4..bede73fb88 100644 --- a/plugins/modules/packaging/os/opkg.py +++ b/plugins/modules/packaging/os/opkg.py @@ -20,19 +20,20 @@ description: options: name: description: - - name of package to install/remove + - Name of package(s) to install/remove. aliases: [pkg] required: true - type: str + type: list + elements: str state: description: - - state of the package + - State of the package. choices: [ 'present', 'absent', 'installed', 'removed' ] default: present type: str force: description: - - opkg --force parameter used + - The C(opkg --force) parameter used. choices: - "" - "depends" @@ -48,10 +49,10 @@ options: type: str update_cache: description: - - update the package db first + - Update the package DB first. - Alias C(update-cache) has been deprecated and will be removed in community.general 5.0.0. aliases: ['update-cache'] - default: "no" + default: false type: bool requirements: - opkg @@ -76,7 +77,9 @@ EXAMPLES = ''' - name: Remove foo and bar community.general.opkg: - name: foo,bar + name: + - foo + - bar state: absent - name: Install foo using overwrite option forcibly @@ -170,7 +173,7 @@ def install_packages(module, opkg_path, packages): def main(): module = AnsibleModule( argument_spec=dict( - name=dict(aliases=["pkg"], required=True), + name=dict(aliases=["pkg"], required=True, type="list", elements="str"), state=dict(default="present", choices=["present", "installed", "absent", "removed"]), force=dict(default="", choices=["", "depends", "maintainer", "reinstall", "overwrite", "downgrade", "space", "postinstall", "remove", "checksum", "removal-of-dependent-packages"]), @@ -187,7 +190,7 @@ def main(): if p["update_cache"]: update_package_db(module, opkg_path) - pkgs = p["name"].split(",") + pkgs = p["name"] if p["state"] in ["present", "installed"]: install_packages(module, opkg_path, pkgs)