handler: refact check_socket_non_container

the `stat --printf=%n` returns something like following:

```
ok: [osd0] => changed=false
  cmd: |-
    stat --printf=%n /var/run/ceph/ceph-osd*.asok
  delta: '0:00:00.009388'
  end: '2020-10-06 06:18:28.109500'
  failed_when_result: false
  rc: 0
  start: '2020-10-06 06:18:28.100112'
  stderr: ''
  stderr_lines: <omitted>
  stdout: /var/run/ceph/ceph-osd.2.asok/var/run/ceph/ceph-osd.5.asok
  stdout_lines: <omitted>
```

it makes the next task "check if the ceph osd socket is in-use" grep
like this:

```
ok: [osd0] => changed=false
  cmd:
  - grep
  - -q
  - /var/run/ceph/ceph-osd.2.asok/var/run/ceph/ceph-osd.5.asok
  - /proc/net/unix
```

which will obviously fail because this path never exists. It makes the
OSD handler broken.

Let's use `find` module instead.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 46d4d97da9)
pull/5934/head
Guillaume Abrioux 2020-10-06 14:58:46 +02:00
parent bff2123430
commit 709deb90cc
2 changed files with 106 additions and 94 deletions

View File

@ -1,198 +1,210 @@
--- ---
- name: check for a ceph mon socket - name: find ceph mon socket
shell: stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mon*.asok find:
changed_when: false paths: ["{{ rbd_client_admin_socket_path }}"]
failed_when: false recurse: yes
check_mode: no file_type: any
patterns: "{{ cluster }}-mon*.asok"
use_regex: no
register: mon_socket_stat register: mon_socket_stat
when: inventory_hostname in groups.get(mon_group_name, []) when: inventory_hostname in groups.get(mon_group_name, [])
- name: check if the ceph mon socket is in-use - name: check if the ceph mon socket is in-use
command: grep -q {{ mon_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: mon_socket register: mon_socket
with_items: "{{ mon_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(mon_group_name, []) - inventory_hostname in groups.get(mon_group_name, [])
- mon_socket_stat.rc == 0 - mon_socket_stat.files | length > 0
- name: remove ceph mon socket if exists and not used by a process - name: remove ceph mon socket if exists and not used by a process
file: file:
name: "{{ mon_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ mon_socket_stat.files }}"
- "{{ mon_socket.results }}"
when: when:
- inventory_hostname in groups.get(mon_group_name, []) - inventory_hostname in groups.get(mon_group_name, [])
- mon_socket_stat.rc == 0 - mon_socket_stat.files | length > 0
- mon_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph osd socket - name: find ceph osd socket
shell: | find:
stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-osd*.asok paths: ["{{ rbd_client_admin_socket_path }}"]
changed_when: false recurse: yes
failed_when: false file_type: any
check_mode: no patterns: "{{ cluster }}-osd.*.asok"
use_regex: no
register: osd_socket_stat register: osd_socket_stat
when: inventory_hostname in groups.get(osd_group_name, []) when: inventory_hostname in groups.get(osd_group_name, [])
- name: check if the ceph osd socket is in-use - name: check if the ceph osd socket is in-use
command: grep -q {{ osd_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: osd_socket register: osd_socket
with_items: "{{ osd_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(osd_group_name, []) - inventory_hostname in groups.get(osd_group_name, [])
- osd_socket_stat.rc == 0 - osd_socket_stat.files | length > 0
- name: remove ceph osd socket if exists and not used by a process - name: remove ceph osd socket if exists and not used by a process
file: file:
name: "{{ osd_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ osd_socket_stat.files }}"
- "{{ osd_socket.results }}"
when: when:
- inventory_hostname in groups.get(osd_group_name, []) - inventory_hostname in groups.get(osd_group_name, [])
- osd_socket_stat.rc == 0 - osd_socket_stat.files | length > 0
- osd_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph mds socket - name: find ceph osd socket
shell: | find:
stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mds*.asok paths: ["{{ rbd_client_admin_socket_path }}"]
changed_when: false recurse: yes
failed_when: false file_type: any
check_mode: no patterns: "{{ cluster }}-mds*.asok"
use_regex: no
register: mds_socket_stat register: mds_socket_stat
when: inventory_hostname in groups.get(mds_group_name, []) when: inventory_hostname in groups.get(mds_group_name, [])
- name: check if the ceph mds socket is in-use - name: check if the ceph mds socket is in-use
command: grep -q {{ mds_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: mds_socket register: mds_socket
with_items: "{{ mds_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(mds_group_name, []) - inventory_hostname in groups.get(mds_group_name, [])
- mds_socket_stat.rc == 0 - mds_socket_stat.files | length > 0
- name: remove ceph mds socket if exists and not used by a process - name: remove ceph mds socket if exists and not used by a process
file: file:
name: "{{ mds_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ mds_socket_stat.files }}"
- "{{ mds_socket.results }}"
when: when:
- inventory_hostname in groups.get(mds_group_name, []) - inventory_hostname in groups.get(mds_group_name, [])
- mds_socket_stat.rc == 0 - mds_socket_stat.files | length > 0
- mds_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph rgw socket - name: find ceph rgw socket
shell: | find:
stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-client.rgw*.asok paths: ["{{ rbd_client_admin_socket_path }}"]
changed_when: false recurse: yes
failed_when: false file_type: any
check_mode: no patterns: "{{ cluster }}-client.rgw*.asok"
use_regex: no
register: rgw_socket_stat register: rgw_socket_stat
when: inventory_hostname in groups.get(rgw_group_name, []) when: inventory_hostname in groups.get(rgw_group_name, [])
- name: check if the ceph rgw socket is in-use - name: check if the ceph rgw socket is in-use
command: grep -q {{ rgw_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: rgw_socket register: rgw_socket
with_items: "{{ rgw_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(rgw_group_name, []) - inventory_hostname in groups.get(rgw_group_name, [])
- rgw_socket_stat.rc == 0 - rgw_socket_stat.files | length > 0
- name: remove ceph rgw socket if exists and not used by a process - name: remove ceph rgw socket if exists and not used by a process
file: file:
name: "{{ rgw_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ rgw_socket_stat.files }}"
- "{{ rgw_socket.results }}"
when: when:
- inventory_hostname in groups.get(rgw_group_name, []) - inventory_hostname in groups.get(rgw_group_name, [])
- rgw_socket_stat.rc == 0 - rgw_socket_stat.files | length > 0
- rgw_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph mgr socket - name: find ceph mgr socket
shell: | find:
stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mgr*.asok paths: ["{{ rbd_client_admin_socket_path }}"]
changed_when: false recurse: yes
failed_when: false file_type: any
check_mode: no patterns: "{{ cluster }}-mgr*.asok"
use_regex: no
register: mgr_socket_stat register: mgr_socket_stat
when: inventory_hostname in groups.get(mgr_group_name, []) when: inventory_hostname in groups.get(mgr_group_name, [])
- name: check if the ceph mgr socket is in-use - name: check if the ceph mgr socket is in-use
command: grep -q {{ mgr_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: mgr_socket register: mgr_socket
with_items: "{{ mgr_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(mgr_group_name, []) - inventory_hostname in groups.get(mgr_group_name, [])
- mgr_socket_stat.rc == 0 - mgr_socket_stat.files | length > 0
- name: remove ceph mgr socket if exists and not used by a process - name: remove ceph mgr socket if exists and not used by a process
file: file:
name: "{{ mgr_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ mgr_socket_stat.files }}"
- "{{ mgr_socket.results }}"
when: when:
- inventory_hostname in groups.get(mgr_group_name, []) - inventory_hostname in groups.get(mgr_group_name, [])
- mgr_socket_stat.rc == 0 - mgr_socket_stat.files | length > 0
- mgr_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph rbd mirror socket - name: find ceph rbd mirror socket
shell: | find:
stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-client.rbd-mirror*.asok paths: ["{{ rbd_client_admin_socket_path }}"]
changed_when: false recurse: yes
failed_when: false file_type: any
check_mode: no patterns: "{{ cluster }}-client.rbd-mirror*.asok"
use_regex: no
register: rbd_mirror_socket_stat register: rbd_mirror_socket_stat
when: inventory_hostname in groups.get(rbdmirror_group_name, []) when: inventory_hostname in groups.get(rbdmirror_group_name, [])
- name: check if the ceph rbd mirror socket is in-use - name: check if the ceph rbd mirror socket is in-use
command: grep -q {{ rbd_mirror_socket_stat.stdout }} /proc/net/unix command: grep -q {{ item.path }} /proc/net/unix
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: rbd_mirror_socket register: rbd_mirror_socket
with_items: "{{ rbd_mirror_socket_stat.files }}"
when: when:
- inventory_hostname in groups.get(rbdmirror_group_name, []) - inventory_hostname in groups.get(rbdmirror_group_name, [])
- rbd_mirror_socket_stat.rc == 0 - rbd_mirror_socket_stat.files | length > 0
- name: remove ceph rbd mirror socket if exists and not used by a process - name: remove ceph rbd mirror socket if exists and not used by a process
file: file:
name: "{{ rbd_mirror_socket_stat.stdout }}" name: "{{ item.0.path }}"
state: absent state: absent
with_together:
- "{{ rbd_mirror_socket_stat.files }}"
- "{{ rbd_mirror_socket.results }}"
when: when:
- inventory_hostname in groups.get(rbdmirror_group_name, []) - inventory_hostname in groups.get(rbdmirror_group_name, [])
- rbd_mirror_socket_stat.rc == 0 - rbd_mirror_socket_stat.files | length > 0
- rbd_mirror_socket.rc == 1 - item.1.rc == 1
- name: check for a ceph nfs ganesha socket - name: check for a nfs ganesha pid
command: stat --printf=%n /var/run/ganesha.pid command: "pgrep ganesha.nfsd"
register: nfs_process
changed_when: false changed_when: false
failed_when: false failed_when: false
check_mode: no check_mode: no
register: nfs_socket_stat
when: inventory_hostname in groups.get(nfs_group_name, []) 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 - name: check for a tcmu-runner
command: "pgrep tcmu-runner" command: "pgrep tcmu-runner"
register: ceph_tcmu_runner_stat register: ceph_tcmu_runner_stat

View File

@ -5,37 +5,37 @@
# We do not want to run these checks on initial deployment (`socket.rc == 0`) # We do not want to run these checks on initial deployment (`socket.rc == 0`)
- name: set_fact handler_mon_status - name: set_fact handler_mon_status
set_fact: set_fact:
handler_mon_status: "{{ (mon_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_mon_container_stat.get('rc') == 0 and ceph_mon_container_stat.get('stdout_lines', []) | length != 0) }}" handler_mon_status: "{{ 0 in (mon_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_mon_container_stat.get('rc') == 0 and ceph_mon_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(mon_group_name, []) when: inventory_hostname in groups.get(mon_group_name, [])
- name: set_fact handler_osd_status - name: set_fact handler_osd_status
set_fact: set_fact:
handler_osd_status: "{{ (osd_socket.get('rc') == 0 and ceph_current_status.fsid is defined) if not containerized_deployment | bool else (ceph_osd_container_stat.get('rc') == 0 and ceph_osd_container_stat.get('stdout_lines', []) | length != 0) }}" handler_osd_status: "{{ 0 in (osd_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_osd_container_stat.get('rc') == 0 and ceph_osd_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(osd_group_name, []) when: inventory_hostname in groups.get(osd_group_name, [])
- name: set_fact handler_mds_status - name: set_fact handler_mds_status
set_fact: set_fact:
handler_mds_status: "{{ (mds_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_mds_container_stat.get('rc') == 0 and ceph_mds_container_stat.get('stdout_lines', []) | length != 0) }}" handler_mds_status: "{{ 0 in (mds_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_mds_container_stat.get('rc') == 0 and ceph_mds_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(mds_group_name, []) when: inventory_hostname in groups.get(mds_group_name, [])
- name: set_fact handler_rgw_status - name: set_fact handler_rgw_status
set_fact: set_fact:
handler_rgw_status: "{{ (rgw_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_rgw_container_stat.get('rc') == 0 and ceph_rgw_container_stat.get('stdout_lines', []) | length != 0) }}" handler_rgw_status: "{{ 0 in (rgw_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_rgw_container_stat.get('rc') == 0 and ceph_rgw_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(rgw_group_name, []) when: inventory_hostname in groups.get(rgw_group_name, [])
- name: set_fact handler_nfs_status - name: set_fact handler_nfs_status
set_fact: set_fact:
handler_nfs_status: "{{ (nfs_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_nfs_container_stat.get('rc') == 0 and ceph_nfs_container_stat.get('stdout_lines', []) | length != 0) }}" handler_nfs_status: "{{ (nfs_process.get('rc') == 0) if not containerized_deployment | bool else (ceph_nfs_container_stat.get('rc') == 0 and ceph_nfs_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(nfs_group_name, []) when: inventory_hostname in groups.get(nfs_group_name, [])
- name: set_fact handler_rbd_status - name: set_fact handler_rbd_status
set_fact: set_fact:
handler_rbd_mirror_status: "{{ (rbd_mirror_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_rbd_mirror_container_stat.get('rc') == 0 and ceph_rbd_mirror_container_stat.get('stdout_lines', []) | length != 0) }}" handler_rbd_mirror_status: "{{ 0 in (rbd_mirror_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_rbd_mirror_container_stat.get('rc') == 0 and ceph_rbd_mirror_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(rbdmirror_group_name, []) when: inventory_hostname in groups.get(rbdmirror_group_name, [])
- name: set_fact handler_mgr_status - name: set_fact handler_mgr_status
set_fact: set_fact:
handler_mgr_status: "{{ (mgr_socket.get('rc') == 0) if not containerized_deployment | bool else (ceph_mgr_container_stat.get('rc') == 0 and ceph_mgr_container_stat.get('stdout_lines', []) | length != 0) }}" handler_mgr_status: "{{ 0 in (mgr_socket.results | map(attribute='rc') | list) if not containerized_deployment | bool else (ceph_mgr_container_stat.get('rc') == 0 and ceph_mgr_container_stat.get('stdout_lines', []) | length != 0) }}"
when: inventory_hostname in groups.get(mgr_group_name, []) when: inventory_hostname in groups.get(mgr_group_name, [])
- name: set_fact handler_crash_status - name: set_fact handler_crash_status