Repository: ansible-collections/community.general

Issue:
vmadm in 2.10.7 fails to validate what should be a valid resolvers parameter
### Summary

When the validations were added for vmadm (as a part of https://github.com/ansible-collections/community.general/commit/f33323ca8930ee566cb29de4f8218b71e0a1417a), the vmadm type check for `resolvers` expects a list of dictionaries. Previous versions expected a list of strings, and the json specification is for a list of strings.


### Issue Type

Bug Report

### Component Name

vmadm

### Ansible Version

```console
$ ansible --version
ansible 2.10.7
  config file = /root/ansible-web/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/local/lib/python3.8/site-packages/ansible
  executable location = /opt/local/bin/ansible
  python version = 3.8.6 (default, Mar 29 2021, 15:09:15) [GCC 9.3.0]
```


### Configuration

```console
$ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/root/ansible-web/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/root/ansible-web/ansible.cfg) = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null
ANSIBLE_SSH_CONTROL_PATH(/root/ansible-web/ansible.cfg) = %(directory)s/%%C
DEFAULT_CALLBACK_WHITELIST(/root/ansible-web/ansible.cfg) = ['profile_tasks']
DEFAULT_ROLES_PATH(/root/ansible-web/ansible.cfg) = ['/root/ansible']
HOST_KEY_CHECKING(/root/ansible-web/ansible.cfg) = False
NETCONF_SSH_CONFIG(env: ANSIBLE_NETCONF_SSH_CONFIG) = True
```


### OS / Environment

Reproduced in target and source OS of SmartOS (base-64-lts 20.4.0)


### Steps to Reproduce

Here's a minimal playbook that I used to recreate the problem. This works with 2.10.6 and below.


```yaml (paste below)
---
- name: build/rebuild machine
  hosts: w2.hweb.stage.cluetrust.net
  gather_facts: no
  vars:
    #    smartos_image: '1d05e788-5409-11eb-b12f-037bd7fee4ee' # base-64-lts  20.4.0
        smartos_memory: 512
        smartos_quota: 40
        smartos_data_top_zone: zones
        filesystems: []
        vm_alias: "{{ inventory_hostname }}"
        vm_brand: "joyent"
        resolvers:
            - '8.8.8.8'
            - '8.8.4.4'

        root_authorized_keys: "{{ (ssh_host_access_keys + ct_admin_keys) | join('\n') }}"

  tasks:
        - name: create/verify host
          throttle: 1
          vmadm:
            brand: "{{ vm_brand }}"
            kernel_version: "{{ vm_kernel | default(omit) }}"
            state: present
            alias: "{{ vm_alias }}"
            hostname: "{{ inventory_hostname }}"
            image_uuid: "{{ smartos_image }}"
            customer_metadata:
              root_authorized_keys: "{{ root_authorized_keys }}"
              user-script: "mkdir /.ct-configured >/dev/null 2>&1 && ( /usr/sbin/mdata-get root_authorized_keys > ~root/.ssh/authorized_keys ; /usr/sbin/mdata-get root_authorized_keys >
 ~admin/.ssh/authorized_keys ; echo 'KbdInteractiveAuthentication no' >> /etc/ssh/sshd_config )"
            max_physical_memory: "{{ smartos_memory }}"
            resolvers: "{{ resolvers }}"
            quota: "{{ smartos_quota }}"
            filesystems: "{{ filesystems }}"
            nics: "{{ nics }}"
            max_lwps: "{{ smartos_lwps | default(omit)}}"
          delegate_to: "{{ global_host }}"

```


### Expected Results

I expected the vmadm to succeed (or at least reach out to the far end to execute the command), but it failed validation inexplicably.


### Actual Results

```console
The full traceback is:
  File "/tmp/ansible_vmadm_payload_wtcbeii_/ansible_vmadm_payload.zip/ansible/module_utils/basic.py", line 1885, in _handle_elements
    validated_params.append(type_checker(value, **kwargs))
  File "/tmp/ansible_vmadm_payload_wtcbeii_/ansible_vmadm_payload.zip/ansible/module_utils/basic.py", line 1763, in _check_type_dict
    return check_type_dict(value)
  File "/tmp/ansible_vmadm_payload_wtcbeii_/ansible_vmadm_payload.zip/ansible/module_utils/common/validation.py", line 431, in check_type_dict
    raise TypeError("dictionary requested, could not parse JSON or key=value")
fatal: [w2.hweb.stage.cluetrust.net -> tarros]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "alias": "XXXXX",
            "brand": "joyent",
            "cpu_type": "qemu64",
            "customer_metadata": {
                "root_authorized_keys": "XXXXX",
                "user-script": "mkdir /.ct-configured >/dev/null 2>&1 && ( /usr/sbin/mdata-get root_authorized_keys > ~root/.ssh/authorized_keys ; /usr/sbin/mdata-get root_authorized_keys > ~admin/.ssh/authorized_keys ; echo 'KbdInteractiveAuthentication no' >> /etc/ssh/sshd_config )"
            },
            "filesystems": [],
            "hostname": "XXXXX",
            "image_uuid": "1d05e788-5409-11eb-b12f-037bd7fee4ee",
            "max_physical_memory": 2048,
            "name": "XXXXX",
            "nics": [
                {
                    "gateways": [
                        "XXX.YY.ZZ.NNN"
                    ],
                    "interface": "net0",
                    "ips": [
                        "XXX.YY.ZZ.NNN/27"
                    ],
                    "nic_tag": "vlan",
                    "primary": true,
                    "vlan_id": "VVV"
                }
            ],
            "quota": 40,
            "resolvers": [
                "NNN.NNN.NNN.NNN",
                "NNN.NNN.NNN.NNN",
                "NNN.NNN.NNN.NNN"
            ],
            "state": "present"
        }
    },
    "msg": "Elements value for option resolvers is of type <class 'str'> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value"
}
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/cloud/smartos/vmadm.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/cloud/smartos/vmadm.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @bcoca @fishman @jasperla @jpdasma @mator @scathatheworm @troy2914 @xen0l
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@gaige since you seem to know vmadm better, do you know whether the other changes made to vmadm in f33323ca8930ee566cb29de4f8218b71e0a1417a are correct?
Yes, the other changes were fine (there were 4 lists in total where the type of items was added), it was just that one list(`resolvers`) that was typed as `dict` when it is actually a string.

I was able to get things working appropriately by changing:
```python3
diff --git a/plugins/modules/cloud/smartos/vmadm.py b/plugins/modules/cloud/smartos/vmadm.py
index 45dc86cc..63a4c212 100644
--- a/plugins/modules/cloud/smartos/vmadm.py
+++ b/plugins/modules/cloud/smartos/vmadm.py
@@ -233,7 +233,7 @@ options:
     description:
       - List of resolvers to be put into C(/etc/resolv.conf).
     type: list
-    elements: dict
+    elements: str
   routes:
     required: false
     description:
@@ -702,7 +702,7 @@ def main():
         vnc_password=dict(type='str', no_log=True),
         disks=dict(type='list', elements='dict'),
         nics=dict(type='list', elements='dict'),
-        resolvers=dict(type='list', elements='dict'),
+        resolvers=dict(type='list', elements='str'),
         filesystems=dict(type='list', elements='dict'),
     )
```
@gaige the patch looks good. Feel free to create a PR (add a `bugfixes` [changelog fragment](https://docs.ansible.com/ansible/devel/community/development_process.html#changelogs-how-to) if you do).
OK, this is my first time with a PR since modules were split out, but #2136 is those changes plus the changelog fragment.

Resolving patch:
diff --git a/plugins/modules/cloud/smartos/vmadm.py b/plugins/modules/cloud/smartos/vmadm.py
--- a/plugins/modules/cloud/smartos/vmadm.py
+++ b/plugins/modules/cloud/smartos/vmadm.py
@@ -233,7 +233,7 @@
     description:
       - List of resolvers to be put into C(/etc/resolv.conf).
     type: list
-    elements: dict
+    elements: str
   routes:
     required: false
     description:
@@ -702,7 +702,7 @@ def main():
         vnc_password=dict(type='str', no_log=True),
         disks=dict(type='list', elements='dict'),
         nics=dict(type='list', elements='dict'),
-        resolvers=dict(type='list', elements='dict'),
+        resolvers=dict(type='list', elements='str'),
         filesystems=dict(type='list', elements='dict'),
     )
 


Test patch: