Repository: ansible-collections/community.general

Issue:
Package module pass list of packages to apt_rpm that is converted to string as is and not supported
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
apt_rpm does not support install packages provided as list, only as comma delimited string. So package module does not work with apt_rpm
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
apt_rpm
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.8.8

```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below

```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->


##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Use simple playbook that install list of packages on Altlinux
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: install packages
  package:
    name:
        - nginx
        - vim
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Packages succesfully installed by invoking apt_rpm

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
TASK [install_packages : install packages] *************************************
fatal: [host-1]: FAILED! => changed=false
  msg: |-
    'apt-get -y install  'vim']' failed: E: Regex compilation error - Unmatched [ or [^
```
It is because:
```
[WARNING]: The value ['nginx', 'vim'] (type list) in a string field was converted to u"['nginx', 'librdkafka']" (type string). If this does not look like what you expect, quote the entire value to ensure it does not change.
```


Discussion:
The module expects a string, not a list as its param. It's probably better to fix the param type from `str` to `list` and make sure lists are handled correctly.
> The module expects a string, not a list as its param. It's probably better to fix the param type from `str` to `list` and make sure lists are handled correctly.

Changing type break behavior of existing playbooks with single package name provided in module
cc @evgkrsk
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
> Changing type break behavior of existing playbooks with single package name provided in module

That's true in general, but not in this case: `type: list` also accepts strings, and splits them by commas to create a list. Since the module currently does this manually, the behavior does not change for existing correct use-cases. What does change is that now the module will also work when lists are passed.

Resolving patch:
diff --git a/plugins/modules/packaging/os/apt_rpm.py b/plugins/modules/packaging/os/apt_rpm.py
--- a/plugins/modules/packaging/os/apt_rpm.py
+++ b/plugins/modules/packaging/os/apt_rpm.py
@@ -17,10 +17,13 @@
 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 @@
     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)


Test patch: