Add OpenStack iSCSI Multipath Playbooks and Jobs

Change-Id: Id29b17c9ef799bd5ae0560eaedfada6dd55a3b3d
diff --git a/playbooks/setup-openstack-iscsi-multipath/post.yaml b/playbooks/setup-openstack-iscsi-multipath/post.yaml
new file mode 100644
index 0000000..e11f10d
--- /dev/null
+++ b/playbooks/setup-openstack-iscsi-multipath/post.yaml
@@ -0,0 +1,33 @@
+- hosts: undercloud-client
+  vars_files:
+    - vars.yaml
+  tasks:
+    - name: Remove the Multipath iSCSI Ports from the StorPool Node
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "server", "remove", "port", "{{ storpool_node }}", "{{ item }}" ]
+      loop:
+        - "{{ port_node_1_iscsi0 }}"
+        - "{{ port_node_1_iscsi1 }}"
+
+    - name: Remove the Multipath iSCSI Ports from the OpenStack Node
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "server", "remove", "port", "{{ openstack_node }}", "{{ item }}" ]
+      loop:
+        - "{{ port_node_2_iscsi0 }}"
+        - "{{ port_node_2_iscsi1 }}"
+
+    - name: Delete the Multipath iSCSI Ports
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "port", "delete", "{{ item }}" ]
+      loop :
+        - "{{ port_node_1_iscsi0 }}"
+        - "{{ port_node_1_iscsi1 }}"
+        - "{{ port_node_2_iscsi0 }}"
+        - "{{ port_node_2_iscsi1 }}"
+
+    - name: Delete Multipath iSCSI Networks
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "network", "delete", "{{ item }}" ]
+      loop:
+        - "{{ network_1 }}"
+        - "{{ network_2 }}"
diff --git a/playbooks/setup-openstack-iscsi-multipath/pre.yaml b/playbooks/setup-openstack-iscsi-multipath/pre.yaml
new file mode 100644
index 0000000..cb1c099
--- /dev/null
+++ b/playbooks/setup-openstack-iscsi-multipath/pre.yaml
@@ -0,0 +1,111 @@
+- hosts: undercloud-client
+  vars_files:
+    - vars.yaml
+  tasks:
+    - name: Create Multipath iSCSI Networks
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "network", "create", "{{ item }}" ]
+      loop:
+        - "{{ network_1 }}"
+        - "{{ network_2 }}"
+
+    - name: Create Multipath iSCSI Subnets
+      ansible.builtin.command:
+        argv:
+          - "{{ os_venv }}/bin/openstack"
+          - --os-cloud
+          - openstack-testing
+          - subnet
+          - create
+          - --subnet-range
+          - "{{ item.ip_range }}"
+          - --network
+          - "{{ item.network }}"
+          - "{{ item.subnet }}"
+      loop:
+        - { ip_range: "{{ network_ip_iscsi0 }}", network: "{{ network_1 }}", subnet: "{{ subnet_1 }}" }
+        - { ip_range: "{{ network_ip_iscsi1 }}", network: "{{ network_2 }}", subnet: "{{ subnet_2 }}" }
+
+    # TODO: Support port security
+    - name: Create the Multipath iSCSI Ports
+      ansible.builtin.command:
+        argv:
+          - "{{ os_venv }}/bin/openstack"
+          - --os-cloud
+          - openstack-testing
+          - port
+          - create
+          - --network
+          - "{{ item.network }}"
+          - --fixed-ip
+          - "subnet={{ item.subnet }},ip-address={{ item.ip }}"
+          - --disable-port-security
+          - "{{ item.port }}"
+      loop:
+        - { network: "{{ network_1 }}", subnet: "{{ subnet_1 }}", ip: "{{ ip_node_1_iscsi0 }}", port: "{{ port_node_1_iscsi0 }}" }
+        - { network: "{{ network_2 }}", subnet: "{{ subnet_2 }}", ip: "{{ ip_node_1_iscsi1 }}", port: "{{ port_node_1_iscsi1 }}" }
+        - { network: "{{ network_1 }}", subnet: "{{ subnet_1 }}", ip: "{{ ip_node_2_iscsi0 }}", port: "{{ port_node_2_iscsi0 }}" }
+        - { network: "{{ network_2 }}", subnet: "{{ subnet_2 }}", ip: "{{ ip_node_2_iscsi1 }}", port: "{{ port_node_2_iscsi1 }}" }
+
+    - name: Attach the Multipath iSCSI Ports to the StorPool Node
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "server", "add", "port", "{{ storpool_node }}", "{{ item }}" ]
+      loop:
+        - "{{ port_node_1_iscsi0 }}"
+        - "{{ port_node_1_iscsi1 }}"
+
+    - name: Attach the Multipath iSCSI Ports to the OpenStack Node
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "server", "add", "port", "{{ openstack_node }}", "{{ item }}" ]
+      loop:
+        - "{{ port_node_2_iscsi0 }}"
+        - "{{ port_node_2_iscsi1 }}"
+
+    - name: Get Information About port_node_1_iscsi0
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "port", "show", "--format", "json", "{{ port_node_1_iscsi0 }}" ]
+      register: port_node_1_iscsi0_info
+
+    - name: Get MAC Address of port_node_1_iscsi0
+      ansible.builtin.set_fact:
+        port_node_1_iscsi0_mac: "{{ (port_node_1_iscsi0_info.stdout | from_json).mac_address }}"
+
+    - name: Get Information About port_node_1_iscsi1
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "port", "show", "--format", "json", "{{ port_node_1_iscsi1 }}" ]
+      register: port_node_1_iscsi1_info
+
+    - name: Get MAC Address of port_node_1_iscsi1
+      ansible.builtin.set_fact:
+        port_node_1_iscsi1_mac: "{{ (port_node_1_iscsi1_info.stdout | from_json).mac_address }}"
+
+    - name: Get Information About port_node_2_iscsi0
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "port", "show", "--format", "json", "{{ port_node_2_iscsi0 }}" ]
+      register: port_node_2_iscsi0_info
+
+    - name: Get MAC Address of port_node_2_iscsi0
+      ansible.builtin.set_fact:
+        port_node_2_iscsi0_mac: "{{ (port_node_2_iscsi0_info.stdout | from_json).mac_address }}"
+
+    - name: Get Information About port_node_2_iscsi1
+      ansible.builtin.command:
+        argv: [ "{{ os_venv }}/bin/openstack", "--os-cloud", "openstack-testing", "port", "show", "--format", "json", "{{ port_node_2_iscsi1 }}" ]
+      register: port_node_2_iscsi1_info
+
+    - name: Get MAC Address of port_node_2_iscsi1
+      ansible.builtin.set_fact:
+        port_node_2_iscsi1_mac: "{{ (port_node_2_iscsi1_info.stdout | from_json).mac_address }}"
+
+    - name: Dump Required Information for Next Stage
+      ansible.builtin.copy:
+        content: |
+          port_node_1_iscsi0_mac: {{ port_node_1_iscsi0_mac }}
+          port_node_1_iscsi1_mac: {{ port_node_1_iscsi1_mac }}
+          ip_node_1_iscsi0: {{ ip_node_1_iscsi0 }}
+          ip_node_1_iscsi1: {{ ip_node_1_iscsi1 }}
+          port_node_2_iscsi0_mac: {{ port_node_2_iscsi0_mac }}
+          port_node_2_iscsi1_mac: {{ port_node_2_iscsi1_mac }}
+          ip_node_2_iscsi0: {{ ip_node_2_iscsi0 }}
+          ip_node_2_iscsi1: {{ ip_node_2_iscsi1 }}
+        dest: "~/ansivars.yaml"
diff --git a/playbooks/setup-openstack-iscsi-multipath/vars.yaml b/playbooks/setup-openstack-iscsi-multipath/vars.yaml
new file mode 100644
index 0000000..10cc748
--- /dev/null
+++ b/playbooks/setup-openstack-iscsi-multipath/vars.yaml
@@ -0,0 +1,24 @@
+undercloud_client_node: "{{ hostvars['undercloud-client']['nodepool']['external_id'] }}"
+storpool_node: "{{ hostvars['lab-sp-a1']['nodepool']['external_id'] }}"
+openstack_node: "{{ hostvars['controller']['nodepool']['external_id'] }}"
+
+network_ip_iscsi0: "192.168.40.0/24"
+network_ip_iscsi1: "192.168.50.0/24"
+
+ip_node_1_iscsi0: "192.168.40.3"
+ip_node_1_iscsi1: "192.168.50.3"
+
+ip_node_2_iscsi0: "192.168.40.4"
+ip_node_2_iscsi1: "192.168.50.4"
+
+network_1: "{{ undercloud_client_node }}-network-iscsi-1"
+network_2: "{{ undercloud_client_node }}-network-iscsi-2"
+
+subnet_1: "{{ undercloud_client_node }}-subnet-iscsi-1"
+subnet_2: "{{ undercloud_client_node }}-subnet-iscsi-2"
+
+port_node_1_iscsi0: "{{ undercloud_client_node }}-port-node-1-iscsi-0"
+port_node_1_iscsi1: "{{ undercloud_client_node }}-port-node-1-iscsi-1"
+
+port_node_2_iscsi0: "{{ undercloud_client_node }}-port-node-2-iscsi-0"
+port_node_2_iscsi1: "{{ undercloud_client_node }}-port-node-2-iscsi-1"