---
# file: roles/incus/tasks/get_and_set_cluster.yml

- name: "incus cluster get {{ ansible_hostname }} {{ item.key }}"
  shell: "/usr/bin/incus cluster get {{ ansible_hostname }} {{ item.key }}"
  register: get_configuration
  changed_when: false
  check_mode: false
  failed_when: get_configuration.rc != 0 and "does not exist on cluster member" not in get_configuration.stderr

- name: "incus cluster set {{ ansible_hostname }} set {{ item.key }}"
  shell: "/usr/bin/incus cluster set {{ ansible_hostname }} {{ item.key }}={{ item.value }}"
  when: get_configuration.stdout != item.value
