# SPDX-License-Identifier: MIT
---
- name: Manage qnetd backup
  when: operation == "backup"
  block:
    - name: Create /etc/corosync/qnetd_backup directory
      file:
        path: /etc/corosync/qnetd_backup
        state: directory
        mode: "0700"

    # Ansible copy doesn't support 'mode: preserve' with 'remote_src: true'
    - name: Back up qnetd settings
      command:
        cmd: >
          cp --preserve=all --recursive
          /etc/corosync/qnetd /etc/corosync/qnetd_backup
      changed_when: true

- name: Manage qnetd restore
  when: operation == "restore"
  block:
    - name: Restore qnetd settings
      command:
        cmd: >
          cp --preserve=all --recursive
          /etc/corosync/qnetd_backup/qnetd /etc/corosync
      changed_when: true

    - name: Start qnetd
      service:
        name: corosync-qnetd
        state: started
