target.yml 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ---
  2. - name: Ensure the iSCSI target is prepared
  3. hosts: serverc.lab.example.com
  4. become: true
  5. tasks:
  6. - name: the target command line tool is installed
  7. yum:
  8. name: targetcli
  9. state: present
  10. - name: the target service is started and enabled
  11. service:
  12. name: target
  13. state: started
  14. enabled: yes
  15. - name: the firewall is opened for iSCSI
  16. firewalld:
  17. service: iscsi-target
  18. state: enabled
  19. immediate: yes
  20. permanent: yes
  21. - name: check if the target already exists
  22. command: targetcli ls /iscsi/iqn.2014-06.com.example:rack1
  23. register: cmdout
  24. ignore_errors: true
  25. changed_when: false
  26. - name: the iSCSI target is prepared
  27. shell: |
  28. targetcli /backstores/block create rack1.disk1 /dev/vdb1
  29. targetcli /iscsi create iqn.2014-06.com.example:rack1
  30. targetcli /iscsi/iqn.2014-06.com.example:rack1/tpg1/acls create iqn.2014-06.com.example:servera
  31. targetcli /iscsi/iqn.2014-06.com.example:rack1/tpg1/luns create /backstores/block/rack1.disk1
  32. targetcli /iscsi/iqn.2014-06.com.example:rack1/tpg1/portals delete 0.0.0.0 3260
  33. targetcli /iscsi/iqn.2014-06.com.example:rack1/tpg1/portals create 172.25.250.12 3260
  34. targetcli saveconfig
  35. when: cmdout.rc != 0