Repository: ansible-collections/community.general

Issue:
community.general.consul add_service failing with 'method' object is not iterable
### Summary

When trying to add a service using `community.general.consul`, the following error is thrown:

```
The full traceback is:
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 597, in main
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 246, in register_with_consul
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 262, in add
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 336, in add_service
fatal: [webserver00]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "check_host": null,
            "check_id": null,
            "check_name": null,
            "check_node": null,
            "host": "localhost",
            "http": null,
            "interval": null,
            "notes": null,
            "port": 8500,
            "scheme": "http",
            "script": null,
            "service_address": null,
            "service_id": null,
            "service_name": "nginx",
            "service_port": 80,
            "state": "present",
            "tags": null,
            "tcp": null,
            "timeout": null,
            "token": null,
            "ttl": null,
            "validate_certs": true
        }
    },
    "msg": "'method' object is not iterable"
}
```

I think this was related to the changes in https://github.com/ansible-collections/community.general/pull/4590. Specifically, it looks like it is failing due to this line https://github.com/ansible-collections/community.general/blob/main/plugins/modules/clustering/consul/consul.py#L336

I believe that line needs changing to:
```
checks=[check.to_dict() for check in service.checks()],
```

I would have opened a PR with this change, but I don't know enough about the inner workings of Ansible, happy to open a PR once this issue has been reviewed and if the suggested changes seem reasonable.

### Issue Type

Bug Report

### Component Name

`community.general.consul`

### Ansible Version

```
ansible 2.10.6
  config file = /home/deploy/ansible_user/ansible/ansible.cfg
  configured module search path = ['/home/deploy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/deploy/.virtualenvs/python3/lib/python3.6/site-packages/ansible
  executable location = /home/deploy/.virtualenvs/python3/bin/ansible
  python version = 3.6.9 (default, Nov  7 2019, 10:44:02) [GCC 8.3.0]
```


### Community.general Version

```console (paste below)
$ # /home/deploy/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.1
```


### Configuration

```console (paste below)
ANSIBLE_PIPELINING(/home/deploy/ansible_user/ansible/ansible.cfg) = False
ANSIBLE_SSH_ARGS(/home/deploy/ansible_user/ansible/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=15m -o ForwardAgent=yes
ANSIBLE_SSH_CONTROL_PATH(/home/deploy/ansible_user/ansible/ansible.cfg) = /tmp/%%h-%%r
DEFAULT_BECOME_FLAGS(/home/deploy/ansible_user/ansible/ansible.cfg) = -HE
DEFAULT_MANAGED_STR(/home/deploy/ansible_user/ansible/ansible.cfg) = Ansible managed file, do not edit directly
DEFAULT_ROLES_PATH(/home/deploy/ansible_user/ansible/ansible.cfg) = ['/home/deploy/ansible_user/ansible/roles-galaxy', '/home/deploy/ansible_user/ansible/roles']
DEFAULT_SCP_IF_SSH(/home/deploy/ansible_user/ansible/ansible.cfg) = True
HOST_KEY_CHECKING(/home/deploy/ansible_user/ansible/ansible.cfg) = False
TRANSFORM_INVALID_GROUP_CHARS(/home/deploy/ansible_user/ansible/ansible.cfg) = never
```


### OS / Environment

Ubuntu - 18.04.2 LTS

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Register nginx service with the local consul agent
  community.general.consul:
    service_name: nginx
    service_port: 80
```


### Expected Results

The service to be successfully registered with Consul.

### Actual Results

```console (paste below)
The full traceback is:
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 597, in main
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 246, in register_with_consul
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 262, in add
  File "/tmp/ansible_community.general.consul_payload_6vojovp1/ansible_community.general.consul_payload.zip/ansible_collections/community/general/plugins/modules/consul.py", line 336, in add_service
fatal: [webserver00]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "check_host": null,
            "check_id": null,
            "check_name": null,
            "check_node": null,
            "host": "localhost",
            "http": null,
            "interval": null,
            "notes": null,
            "port": 8500,
            "scheme": "http",
            "script": null,
            "service_address": null,
            "service_id": null,
            "service_name": "nginx",
            "service_port": 80,
            "state": "present",
            "tags": null,
            "tcp": null,
            "timeout": null,
            "token": null,
            "ttl": null,
            "validate_certs": true
        }
    },
    "msg": "'method' object is not iterable"
}
```


### Code of Conduct

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


Discussion:
Files identified in the description:
* [`plugins/modules/clustering/consul/consul.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/clustering/consul/consul.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @sgargan
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
CC @russoz since it's about your change

Resolving patch:
diff --git a/plugins/modules/clustering/consul/consul.py b/plugins/modules/clustering/consul/consul.py
--- a/plugins/modules/clustering/consul/consul.py
+++ b/plugins/modules/clustering/consul/consul.py
@@ -333,7 +333,7 @@ def add_service(module, service):
                      service_id=result.id,
                      service_name=result.name,
                      service_port=result.port,
-                     checks=[check.to_dict() for check in service.checks],
+                     checks=[check.to_dict() for check in service.checks()],
                      tags=result.tags)
 
 


Test patch: