{"id":16777322,"url":"https://github.com/githubixx/ansible-role-iscsi_target","last_synced_at":"2025-07-14T04:32:26.754Z","repository":{"id":45919383,"uuid":"432682784","full_name":"githubixx/ansible-role-iscsi_target","owner":"githubixx","description":"Ansible role to configure a iSCSI target","archived":false,"fork":false,"pushed_at":"2024-04-02T21:17:50.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-14T07:24:17.849Z","etag":null,"topics":["ansible","ansible-role","ansible-roles","block-storage","iscsi","iscsi-target","remote-storage","storage"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/githubixx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-28T10:37:11.000Z","updated_at":"2024-09-29T12:15:22.000Z","dependencies_parsed_at":"2023-01-18T05:15:14.260Z","dependency_job_id":null,"html_url":"https://github.com/githubixx/ansible-role-iscsi_target","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubixx%2Fansible-role-iscsi_target","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubixx%2Fansible-role-iscsi_target/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubixx%2Fansible-role-iscsi_target/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubixx%2Fansible-role-iscsi_target/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/githubixx","download_url":"https://codeload.github.com/githubixx/ansible-role-iscsi_target/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225950751,"owners_count":17550309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-role","ansible-roles","block-storage","iscsi","iscsi-target","remote-storage","storage"],"created_at":"2024-10-13T07:24:23.148Z","updated_at":"2024-11-22T19:00:00.074Z","avatar_url":"https://github.com/githubixx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ansible-role-iscsi_target\n=========================\n\nThis role configures a Linux-LIO based iSCSI target on a Linux host using `targetcli`. Additionally this role includes Python modules to interact with `targetcli` command which can be used separately for more advanced stuff. Modules implement checking, creating and deleting.\n\nTested with:\n\n- Ubuntu 20.04\n- Ubuntu 22.04\n- Archlinux\n\nDocumentation about LIO and Target can be found [here](https://linux-iscsi.org/wiki/Main_Page).\n\nRequirements\n------------\n\nThis role is not creating any disks/partitions/LVs. It is expected that they are already present on machine or created by some other role. For example: [githubixx.lvm](https://github.com/githubixx/ansible-role-lvm).\n\nChangelog\n---------\n\nsee [CHANGELOG](https://github.com/githubixx/ansible-role-iscsi_target/blob/master/CHANGELOG.md)\n\nRole Variables\n--------------\n\n```yaml\n# The iSCSI target(s) is/are configured via \"iscsi_targets\" nested variable.\n# A quite minimal setup looks like this example:\n#\n# iscsi_targets:\n#   - name: \"iqn.2021-11.blog.tauceti:{{ ansible_facts['nodename'] }}\"\n#     disks:\n#       - name: lun_node1\n#         path: /dev/vdb\n#         type: block\n#         lunid: 0\n#     initiators:\n#       - name: iqn.2021-07.blog.tauceti:node1\n#         authentication:\n#           userid: node1user\n#           password: node1pw\n#           userid_mutual: node1sharedkey\n#           password_mutual: node1sharedsecret\n#         mapped_luns:\n#           - mapped_lunid: 0\n#             lunid: 0\n#     portals:\n#       - ip: \"0.0.0.0\"\n#\n# For more information see README.\niscsi_targets: []\n```\n\nThe configuration above will create an iSCSI setup that will look like this (Output generated with `targetcli 'ls'`):\n\n```plain\n# o- / .................................................................................... [...]\n#   o- backstores ......................................................................... [...]\n#   | o- block ............................................................. [Storage Objects: 1]\n#   | | o- lun_node1 ................................... [/dev/vdb (1.0GiB) write-thru activated]\n#   | |   o- alua .............................................................. [ALUA Groups: 1]\n#   | |     o- default_tg_pt_gp .................................. [ALUA state: Active/optimized]\n#   | o- fileio ............................................................ [Storage Objects: 0]\n#   | o- pscsi ............................................................. [Storage Objects: 0]\n#   | o- ramdisk ........................................................... [Storage Objects: 0]\n#   o- iscsi ....................................................................... [Targets: 1]\n#   | o- iqn.2021-11.blog.tauceti:ubuntu .............................................. [TPGs: 1]\n#   |   o- tpg1 .......................................................... [no-gen-acls, no-auth]\n#   |     o- acls ..................................................................... [ACLs: 1]\n#   |     | o- iqn.2021-07.blog.tauceti:node1 .................................. [Mapped LUNs: 1]\n#   |     |   o- mapped_lun0 ........................................ [lun0 block/lun_node1 (rw)]\n#   |     o- luns ..................................................................... [LUNs: 1]\n#   |     | o- lun0 ............................. [block/lun_node1 (/dev/vdb) (default_tg_pt_gp)]\n#   |     o- portals ............................................................... [Portals: 1]\n#   |       o- 0.0.0.0:3260 ................................................................ [OK]\n#   o- loopback .................................................................... [Targets: 0]\n#   o- vhost ....................................................................... [Targets: 0]\n#   o- xen-pvscsi .................................................................. [Targets: 0]\n```\n\n`iscsi_targets.name` specifies the name of the iSCSI target (the iSCSI server so to say). As you can see above this entry will appear under the `iscsi` node in the `targetcli` output.\n\n`disks` create one or more block storage object(s). In this case it will be called `lun_node1`, the LUN ID will be `0`. The storage type will be a `block` device which in this case is located at `/dev/vdb`. This device can (and maybe even should) be a logical volume too of course.\n\n`initiators` defines all iSCSI initiators (the iSCSI clients - if you want - which wants to access the iSCSI target specified above). Every iSCSI initiator host (client) that wants to connect the iSCSI target (server) needs an entry here. The iSCSI initiator name normally can be found in `/etc/iscsi/initiatorname.iscsi` on every initiator (client) after `open-iscsi` package has been installed. The `authentication` object contains either only `userid` and `password` and optional also `userid_mutual` plus `password_mutual`.\n\n`mapped_luns` assigns mapped LUNs (logical units) to initiator. Normally `mapped_lunid` and `lunid` matches the same `lunid` in `iscsi_targets.disks`. But it also could be different.\n\n`portals` allows to specify the IP address the iSCSI target service should listen on. E.g. if `0.0.0.0` is specified then the service will listen on all interfaces on port `3260`. Of course Ansible facts can also be used e.g. `{{ ansible_default_ipv4.address | default(ansible_all_ipv4_addresses[0]) }}`.\n\n```yaml\n#######################################\n# Settings only relevant for Archlinux\n#######################################\n\n# \"targetcli-fb\" package is needed to configure iSCSI target. For Archlinux\n# this package needs to be installed from AUR. This requires an AUR install\n# helper like \"yay\", \"paru\", \"pacaur\", \"trizen\" or \"pikaur\". If such a helper\n# is already installed on the target host then there is no need to install it\n# via this role. In this case \"iscsi_archlinux_aur_helper\" needs to be\n# set to \"\" (empty sting) and this role will skip the installation of an AUR helper.\n# The install task picks one of the AUR helper mentioned above (in that order)\n# to install the iSCSI packages.\niscsi_archlinux_aur_helper: yay\n\n# While Ansible expects to SSH as root, makepkg or AUR helpers do not allow\n# executing operations as root, they fail with \"you cannot perform this\n# operation as root\". It is therefore recommended to have a user, which\n# is non-root but has no need for password. If \"iscsi_archlinux_aur_helper\"\n# variable is set it is assumed that the AUR helper user doesn't exist yet\n# so it will be created. The user will be part of the \"wheel\" group.\niscsi_archlinux_aur_helper_user: aur_builder\n```\n\nDependencies\n------------\n\nFor Archlinux [kewlfft.aur](https://galaxy.ansible.com/kewlfft/aur) Ansible collection is used to 1) install an AUR helper like [yay](https://github.com/Jguer/yay) and 2) to install [targetcli](https://aur.archlinux.org/packages/targetcli-fb/) utility from Archlinux User Repository.\n\nExample Playbook\n----------------\n\n```yaml\n- hosts: your-host\n  become: true\n  gather_facts: true\n  roles:\n    - githubixx.iscsi_target\n  vars:\n    iscsi_targets:\n      - name: \"iqn.2021-11.blog.tauceti:{{ ansible_facts['nodename'] }}\"\n        disks:\n          - name: lun_node1\n            path: /dev/vdb\n            type: block\n            lunid: 0\n        initiators:\n          - name: iqn.2021-07.blog.tauceti:node1\n            authentication:\n              userid: node1user\n              password: node1pw\n              userid_mutual: node1sharedkey\n              password_mutual: node1sharedsecret\n            mapped_luns:\n              - mapped_lunid: 0\n                lunid: 0\n        portals:\n          - ip: \"0.0.0.0\"\n```\n\nTesting\n-------\n\nThis role has a small test setup that is created using [Molecule](https://github.com/ansible-community/molecule), libvirt (vagrant-libvirt) and QEMU/KVM. Please see my blog post [Testing Ansible roles with Molecule, libvirt (vagrant-libvirt) and QEMU/KVM](https://www.tauceti.blog/posts/testing-ansible-roles-with-molecule-libvirt-vagrant-qemu-kvm/) how to setup. The test configuration is [here](https://github.com/githubixx/ansible-role-iscsi_target/tree/master/molecule/kvm).\n\nAfterwards molecule can be executed:\n\n```bash\nmolecule converge\n```\n\nThis will setup a few virtual machines (VM) with different supported Linux operating systems and installs `iscsi_target` role.\n\nTo run a few tests:\n\n```bash\nmolecule verify\n```\n\nTo clean up run\n\n```bash\nmolecule destroy\n```\n\nLicense\n-------\n\nMIT/BSD\n\nAuthor Information\n------------------\n\nOriginal author: Ondrej Famera [ansible.targetcli](https://github.com/OndrejHome/ansible.targetcli)  \nAdditional author: Ricardo Sanchez [ansible-role-iscsi_target](https://github.com/ricsanfre/ansible-role-iscsi_target)  \nAdditional author (this role version): [https://www.tauceti.blog](http://www.tauceti.blog)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubixx%2Fansible-role-iscsi_target","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithubixx%2Fansible-role-iscsi_target","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubixx%2Fansible-role-iscsi_target/lists"}