initiator.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ---
  2. - name: Ensure /data_prod is mounted from serverc iSCSI target
  3. hosts: initiators
  4. become: true
  5. tasks:
  6. - name: the iSCSI initiator software is installed
  7. yum:
  8. name: iscsi-initiator-utils
  9. state: present
  10. - name: the IQN is set for the initiator
  11. copy:
  12. dest: /etc/iscsi/initiatorname.iscsi
  13. content: "InitiatorName=iqn.2014-06.com.example:{{ ansible_facts['hostname'] }}\n"
  14. mode: '644'
  15. owner: root
  16. group: root
  17. notify: restart iscsid
  18. # Forces the handler to run so that the iscsid service is restarted
  19. # and is aware of the new initiator IQN
  20. - meta: flush_handlers
  21. - name: the iSCSI target is discovered and available
  22. open_iscsi:
  23. portal: 172.25.250.12
  24. port: '3260'
  25. target: iqn.2014-06.com.example:rack1
  26. discover: yes
  27. login: yes
  28. register: target
  29. - name: display the discovered devices
  30. debug:
  31. msg: The new device is {{ target['devicenodes'][0] }}
  32. - name: the new device is formatted and mounted under /data_prod
  33. include_role:
  34. name: rhel-system-roles.storage
  35. vars:
  36. storage_volumes:
  37. - name: devdata
  38. state: present
  39. type: disk
  40. disks:
  41. - "{{ target['devicenodes'][0] }}"
  42. mount_point: /data_prod
  43. fs_type: ext4
  44. mount_options: '_netdev'
  45. handlers:
  46. - name: restart iscsid
  47. service:
  48. name: iscsid
  49. state: restarted