mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 10:13:58 +00:00
59 lines
1.9 KiB
YAML
59 lines
1.9 KiB
YAML
---
|
|
- name: Cleanup stale iSCSI nodes and restart open-iscsi
|
|
hosts: myrddin.prole.org
|
|
become: true
|
|
tasks:
|
|
- name: List configured iSCSI nodes
|
|
ansible.builtin.command: iscsiadm -m node
|
|
register: iscsiadm_nodes
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Build desired iSCSI target list
|
|
ansible.builtin.set_fact:
|
|
desired_iqns: "{{ iscsi_targets | default([]) | map(attribute='iqn') | list }}"
|
|
|
|
- name: Build current iSCSI node list
|
|
ansible.builtin.set_fact:
|
|
iscsi_node_iqns: "{{ iscsiadm_nodes.stdout_lines | default([]) | map('split') | map('first') | list | unique }}"
|
|
|
|
- name: Determine stale iSCSI nodes
|
|
ansible.builtin.set_fact:
|
|
iscsi_stale_iqns: "{{ iscsi_node_iqns | difference(desired_iqns | default([])) }}"
|
|
|
|
- name: Logout stale iSCSI nodes
|
|
ansible.builtin.command: >
|
|
iscsiadm -m node -T {{ item }} -p {{ iscsi_portal }} --logout
|
|
loop: "{{ iscsi_stale_iqns | default([]) }}"
|
|
loop_control:
|
|
label: "{{ item }}"
|
|
failed_when: false
|
|
|
|
- name: Delete stale iSCSI node records
|
|
ansible.builtin.command: >
|
|
iscsiadm -m node -o delete -T {{ item }} -p {{ iscsi_portal }}
|
|
loop: "{{ iscsi_stale_iqns | default([]) }}"
|
|
loop_control:
|
|
label: "{{ item }}"
|
|
failed_when: false
|
|
|
|
- name: Reset open-iscsi failed state
|
|
ansible.builtin.command: systemctl reset-failed open-iscsi
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Restart open-iscsi
|
|
ansible.builtin.service:
|
|
name: open-iscsi
|
|
state: restarted
|
|
|
|
- name: Check open-iscsi status
|
|
ansible.builtin.command: systemctl is-failed open-iscsi
|
|
register: open_iscsi_state
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Report open-iscsi status
|
|
ansible.builtin.debug:
|
|
msg: "open-iscsi state: {{ open_iscsi_state.stdout | default('unknown') }}"
|