This change adds very minimal diff support for just the monitor plugin. It only does a diff based on the arguments passed in by the user and only supports only the "present" state.
To support a "full" diff, it would be necessary to make an additional network call to get the new monitor configuration from the instance. To avoid this, the code just diffs the changes passed in.
Please let me know if there's any changes you'd like me to make. I tested this on a local copy using the following playbook:
- hosts: 127.0.0.1
tasks:
- name: Setup
lucasheld.uptime_kuma.setup:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
- name: Login to get a token for other roles that want to create monitors
lucasheld.uptime_kuma.login:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
register: uptime_kuma_result
- name: Set login token
set_fact:
uptime_kuma_token: "{{ uptime_kuma_result.token }}"
- name: add monitor
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:3001
api_token: "{{ uptime_kuma_token }}"
name: google
type: http
url: https://google.com
state: present
- name: update monitor
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:3001
api_token: "{{ uptime_kuma_token }}"
name: google
type: ping
hostname: 127.0.0.10
url: https://google.com
state: present
- name: remove monitor
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:3001
api_token: "{{ uptime_kuma_token }}"
name: google
type: http
url: https://google.com
state: absent
Putting this file at the repo root and running the following command should execute the playbook: COLLECTIONS_PATHS="./:/usr/share/ansible/collections" ansible-playbook kuma-test-playbook.yml --diff (you may have to adjust the COLLECTIONS_PATH setting to suit your environment.
This should produce the following output (truncated to relevant parts):
TASK [add monitor]
--- before
+++ after
@@ -0,0 +1,5 @@
+accepted_statuscodes:
+- 200-299
+name: google
+type: http
+url: https://google.com
changed: [127.0.0.1]
TASK [update monitor]
--- before
+++ after
@@ -1,6 +1,6 @@
accepted_statuscodes:
- 200-299
-hostname: null
+hostname: 127.0.0.10
name: google
-type: http
+type: ping
url: https://google.com
changed: [127.0.0.1]
TASK [remove monitor]
changed: [127.0.0.1]
This change adds very minimal diff support for just the monitor plugin. It only does a diff based on the arguments passed in by the user and only supports only the "present" state.
To support a "full" diff, it would be necessary to make an additional network call to get the new monitor configuration from the instance. To avoid this, the code just diffs the changes passed in.
Please let me know if there's any changes you'd like me to make. I tested this on a local copy using the following playbook:
Putting this file at the repo root and running the following command should execute the playbook:
COLLECTIONS_PATHS="./:/usr/share/ansible/collections" ansible-playbook kuma-test-playbook.yml --diff
(you may have to adjust theCOLLECTIONS_PATH
setting to suit your environment.This should produce the following output (truncated to relevant parts):