/etc/ansible/roles/ceph-ansible/roles/ceph-handler/tasks/check_socket_non_container.yml
---
- name: check for a ceph mon socket
  shell: stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mon*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: mon_socket_stat
  when: inventory_hostname in groups.get(mon_group_name, [])

- name: check if the ceph mon socket is in-use
  command: grep -q {{ mon_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: mon_socket
  when:
    - inventory_hostname in groups.get(mon_group_name, [])
    - mon_socket_stat.rc == 0

- name: remove ceph mon socket if exists and not used by a process
  file:
    name: "{{ mon_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(mon_group_name, [])
    - mon_socket_stat.rc == 0
    - mon_socket.rc == 1

- name: check for a ceph osd socket
  shell: |
    stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-osd*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: osd_socket_stat
  when: inventory_hostname in groups.get(osd_group_name, [])

- name: check if the ceph osd socket is in-use
  command: grep -q {{ osd_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: osd_socket
  when:
    - inventory_hostname in groups.get(osd_group_name, [])
    - osd_socket_stat.rc == 0

- name: remove ceph osd socket if exists and not used by a process
  file:
    name: "{{ osd_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(osd_group_name, [])
    - osd_socket_stat.rc == 0
    - osd_socket.rc == 1

- name: check for a ceph mds socket
  shell: |
    stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mds*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: mds_socket_stat
  when: inventory_hostname in groups.get(mds_group_name, [])

- name: check if the ceph mds socket is in-use
  command: grep -q {{ mds_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: mds_socket
  when:
    - inventory_hostname in groups.get(mds_group_name, [])
    - mds_socket_stat.rc == 0

- name: remove ceph mds socket if exists and not used by a process
  file:
    name: "{{ mds_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(mds_group_name, [])
    - mds_socket_stat.rc == 0
    - mds_socket.rc == 1

- name: check for a ceph rgw socket
  shell: |
    stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-client.rgw*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: rgw_socket_stat
  when: inventory_hostname in groups.get(rgw_group_name, [])

- name: check if the ceph rgw socket is in-use
  command: grep -q {{ rgw_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: rgw_socket
  when:
    - inventory_hostname in groups.get(rgw_group_name, [])
    - rgw_socket_stat.rc == 0

- name: remove ceph rgw socket if exists and not used by a process
  file:
    name: "{{ rgw_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(rgw_group_name, [])
    - rgw_socket_stat.rc == 0
    - rgw_socket.rc == 1

- name: check for a ceph mgr socket
  shell: |
    stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mgr*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: mgr_socket_stat
  when: inventory_hostname in groups.get(mgr_group_name, [])

- name: check if the ceph mgr socket is in-use
  command: grep -q {{ mgr_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: mgr_socket
  when:
    - inventory_hostname in groups.get(mgr_group_name, [])
    - mgr_socket_stat.rc == 0

- name: remove ceph mgr socket if exists and not used by a process
  file:
    name: "{{ mgr_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(mgr_group_name, [])
    - mgr_socket_stat.rc == 0
    - mgr_socket.rc == 1

- name: check for a ceph rbd mirror socket
  shell: |
    stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-client.rbd-mirror*.asok
  changed_when: false
  failed_when: false
  check_mode: no
  register: rbd_mirror_socket_stat
  when: inventory_hostname in groups.get(rbdmirror_group_name, [])

- name: check if the ceph rbd mirror socket is in-use
  command: grep -q {{ rbd_mirror_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: rbd_mirror_socket
  when:
    - inventory_hostname in groups.get(rbdmirror_group_name, [])
    - rbd_mirror_socket_stat.rc == 0

- name: remove ceph rbd mirror socket if exists and not used by a process
  file:
    name: "{{ rbd_mirror_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(rbdmirror_group_name, [])
    - rbd_mirror_socket_stat.rc == 0
    - rbd_mirror_socket.rc == 1

- name: check for a ceph nfs ganesha socket
  command: stat --printf=%n /var/run/ganesha.pid
  changed_when: false
  failed_when: false
  check_mode: no
  register: nfs_socket_stat
  when: inventory_hostname in groups.get(nfs_group_name, [])

- name: check if the ceph nfs ganesha socket is in-use
  command: grep -q {{ nfs_socket_stat.stdout }} /proc/net/unix
  changed_when: false
  failed_when: false
  check_mode: no
  register: nfs_socket
  when:
    - inventory_hostname in groups.get(nfs_group_name, [])
    - nfs_socket_stat.rc == 0

- name: remove ceph nfs ganesha socket if exists and not used by a process
  file:
    name: "{{ nfs_socket_stat.stdout }}"
    state: absent
  when:
    - inventory_hostname in groups.get(nfs_group_name, [])
    - nfs_socket_stat.rc == 0
    - nfs_socket.rc == 1

- name: check for a tcmu-runner
  command: "pgrep tcmu-runner"
  register: ceph_tcmu_runner_stat
  changed_when: false
  failed_when: false
  check_mode: no
  when: inventory_hostname in groups.get(iscsi_gw_group_name, [])

- name: check for a rbd-target-api
  command: "pgrep rbd-target-api"
  register: ceph_rbd_target_api_stat
  changed_when: false
  failed_when: false
  check_mode: no
  when: inventory_hostname in groups.get(iscsi_gw_group_name, [])

- name: check for a rbd-target-gw
  command: "pgrep name=rbd-target-gw"
  register: ceph_rbd_target_gw_stat
  changed_when: false
  failed_when: false
  check_mode: no
  when: inventory_hostname in groups.get(iscsi_gw_group_name, [])