ricsanfre.iscsi_target

Ansible Role: iSCSI Target

This role sets up an iSCSI target on a Linux machine using targetcli, which is based on Linux-LIO.

Additionally, it includes custom Python modules to work with the targetcli command. These modules allow you to check, create, and delete targets.

NOTE: You can find documentation about LIO and Target here.

Requirements

This role does not create any disks, partitions, or logical volumes (LVs). It is assumed that these already exist on the machine or are created by another role. For example: ricsanfre.storage.

Role Variables

To configure the iSCSI target, you'll need to use a specific nested variable structure that defines the desired configuration.

iscsi_targets:
  - name: "iqn.2021-07.com.ricsanfre:target_server"
    disks:
      - name: lun_node1
        path: /dev/vg_iscsi/vg_iscsi_lv_node1
        type: block
        lunid: 0
      - name: lun_node2
        path: /dev/vg_iscsi/vg_iscsi_lv_node2
        type: block
        lunid: 1
      - name: lun_node3
        path: /dev/vg_iscsi/vg_iscsi_lv_node3
        type: block
        lunid: 2
      - name: lun_node4
        path: /dev/vg_iscsi/vg_iscsi_lv_node4
        type: block
        lunid: 3
    initiators:
      - name: iqn.2021-07.com.ricsanfre:node1
        authentication:
          userid: node1
          password: passwd1
          userid_mutual: sharedkey
          password_mutual: sharedsecret
        mapped_luns:
          - mapped_lunid: 0
            lunid: 0
          - mapped_lunid: 1
            lunid: 2
      - name: iqn.2021-07.com.ricsanfre:node2
        authentication:
          userid: node2
          password: passwd2
        mapped_luns:
          - mapped_lunid: 0
            lunid: 1
          - mapped_lunid: 1
            lunid: 3
            write_protect: 1
    portals:
      - ip: 192.168.1.45
        port: 5555
      - ip: 192.168.2.10

Dependencies

None.

Example Playbook

This example uses the ricsanfre.storage role to create the logical volumes needed for the iSCSI target configuration.

- hosts: all
  become: true
  gather_facts: true
  vars:
    storage_partitions:
      - name: /dev/vdb
        number: 1
        flags:
          - lvm
        part_end: 1GB
    storage_volumegroups:
      - name: vg_iscsi
        devices:
          - /dev/vdb1
    storage_volumes:
      - name: vg_iscsi_lv_node1
        vg: vg_iscsi
        size: 100
      - name: vg_iscsi_lv_node2
        vg: vg_iscsi
        size: 100
      - name: vg_iscsi_lv_node3
        vg: vg_iscsi
        size: 100
      - name: vg_iscsi_lv_node4
        vg: vg_iscsi
        size: 100
    iscsi_targets:
      - name: "iqn.2021-07.com.ricsanfre:{{ ansible_facts['nodename'] }}"
        disks:
          - name: lun_node1
            path: /dev/vg_iscsi/vg_iscsi_lv_node1
            type: block
            lunid: 0
          - name: lun_node2
            path: /dev/vg_iscsi/vg_iscsi_lv_node2
            type: block
            lunid: 1
          - name: lun_node3
            path: /dev/vg_iscsi/vg_iscsi_lv_node3
            type: block
            lunid: 2
          - name: lun_node4
            path: /dev/vg_iscsi/vg_iscsi_lv_node4
            type: block
            lunid: 3
        initiators:
          - name: iqn.2021-07.com.ricsanfre:node1
            authentication:
              userid: node1
              password: passwd1
            mapped_luns:
              - mapped_lunid: 0
                lunid: 0
              - mapped_lunid: 1
                lunid: 2
          - name: iqn.2021-07.com.ricsanfre:node2
            authentication:
              userid: node2
              password: passwd2
            mapped_luns:
              - mapped_lunid: 0
                lunid: 1
              - mapped_lunid: 1
                lunid: 3
                write_protect: 1
        portals:
          - ip: "{{ ansible_default_ipv4.address | default(ansible_all_ipv4_addresses[0]) }}"

  roles:
    - ricsanfre.storage
    - ricsanfre.iscsi_target

License

MIT/BSD

Author Information

Created by Ricardo Sanchez (ricsanfre), based on the development by Ondrej Famera on targetcli.

Informazioni sul progetto

Configure iSCSI Target role

Installa
ansible-galaxy install ricsanfre.iscsi_target
Licenza
mit
Download
8k
Proprietario
Telecom engineer.