prole/infrastructure/roles/iscsi/tasks/iscsi_target.yml
chrisfu 2244d6acd6 Refactor iSCSI Synology mounts to /synology/d00x
- Rename host mount namespace from /prole/d00x to /synology/d00x

- Make LUN ownership explicit per host in inventory (myrddin=d001; merlin=d002,d004; pi=d003)

- Add safe migration cleanup for legacy /prole/d00x mounts and stale /etc/fstab entries

- Update k3s/ArgoCD/OpenTofu manifests and PV node affinities to match new mount paths

- Improve iSCSI role check-mode behavior and add quiesce/detach flow in ansible.sh
2026-03-21 10:43:06 -07:00

75 lines
2.3 KiB
YAML

---
- name: Ensure node record exists for target
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }}
register: node_check
changed_when: false
failed_when: false
- name: Create node record if missing
ansible.builtin.command: >
iscsiadm -m node -o new -T {{ t.iqn }} -p {{ iscsi_portal }}
when: node_check.rc != 0
- name: Configure CHAP authmethod
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }}
--op update -n node.session.auth.authmethod -v CHAP
when: (t.chap_user | default('')) | length > 0
- name: Configure CHAP username
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }}
--op update -n node.session.auth.username -v {{ t.chap_user }}
when: (t.chap_user | default('')) | length > 0
- name: Configure CHAP password
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }}
--op update -n node.session.auth.password -v {{ t.chap_password }}
when: (t.chap_user | default('')) | length > 0
no_log: true
- name: Check if target session is already logged in
ansible.builtin.shell: >-
iscsiadm -m session 2>/dev/null | grep -Fq -- {{ t.iqn | quote }}
register: session_check
changed_when: false
failed_when: false
- name: Login to target
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }} --login
register: login
changed_when: false
failed_when: false
when: session_check.rc != 0
- name: Re-check session after login attempt
ansible.builtin.shell: >-
iscsiadm -m session 2>/dev/null | grep -Fq -- {{ t.iqn | quote }}
register: session_after_login
changed_when: false
failed_when: false
when: session_check.rc != 0
- name: Fail if login did not establish a session
ansible.builtin.fail:
msg: |-
iSCSI login failed for {{ t.iqn }} at {{ iscsi_portal }}.
login.rc={{ login.rc | default('') }}
login.stdout={{ (login.stdout | default('')) | trim }}
login.stderr={{ (login.stderr | default('')) | trim }}
when:
- session_check.rc != 0
- session_after_login is defined
- session_after_login.rc != 0
- login is defined
- login.rc not in [0, 15]
- name: Ensure iSCSI autologin
ansible.builtin.command: >
iscsiadm -m node -T {{ t.iqn }} -p {{ iscsi_portal }}
--op update -n node.startup -v automatic