pulitux пре 2 година
родитељ
комит
969b382bb6

+ 3 - 0
iscsi-automation.03-06-09:15:49/ansible.cfg

@@ -0,0 +1,3 @@
+[defaults]
+inventory=inventory
+remote_user=devops

+ 45 - 0
iscsi-automation.03-06-09:15:49/cleanup.yml

@@ -0,0 +1,45 @@
+---
+- name: Ensure /data is cleaned up
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the device does not contain a file system
+      include_role:
+        name: rhel-system-roles.storage
+      vars:
+        storage_volumes:
+          - name: devdata
+            state: absent
+            type: disk
+            disks:
+              - "{{ item.key }}"
+            mount_point: /data
+            fs_type: xfs
+            mount_options: '_netdev'
+      loop: "{{ ansible_facts['devices'] | dict2items }}"
+      when: item.value['model'] == "serverd.disk1"
+
+    - name: the iSCSI target is disconnected
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:serverd
+        discover: no
+        login: no
+        auto_node_startup: no
+      ignore_errors: yes
+
+    - name: the iscsi-initiator-utils package is not installed
+      yum:
+        name: iscsi-initiator-utils
+        state: absent
+
+    - name: the iSCSI configuration files are not present
+      file:
+        path: "{{ item }}"
+        state: absent
+      loop:
+        - /etc/iscsi
+        - /var/lib/iscsi
+        - /var/lock/iscsi

+ 2 - 0
iscsi-automation.03-06-09:15:49/inventory

@@ -0,0 +1,2 @@
+[initiators]
+servera.lab.example.com

+ 59 - 0
iscsi-automation.03-06-09:15:49/playbook.yml

@@ -0,0 +1,59 @@
+---
+- name: Ensure /data is mounted from serverd iSCSI target
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the iscsi-initiator-utils package is installed
+      yum:
+        name: iscsi-initiator-utils
+        state: present
+
+    - name: the IQN is set for the initiator
+      template:
+        src: templates/initiatorname.iscsi.j2
+        dest: /etc/iscsi/initiatorname.iscsi
+        owner: root
+        group: root
+        mode: 644
+      notify: restart iscsid
+
+    # Forces the handler to run so that the iscsid service is restarted
+    # and is aware of the new initiator IQN
+    - meta: flush_handlers
+
+    - name: the iSCSI target is discovered and available
+      open_iscsi:
+        portal: 172.25.250.13
+        port: 3260
+        target: iqn.2014-06.com.example:serverd
+        discover: yes
+        login: yes
+      register: target
+
+    - name: display the discovered devices
+      debug:
+        var: target['devicenodes']
+
+    - name: the new device is formatted and mounted under /data
+      include_role:
+        name: rhel-system-roles.storage
+      vars:
+        storage_volumes:
+          - name: devdata
+            state: present
+            type: disk
+            disks:
+              - "{{ target['devicenodes'][0] }}"
+            mount_point: /data
+            fs_type: xfs
+            mount_points: '_netdev'
+            #FIXME: see /usr/share/doc/rhel-system-roles/storage/README.md
+            #       Set the mount point to /data, the file system type to xfs,
+            #       and add the _netdev mount option.
+
+  handlers:
+    - name: restart iscsid
+      service:
+        name: iscsid
+        state: restarted

+ 56 - 0
iscsi-automation.03-06-09:15:49/solution/playbook.yml

@@ -0,0 +1,56 @@
+---
+- name: Ensure /data is mounted from serverd iSCSI target
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the iscsi-initiator-utils package is installed
+      yum:
+        name: iscsi-initiator-utils
+        state: present
+
+    - name: the IQN is set for the initiator
+      template:
+        dest: /etc/iscsi/initiatorname.iscsi
+        src: templates/initiatorname.iscsi.j2
+        mode: '644'
+        owner: root
+        group: root
+      notify: restart iscsid
+
+    # Forces the handler to run so that the iscsid service is restarted
+    # and is aware of the new initiator IQN
+    - meta: flush_handlers
+
+    - name: the iSCSI target is discovered and available
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:serverd
+        discover: yes
+        login: yes
+      register: target
+
+    - name: display the discovered devices
+      debug:
+        var: target['devicenodes']
+
+    - name: the new device is formatted and mounted under /data
+      include_role:
+        name: rhel-system-roles.storage
+      vars:
+        storage_volumes:
+          - name: devdata
+            state: present
+            type: disk
+            disks:
+              - "{{ target['devicenodes'][0] }}"
+            mount_point: /data
+            fs_type: xfs
+            mount_options: '_netdev'
+
+  handlers:
+    - name: restart iscsid
+      service:
+        name: iscsid
+        state: restarted

+ 1 - 0
iscsi-automation.03-06-09:15:49/templates/initiatorname.iscsi.j2

@@ -0,0 +1 @@
+InitiatorName=iqn.2014-06.com.example:{{ ansible_facts['hostname'] }}

+ 19 - 0
iscsi-automation.03-06-09:15:49/unmount.yml

@@ -0,0 +1,19 @@
+---
+- name: Ensure /data is not mounted
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the new device is not mounted
+      mount:
+        path: /data
+        state: absent
+
+    - name: the iSCSI target is disconnected
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:serverd
+        discover: no
+        login: no
+        auto_node_startup: no

+ 6 - 15
iscsi-automation/playbook.yml

@@ -10,12 +10,8 @@
         state: present
 
     - name: the IQN is set for the initiator
