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

- name: "incus {{ item.section }} get {{ item.object | default('') }} {{ item.key }}"
  ansible.builtin.shell: "/usr/bin/incus {{ item.section }} get {{ item.object | default('') }} {{ item.key }}"
  register: get_configuration
  changed_when: false
  check_mode: false
  failed_when: 'get_configuration.rc != 0 and "not found" not in get_configuration.stderr'

- name: "/usr/bin/incus {{ item.section }} set {{ item.object | default('') }} {{ item.key }}"
  ansible.builtin.shell: "/usr/bin/incus {{ item.section }} set {{ item.object | default('') }} {{ item.key }} -- \"{{ item.value }}\""
  when: get_configuration.stdout != item.value
