--- - name: Get list of repositories ansible.builtin.uri: url: "{{ borgmatic_borgwarehouse_url }}/api/repo" method: GET headers: Authorization: "Bearer {{ borgmatic_borgwarehouse_key }}" Content-Type: "application/json" body_format: json return_content: true register: repo_list - name: Get repository informations ansible.builtin.set_fact: repo_infos: "{{ repo_list.json.repoList | selectattr('alias', 'equalto', inventory_hostname) }}" - name: Create repository ansible.builtin.uri: url: "{{ borgmatic_borgwarehouse_url }}/api/repo/add" method: POST headers: Authorization: "Bearer {{ borgmatic_borgwarehouse_key }}" Content-Type: "application/json" body_format: json body: "{{ borgwarehouse_body }}" when: repo_infos | length == 0 - name: Update repository ansible.builtin.uri: url: "{{ borgmatic_borgwarehouse_url }}/api/repo/id/{{ repo_infos[0].id }}/edit" method: PATCH headers: Authorization: "Bearer {{ borgmatic_borgwarehouse_key }}" Content-Type: "application/json" body_format: json body: "{{ borgwarehouse_body }}" when: repo_infos | length > 0