-      template:
-        src: templates/initiatorname.iscsi.j2
-        dest: /etc/iscsi/initiatorname.iscsi
-        owner: root
-        group: root
-        mode: 644
+      #FIXME: see "ansible-doc template" for some examples.
+      #       Deploy the templates/initiatorname.iscsi.j2 template file
       notify: restart iscsid
 
     # Forces the handler to run so that the iscsid service is restarted
@@ -23,12 +19,10 @@
     - meta: flush_handlers
 
     - name: the iSCSI target is discovered and available
-      open_iscsi:
-        portal: 172.25.250.13
-        port: 3260
-        target: iqn.2014-06.com.example:serverd
-        discover: yes
-        login: yes
+      #FIXME: see "ansible-doc open_iscsi" for some examples.
+      #       The target is iqn.2014-06.com.example:serverd and the portal is
+      #       172.25.250.13 (port 3260)
+      #       Make sure that the target is automatically connected at startup.
       register: target
 
     - name: display the discovered devices
@@ -45,9 +39,6 @@
             type: disk
             disks:
               - "{{ target['devicenodes'][0] }}"
-            mount_point: /data
-            fs_type: xfs
-            mount_points: '_netdev'
             #FIXME: see /usr/share/doc/rhel-system-roles/storage/README.md
             #       Set the mount point to /data, the file system type to xfs,
             #       and add the _netdev mount option.

+ 34 - 0
iscsi-review/.solution/cleanup.yml

@@ -0,0 +1,34 @@
+---
+- name: Ensure /iscsidisk is not mounted
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the /iscsidisk file system is unmounted
+      mount:
+        path: /iscsidisk
+        state: absent
+
+    - name: the iSCSI target is disconnected
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:store1
+        discover: no
+        login: no
+        auto_node_startup: no
+      ignore_errors: yes
+
+    - name: the iscsi-initiator-utils package is not installed
+      yum:
+        name: iscsi-initiator-utils
+        state: absent
+
+    - name: the iSCSI configuration files are not present
+      file:
+        path: "{{ item }}"
+        state: absent
+      loop:
+        - /etc/iscsi
+        - /var/lib/iscsi
+        - /var/lock/iscsi

+ 56 - 0
iscsi-review/.solution/playbook.yml

@@ -0,0 +1,56 @@
+---
+- name: Ensure /iscsidisk is mounted from serverd iSCSI target
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the iscsi-initiator-utils package is installed
+      yum:
+        name: iscsi-initiator-utils
+        state: present
+
+    - name: the IQN is set for the initiator
+      copy:
+        dest: /etc/iscsi/initiatorname.iscsi
+        content: "InitiatorName=iqn.2014-06.com.example:{{ ansible_facts['hostname'] }}\n"
+        mode: '644'
+        owner: root
+        group: root
+      notify: restart iscsid
+
+    # Forces the handler to run so that the iscsid service is restarted
+    # and is aware of the new initiator IQN
+    - meta: flush_handlers
+
+    - name: the iSCSI target is discovered and available
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:store1
+        discover: yes
+        login: yes
+      register: target
+
+    - name: display the discovered devices
+      debug:
+        msg: The new device is {{ target['devicenodes'][0] }}
+
+    - name: the new device is formatted and mounted under /iscsidisk
+      include_role:
+        name: rhel-system-roles.storage
+      vars:
+        storage_volumes:
+          - name: devdata
+            state: present
+            type: disk
+            disks:
+              - "{{ target['devicenodes'][0] }}"
+            mount_point: /iscsidisk
+            fs_type: ext4
+            mount_options: '_netdev'
+
+  handlers:
+    - name: restart iscsid
+      service:
+        name: iscsid
+        state: restarted

+ 3 - 0
iscsi-review/ansible.cfg

@@ -0,0 +1,3 @@
+[defaults]
+inventory=inventory
+remote_user=devops

+ 2 - 0
iscsi-review/inventory

@@ -0,0 +1,2 @@
+[initiators]
+servera.lab.example.com

+ 54 - 0
iscsi-review/playbook.yml

@@ -0,0 +1,54 @@
+---
+- name: Ensure /iscsidisk is mounted from serverd iSCSI target
+  hosts: initiators
+  become: true
+
+  tasks:
+    - name: the iSCSI initiator software installed
+      yum:
+        name: iscsi-initiator-utils
+        state: present
+
+    - name: the IQN is set for the initiator
+      template: 
+        src: templates/initiatorname.iscsi.j2      
+        dest: /etc/iscsi/initiatorname.iscsi
+        owner: root
+        group: root
+        mode: 0640
+      notify: restart iscsid
+
+    - meta: flush_handlers
+
+    - name: the iSCSI target is discovered and available
+      open_iscsi:
+        portal: 172.25.250.13
+        port: '3260'
+        target: iqn.2014-06.com.example:store1
+        discover: yes
+        login: yes
+      register: target
+
+    - name: display the discovered devices
+      debug:
+        msg: "The new device is {{ target['devicenodes'][0] }}"
+
+    - name: the new device is formatted and mounted under /iscsidisk
+      include_role:
+        name: rhel-system-roles.storage
+      vars:
+        storage_volumes:
+          - name: devdata
+            state: present
+            type: disk
+            disks: 
+              - "{{ target['devicenodes'][0] }}"
+            mount_point: /iscsidisk
+            fs_type: ext4
+            mount_options: '_netdev'
+
+  handlers:
+    - name: restart iscsid
+      service:
+        name: iscsid
+        state: restarted

+ 1 - 0
iscsi-review/templates/initiatorname.iscsi.j2

@@ -0,0 +1 @@
+InitiatorName=iqn.2014-06.com.example:{{ ansible_facts['hostname'] }}