Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MoGutzeit opened this issue Jul 25, 2024 · 0 comments

Comments

@MoGutzeit
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant