Repository: ansible-collections/community.general

Issue:
community.general.icinga2_host - including template not working
### Summary

I am trying to create a Host with this module. The original curl command, which works, is (anonymized)
```
curl -k -s -S -i -u root:secret -H 'Accept: application/json' \
 -X PUT 'https://icinga2-master.example.com:5665/v1/objects/hosts/myhost.example.com' \
 -d '{ "templates": [ "generic-linux" ], "attrs": { "address": "1.2.3.4", "check_command": "icmp", "zone": "myzone", "vars.procs.myproc.procs_command": "fancyproc", "vars.procs.myproc.procs_critical": "1:" }, "pretty": true }'
```
The host is created. The "generic-linux" template, has an 'import "generic-host"' inside and both are imported into the host

Trying to add this via the playbook
```
- hosts: all
  tasks:
    - name: Add host to icinga
      community.general.icinga2_host:
        url: "https://icinga2-master.example.com:5665"
        url_username: "root"
        url_password: "secret"
        validate_certs: no
        state: present
        name: "{{ ansible_fqdn }}"
        ip: "{{ ansible_default_ipv4.address }}"
        check_command: "icmp"
        zone: "myzone"
        template: "generic-linux"
        variables:
          procs: {
             myproc: {
               'procs_command' : 'fancyproc',
               'procs_critical' : '1:'
             }
          }
      delegate_to: 127.0.0.1
```
creates the host, but does not both import the generic-linux and generic-host template. Also the procs service, which is applied via curl, is not applied via playbook. Does this module calls curl in a different way than my example?

### Issue Type

Bug Report

### Component Name

community.general.icinga2_host
icinga2_host.py

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.11.4]

```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
community.general 4.1.0

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

Ubuntu 20.04 LTS

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
  tasks:
    - name: Add host to icinga
      community.general.icinga2_host:
        url: "https://icinga2-master.example.com:5665"
        url_username: "root"
        url_password: "secret"
        validate_certs: no
        state: present
        name: "{{ ansible_fqdn }}"
        ip: "{{ ansible_default_ipv4.address }}"
        check_command: "icmp"
        zone: "myzone"
        template: "generic-linux"
        variables:
          procs: {
             myproc: {
               'procs_command' : 'fancyproc',
               'procs_critical' : '1:'
             }
          }
      delegate_to: 127.0.0.1
```


### Expected Results

Host is created with all variables from the generic-linux ( + generic-host) templates.

### Actual Results

Host is created without variables from the templates.



### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/monitoring/icinga2_host.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/monitoring/icinga2_host.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 @t794104
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@t794104 @felixfontein is this plugin still maintained? No response since last year... :) 
@MarcusCaepio doesn't look like it... but then, it's "community maintained", so everyone can help if they want :)
Files identified in the description:
* [`plugins/modules/icinga2_host.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/icinga2_host.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 --->

Resolving patch:
diff --git a/plugins/modules/icinga2_host.py b/plugins/modules/icinga2_host.py
--- a/plugins/modules/icinga2_host.py
+++ b/plugins/modules/icinga2_host.py
@@ -256,9 +256,9 @@ def main():
     state = module.params["state"]
     name = module.params["name"]
     zone = module.params["zone"]
-    template = [name]
+    template = []
     if module.params["template"]:
-        template.append(module.params["template"])
+        template = [module.params["template"]]
     check_command = module.params["check_command"]
     ip = module.params["ip"]
     display_name = module.params["display_name"]
@@ -273,20 +273,18 @@ def main():
         module.fail_json(msg="unable to connect to Icinga. Exception message: %s" % (e))
 
     data = {
+        'templates': template,
         'attrs': {
             'address': ip,
             'display_name': display_name,
             'check_command': check_command,
             'zone': zone,
-            'vars': {
-                'made_by': "ansible",
-            },
-            'templates': template,
+            'vars.made_by': "ansible"
         }
     }
 
-    if variables:
-        data['attrs']['vars'].update(variables)
+    for key, value in variables.items():
+        data['attrs']['vars.' + key] = value
 
     changed = False
     if icinga.exists(name):


Test patch: