---
- name: Linux | Delete the PKI directory
  file:
    path: /{{ facts.tmpfs_volume_path }}/{{ facts.tmpfs_volume_name }}/
    state: absent
  when: facts.ansible_system == "Linux"

- block:
    - name: MacOS | check fs the ramdisk exists
      command: /usr/sbin/diskutil info "{{ facts.tmpfs_volume_name }}"
      failed_when: false
      changed_when: false
      register: diskutil_info

    - name: MacOS | unmount and eject the ram disk
      shell: >
        /usr/sbin/diskutil umount force "/{{ facts.tmpfs_volume_path }}/{{ facts.tmpfs_volume_name }}/" &&
        /usr/sbin/diskutil eject "{{ facts.tmpfs_volume_name }}"
      changed_when: false
      when: diskutil_info.rc == 0
      register: result
      until: result.rc == 0
      retries: 5
      delay: 3
  when:
    - facts.ansible_system == "Darwin"
