diff --git a/defaults/main.yml b/defaults/main.yml index 2a7bcc7..93d83c0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -53,3 +53,5 @@ k3s_server_resource_creations: [] k3s_server_resource_patches: [] k3s_node_labels: {} + +k3s_iscsi_enabled: False diff --git a/handlers/main.yml b/handlers/main.yml index d1782ba..8afcd79 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,3 +8,13 @@ listen: __k3s_restart become: True become_user: root + +- name: Restart iscsid service + service: + name: iscsid + state: restarted + daemon_reload: yes + enabled: yes + listen: __iscsid_restart + become: True + become_user: root diff --git a/molecule/rocky9/converge.yml b/molecule/rocky9/converge.yml index 7350034..6f16f1b 100644 --- a/molecule/rocky9/converge.yml +++ b/molecule/rocky9/converge.yml @@ -30,6 +30,7 @@ # token: "{{ hcloud_token | b64encode }}" k3s_node_labels: node.kubernetes.io/exclude-from-external-load-balancers: "true" + k3s_iscsi_enabled: True pre_tasks: - name: Override host variables set_fact: diff --git a/molecule/rocky9/tests/test_default.py b/molecule/rocky9/tests/test_default.py index 0668b83..45b3b74 100644 --- a/molecule/rocky9/tests/test_default.py +++ b/molecule/rocky9/tests/test_default.py @@ -14,6 +14,12 @@ def test_k3s_running_and_enabled(host): assert k3s.is_enabled +def test_iscsid_running_and_enabled(host): + k3s = host.service("iscsid") + assert k3s.is_running + assert k3s.is_enabled + + def test_k3s_node_ready(host): jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa nodes = host.run(f"k3s kubectl get nodes -o jsonpath='{jsonpth}'").stdout diff --git a/tasks/iscsi.yml b/tasks/iscsi.yml new file mode 100644 index 0000000..ead8107 --- /dev/null +++ b/tasks/iscsi.yml @@ -0,0 +1,26 @@ +--- +- block: + - name: Ensure iscsi is installed + package: + name: "{{ item }}" + state: present + loop: + - iscsi-initiator-utils + + - name: Configure iscsi-initiator + copy: + content: "InitiatorName=$(/sbin/iscsi-iname)" + dest: /etc/iscsi/initiatorname.iscsi + owner: root + group: root + mode: 0644 + notify: __iscsid_restart + + - name: Ensure iscsid service is up and running + service: + name: iscsid + daemon_reload: True + enabled: True + state: started + become: True + become_user: root diff --git a/tasks/main.yml b/tasks/main.yml index 9cbf09f..2384bdc 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,3 +5,5 @@ - include_tasks: init.yml when: k3s_server | bool - include_tasks: setup.yml +- incluse_tasks: iscsi.yml + when: k3s_iscsi_enabled | bool