mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 14:54:34 +00:00
70 lines
2.2 KiB
YAML
70 lines
2.2 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.command: >
|
|
iscsiadm -m session -T {{ t.iqn }} -p {{ iscsi_portal }}
|
|
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.command: >
|
|
iscsiadm -m session -T {{ t.iqn }} -p {{ iscsi_portal }}
|
|
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 }}"
|
|
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
|