From 16ce942448efcf84808d29b5538464235c9f9629 Mon Sep 17 00:00:00 2001 From: amleshkov <48879764+amleshkov@users.noreply.github.com> Date: Wed, 17 Jun 2020 19:04:27 +0300 Subject: [PATCH] apt_rpm: support installing a list of packages (Fixes #143) (#169) * Fixes #143, change package parameter from str to list * remove uneccessary splitting * add changelog fragment * fix parameter-list-no-elements validation * fix documentation * Fix changelog * Fix documetation, add example with list of packages * Update changelogs/fragments/apt_rpm_typefix.yml Co-authored-by: Alexander Leshkov Co-authored-by: Felix Fontein --- changelogs/fragments/apt_rpm_typefix.yml | 2 ++ plugins/modules/packaging/os/apt_rpm.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/apt_rpm_typefix.yml diff --git a/changelogs/fragments/apt_rpm_typefix.yml b/changelogs/fragments/apt_rpm_typefix.yml new file mode 100644 index 0000000000..72f185e667 --- /dev/null +++ b/changelogs/fragments/apt_rpm_typefix.yml @@ -0,0 +1,2 @@ +bugfixes: + - apt_rpm - fix ``package`` type from ``str`` to ``list`` to fix invoking with list of packages (https://github.com/ansible-collections/community.general/issues/143). diff --git a/plugins/modules/packaging/os/apt_rpm.py b/plugins/modules/packaging/os/apt_rpm.py index 86cd4d4599..e5156605fe 100644 --- a/plugins/modules/packaging/os/apt_rpm.py +++ b/plugins/modules/packaging/os/apt_rpm.py @@ -17,10 +17,13 @@ short_description: apt_rpm package manager description: - Manages packages with I(apt-rpm). Both low-level (I(rpm)) and high-level (I(apt-get)) package manager binaries required. options: - pkg: + package: description: - - name of package to install, upgrade or remove. + - list of packages to install, upgrade or remove. required: true + aliases: [ name, pkg ] + type: list + elements: str state: description: - Indicates the desired package state. @@ -41,6 +44,13 @@ EXAMPLES = ''' pkg: foo state: present +- name: Install packages foo and bar + apt_rpm: + pkg: + - foo + - bar + state: present + - name: Remove package foo apt_rpm: pkg: foo @@ -146,7 +156,7 @@ def main(): argument_spec=dict( state=dict(type='str', default='installed', choices=['absent', 'installed', 'present', 'removed']), update_cache=dict(type='bool', default=False, aliases=['update-cache']), - package=dict(type='str', required=True, aliases=['name', 'pkg']), + package=dict(type='list', elements='str', required=True, aliases=['name', 'pkg']), ), ) @@ -158,7 +168,7 @@ def main(): if p['update_cache']: update_package_db(module) - packages = p['package'].split(',') + packages = p['package'] if p['state'] in ['installed', 'present']: install_packages(module, packages)