lucasheld / ansible-uptime-kuma

Ansible collection of modules to configure Uptime Kuma
GNU General Public License v3.0
135 stars 19 forks source link

Multiple monitors in monitor list not working #9

Closed mailuminatti closed 1 year ago

mailuminatti commented 1 year ago

What happened: When creating a status page, multiple monitors can be added in the monitorList section. However, after executing the playbook, only the first monitor is added into the group in UptimeKuma

Expected result: Multiple monitors to be created, after being added in the monitorList

Sample code:

    - name: Add status page with monitor
      lucasheld.uptime_kuma.status_page:
        api_url:  "{{ kuma_api }}"
        api_token: "{{ kuma_api_token }}"
        slug: page-status
        title: 'Status Page'
        publicGroupList:
          - name: 'Page Status Monitors'
            weight: 1
            monitorList:
              - name: monitor_1
              - name: monitor_2
lucasheld commented 1 year ago

Unfortunately i can't reproduce this problem. It's working for me with the following playbook.

---
- hosts: localhost
  connection: local
  tasks:
    - name: Add monitor 1
      lucasheld.uptime_kuma.monitor:
        api_url: http://127.0.0.1:3001
        api_username: admin
        api_password: secret123
        type: http
        name: monitor_1
        url: http://127.0.0.1
        state: present

    - name: Add monitor 2
      lucasheld.uptime_kuma.monitor:
        api_url: http://127.0.0.1:3001
        api_username: admin
        api_password: secret123
        type: http
        name: monitor_2
        url: http://127.0.0.2
        state: present

    - name: Add status page with monitor
      lucasheld.uptime_kuma.status_page:
        api_url: http://127.0.0.1:3001
        api_username: admin
        api_password: secret123
        slug: page-status
        title: 'Status Page'
        publicGroupList:
          - name: 'Page Status Monitors'
            weight: 1
            monitorList:
              - name: monitor_1
              - name: monitor_2

image

mailuminatti commented 1 year ago

Hey @lucasheld, I did a bit more testing, and I can give you further details on how to reproduce this issue. As you highlighted in the comment before, creating the status page with monitors works. However, where it fails is when a monitor is added. The expected result would be to ansible to mark this is a [changed], however it fails with the following error:


TASK [Add status page with monitor] ************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Traceback (most recent call last):\n  File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload_kf4hahkj/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/status_page.py\", line 274, in main\n  File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload_kf4hahkj/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/status_page.py\", line 200, in run\n  File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload_kf4hahkj/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/module_utils/common.py\", line 25, in object_changed\n    if object_changed(value2[i], value[i]):\n  File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload_kf4hahkj/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/module_utils/common.py\", line 25, in object_changed\n    if object_changed(value2[i], value[i]):\nIndexError: list index out of range\n"}

To reproduce, simply create a new status page with one or two monitors, and add an additional one.

lucasheld commented 1 year ago

Thank you! It is a bug that has been fixed in version 0.6.1.