Skip to content

monitor task fails when changing existing monitor and providing more "accepted_statuscodes" than it was originally created with or do nothing if decreasing the amount #52

@MoGutzeit

Description

@MoGutzeit

When changing an existing monitor with more values in the list of "accepted_statuscodes" than it was created with, the module fails.

For example my playbook with the task:

- name: MONITOR | Create or change Monitors
  lucasheld.uptime_kuma.monitor:
    api_url: mykuma.de
    api_token: "{{ api_token }}"
    type: http
    name: "{{ item | regex_replace(':.*$', '')}}" # Alles ab dem Doppelpunkt wird abgeschnitten
    url: "{{ item | regex_replace('^', 'https:\/\/')}}" # https:// wird vorne angehangen
    state: present
    expiryNotification: yes
    notification_names: "Mail Notification"
    accepted_statuscodes:
      - "200-299"
      - "401"
      - "404"
  loop:
    - mypage1.de
    - mypage2.de
    - mypage3.de

Will work if it creates a new monitor but will fail if:

  • The monitor does already exist and
  • The monitor was originally created with two or less accepted statuscodes
TASK [MONITOR | Create or change Monitors] ***********
failed: [localhost] (item=mypage1.de) => {"ansible_loop_var": "item", "changed": false, "item": "mypage1.de", "msg": "Traceback (most recent call last):\n  File \"/tmp/ansible_lucasheld.uptime_kuma.monitor_payload_48wj05n1/ansible_lucasheld.uptime_kuma.monitor_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/monitor.py\", line 578, in main\n  File \"/tmp/ansible_lucasheld.uptime_kuma.monitor_payload_48wj05n1/ansible_lucasheld.uptime_kuma.monitor_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/monitor.py\", line 425, in run\n  File \"/tmp/ansible_lucasheld.uptime_kuma.monitor_payload_48wj05n1/ansible_lucasheld.uptime_kuma.monitor_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/module_utils/common.py\", line 28, in object_changed\n    if value[i] != value2[i]:\nIndexError: list index out of range\n"}

When decreasing the amount of accepted statuscodes, it won't fail but just not try to change the status codes.
For example a monitor was created with 3 accepted codes and I try to change it to two:

TASK [MONITOR | Create or change Monitors] ***********
ok: [localhost] => (item=mypage1)

The module does not try and change the monitor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions