Vendor Galaxy Roles and Collections
This commit is contained in:
parent
c1e1897cda
commit
2aed20393f
8 changed files with 387444 additions and 2 deletions
19
ansible_collections/debops/debops/roles/iscsi/COPYRIGHT
Normal file
19
ansible_collections/debops/debops/roles/iscsi/COPYRIGHT
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
debops.iscsi - Manage Open-iSCSI configuration using Ansible
|
||||
|
||||
Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
This Ansible role is part of DebOps.
|
||||
|
||||
DebOps is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 3, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
DebOps is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DebOps. If not, see https://www.gnu.org/licenses/.
|
||||
196
ansible_collections/debops/debops/roles/iscsi/defaults/main.yml
Normal file
196
ansible_collections/debops/debops/roles/iscsi/defaults/main.yml
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
---
|
||||
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
|
||||
|
||||
# .. Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# .. Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# .. SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# .. _iscsi__ref_defaults:
|
||||
|
||||
# debops.iscsi default variables
|
||||
# ==============================
|
||||
|
||||
# .. contents:: Sections
|
||||
# :local:
|
||||
#
|
||||
# .. include:: ../../../../includes/global.rst
|
||||
|
||||
|
||||
# General configuration [[[
|
||||
# -------------------------
|
||||
|
||||
# .. envvar:: iscsi__packages [[[
|
||||
#
|
||||
# List of packages installed for iSCSI Initiator support.
|
||||
iscsi__packages: [ 'open-iscsi', 'lvm2' ]
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__interfaces [[[
|
||||
#
|
||||
# List of network interfaces configured for iSCSI connections. If not
|
||||
# specified, iSCSI targets will be discovered on all network interfaces.
|
||||
iscsi__interfaces: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__portals [[[
|
||||
#
|
||||
# List of FQDN hostnames or IP addresses of iSCSI Target hosts on which Ansible
|
||||
# will perform iSCSI discovery. Each discovered host will not be scanned again
|
||||
# automatically to not distrupt existing connections. The discovery state is
|
||||
# stored in Ansible local facts.
|
||||
iscsi__portals: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__targets [[[
|
||||
#
|
||||
# List of iSCSI Targets configured on a given host. Each iSCSI Target is
|
||||
# defined as a YAML dict. Check :ref:`iscsi__targets` for more details.
|
||||
iscsi__targets: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__logical_volumes [[[
|
||||
#
|
||||
# List of LVM Logical Volumes based on iSCSI storage. Each volume is defined as
|
||||
# a YAML dict. Check :ref:`iscsi__logical_volumes` for more details.
|
||||
iscsi__logical_volumes: []
|
||||
# ]]]
|
||||
# ]]]
|
||||
# iSCSI Qualified Name [[[
|
||||
# ------------------------
|
||||
|
||||
# .. envvar:: iscsi__iqn_date [[[
|
||||
#
|
||||
# Year and month when the Naming Authority of this iSCSI host was established.
|
||||
iscsi__iqn_date: '{{ ansible_date_time.year + "-" + ansible_date_time.month }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__iqn_authority [[[
|
||||
#
|
||||
# DNS domain name of the Naming Authority responsible for this iSCSI host.
|
||||
iscsi__iqn_authority: '{{ ansible_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__iqn [[[
|
||||
#
|
||||
# Base prefix for iSCSI Qualified Name of this iSCSI Initiator host, will be
|
||||
# saved in Ansible local facts to prevent changes related to the default date
|
||||
# field.
|
||||
iscsi__iqn: '{{ (ansible_local.iscsi.iqn
|
||||
if (ansible_local.iscsi.iqn | d())
|
||||
else ("iqn." + iscsi__iqn_date + "." +
|
||||
iscsi__iqn_authority.split(".")[::-1] | join("."))) }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__hostname [[[
|
||||
#
|
||||
# Hostname added to the IQN to create Initiator Name.
|
||||
iscsi__hostname: '{{ ansible_hostname }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__initiator_name [[[
|
||||
#
|
||||
# iSCSI initiator name of this host.
|
||||
iscsi__initiator_name: '{{ iscsi__iqn + ":" + iscsi__hostname }}'
|
||||
# ]]]
|
||||
# ]]]
|
||||
# Default Initiator configuration [[[
|
||||
# -----------------------------------
|
||||
|
||||
# .. envvar:: iscsi__enabled [[[
|
||||
#
|
||||
# Enable or disable ``iscsid`` daemon
|
||||
iscsi__enabled: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__node_startup [[[
|
||||
#
|
||||
# Specify if sessions should be started at boot (``automatic``) or not
|
||||
# (``manual``).
|
||||
iscsi__node_startup: 'automatic'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__discovery_auth [[[
|
||||
#
|
||||
# Enable or disable iSCSI discovery authentication.
|
||||
iscsi__discovery_auth: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__discovery_auth_username [[[
|
||||
#
|
||||
# Username used for iSCSI discovery authentication on all hosts, should be the
|
||||
# same for all iSCSI Targets to work automatically.
|
||||
iscsi__discovery_auth_username: '{{ lookup("password", secret + "/iscsi/credentials/discovery/username") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__discovery_auth_password [[[
|
||||
#
|
||||
# Password used for iSCSI discovery authentication on all hosts, should be the
|
||||
# same for all iSCSI Targets to work automatically.
|
||||
iscsi__discovery_auth_password: '{{ lookup("password", secret + "/iscsi/credentials/discovery/password") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__session_auth [[[
|
||||
#
|
||||
# Enable or disable iSCSI session authentication.
|
||||
iscsi__session_auth: True
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__session_auth_username [[[
|
||||
#
|
||||
# Username used for iSCSI session authentication on all hosts, should be the
|
||||
# same for all iSCSI Targets to work automatically. Can be overridden using
|
||||
# ``item.auth_username`` in target configuration.
|
||||
iscsi__session_auth_username: '{{ lookup("password", secret + "/iscsi/credentials/session/username") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__session_auth_password [[[
|
||||
#
|
||||
# Password used for iSCSI session authentication on all hosts, should be the
|
||||
# same for all iSCSI Targets to work automatically. Can be overridden using
|
||||
# ``item.auth_password`` in target configuration.
|
||||
iscsi__session_auth_password: '{{ lookup("password", secret + "/iscsi/credentials/session/password") }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__default_options [[[
|
||||
#
|
||||
# Dict with options set in ``/etc/iscsi/iscsid.conf``, passed to ``lineinfile``
|
||||
# Ansible module.
|
||||
iscsi__default_options:
|
||||
'node.startup': '{{ iscsi__node_startup }}'
|
||||
'discovery.sendtargets.auth.authmethod': '{{ "CHAP" if (iscsi__discovery_auth | d(False)) else "None" }}'
|
||||
'discovery.sendtargets.auth.username': '{{ iscsi__discovery_auth_username }}'
|
||||
'discovery.sendtargets.auth.password': '{{ iscsi__discovery_auth_password }}'
|
||||
'node.session.auth.authmethod': '{{ "CHAP" if (iscsi__session_auth | d(False)) else "None" }}'
|
||||
'node.session.auth.username': '{{ iscsi__session_auth_username }}'
|
||||
'node.session.auth.password': '{{ iscsi__session_auth_password }}'
|
||||
# ]]]
|
||||
# ]]]
|
||||
# Filesystem and mount configuration [[[
|
||||
# --------------------------------------
|
||||
|
||||
# .. envvar:: iscsi__default_fs_type [[[
|
||||
#
|
||||
# Default filesystem created on block devices if none is specified.
|
||||
iscsi__default_fs_type: 'ext4'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: iscsi__default_mount_options [[[
|
||||
#
|
||||
# Default mount options added in ``/etc/fstab`` to all iSCSI-based filesystems,
|
||||
# if none are specified.
|
||||
iscsi__default_mount_options: 'defaults,_netdev'
|
||||
# ]]]
|
||||
# ]]]
|
||||
# Configuration of other Ansible roles [[[
|
||||
# ----------------------------------------
|
||||
|
||||
# .. envvar:: iscsi__unattended_upgrades__dependent_blacklist [[[
|
||||
#
|
||||
# Configuration of the ``debops.unattended_upgrades`` role.
|
||||
iscsi__unattended_upgrades__dependent_blacklist:
|
||||
|
||||
# Prevent automatic upgrades of the ``open-iscsi`` package. The upgrade
|
||||
# results in a restart of the service and all existing connections are lost.
|
||||
- 'open-iscsi'
|
||||
# ]]]
|
||||
# ]]]
|
||||
31
ansible_collections/debops/debops/roles/iscsi/meta/main.yml
Normal file
31
ansible_collections/debops/debops/roles/iscsi/meta/main.yml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2022 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Ensure that custom Ansible plugins and modules included in the main DebOps
|
||||
# collection are available to roles in other collections.
|
||||
collections: [ 'debops.debops' ]
|
||||
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
|
||||
author: 'Maciej Delmanowski'
|
||||
description: 'Manage iSCSI Initiator configuration'
|
||||
company: 'DebOps'
|
||||
license: 'GPL-3.0-only'
|
||||
min_ansible_version: '1.8.0'
|
||||
|
||||
platforms:
|
||||
|
||||
- name: 'Ubuntu'
|
||||
versions: [ 'all' ]
|
||||
|
||||
- name: 'Debian'
|
||||
versions: [ 'all' ]
|
||||
|
||||
galaxy_tags:
|
||||
- iscsi
|
||||
- storage
|
||||
- networking
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
108
ansible_collections/debops/debops/roles/iscsi/tasks/main.yml
Normal file
108
ansible_collections/debops/debops/roles/iscsi/tasks/main.yml
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
---
|
||||
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
- name: Import custom Ansible plugins
|
||||
ansible.builtin.import_role:
|
||||
name: 'ansible_plugins'
|
||||
|
||||
- name: Import DebOps global handlers
|
||||
ansible.builtin.import_role:
|
||||
name: 'global_handlers'
|
||||
|
||||
- name: Import DebOps secret role
|
||||
ansible.builtin.import_role:
|
||||
name: 'secret'
|
||||
|
||||
- name: DebOps pre_tasks hook
|
||||
ansible.builtin.include_tasks: "{{ lookup('debops.debops.task_src', 'iscsi/pre_main.yml') }}"
|
||||
|
||||
- name: Install required iSCSI packages
|
||||
ansible.builtin.package:
|
||||
name: '{{ q("flattened", iscsi__packages) }}'
|
||||
state: 'present'
|
||||
register: iscsi__register_packages
|
||||
until: iscsi__register_packages is succeeded
|
||||
|
||||
- name: Configure iSCSI Initiator IQN
|
||||
ansible.builtin.lineinfile:
|
||||
dest: '/etc/iscsi/initiatorname.iscsi'
|
||||
regexp: '^InitiatorName=iqn'
|
||||
line: 'InitiatorName={{ iscsi__initiator_name }}'
|
||||
state: 'present'
|
||||
mode: '0600'
|
||||
register: iscsi__register_initiatorname
|
||||
|
||||
- name: Configure iSCSI discovery authentication
|
||||
ansible.builtin.lineinfile:
|
||||
dest: '/etc/iscsi/iscsid.conf'
|
||||
regexp: '{{ (item.key | replace(".", "\.")) + "\s=\s" }}'
|
||||
line: '{{ item.key + " = " + item.value }}'
|
||||
state: 'present'
|
||||
mode: '0600'
|
||||
with_dict: '{{ iscsi__default_options }}'
|
||||
when: item | d(False) and item.value
|
||||
no_log: '{{ debops__no_log | d(True) }}'
|
||||
|
||||
- name: Restart iSCSI service if initial configuration changed
|
||||
ansible.builtin.service: # noqa no-handler
|
||||
name: 'open-iscsi'
|
||||
state: 'restarted'
|
||||
when: iscsi__enabled | d() and iscsi__register_initiatorname | d() and iscsi__register_initiatorname is changed
|
||||
|
||||
- name: Generate iSCSI interface configuration
|
||||
ansible.builtin.shell: iscsiadm -m iface -I {{ item }} -o new ;
|
||||
iscsiadm -m iface -I {{ item }} --op=update -n iface.net_ifacename -v {{ item }}
|
||||
args:
|
||||
creates: '/etc/iscsi/ifaces/{{ item }}'
|
||||
with_items: '{{ iscsi__interfaces }}'
|
||||
when: (iscsi__interfaces | d(False) and item in ansible_interfaces)
|
||||
|
||||
- name: Discover iSCSI targets on portals
|
||||
community.general.open_iscsi:
|
||||
discover: True
|
||||
portal: '{{ item }}'
|
||||
with_items: '{{ iscsi__portals }}'
|
||||
register: iscsi__register_discover_targets
|
||||
when: iscsi__portals | d(False) and
|
||||
item not in ansible_local.iscsi.discovered_portals | d([])
|
||||
|
||||
- name: Log in to specified iSCSI targets
|
||||
community.general.open_iscsi:
|
||||
target: '{{ item.target }}'
|
||||
login: '{{ False if (not item.login | d(True)) else True }}'
|
||||
node_auth: '{{ "CHAP" if (item.auth | d(False)) else omit }}'
|
||||
node_user: '{{ item.auth_username if (item.auth | d(False)) else omit }}'
|
||||
node_pass: '{{ item.auth_password if (item.auth | d(False)) else omit }}'
|
||||
auto_node_startup: '{{ False if (not item.auto | d(True)) else True }}'
|
||||
with_items: '{{ iscsi__targets }}'
|
||||
register: iscsi__register_targets
|
||||
when: iscsi__targets | d()
|
||||
no_log: '{{ debops__no_log | d(True) }}'
|
||||
|
||||
- name: Make sure that local facts directory exists
|
||||
ansible.builtin.file:
|
||||
dest: '/etc/ansible/facts.d'
|
||||
state: 'directory'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0755'
|
||||
|
||||
- name: Save iSCSI facts
|
||||
ansible.builtin.template:
|
||||
src: 'etc/ansible/facts.d/iscsi.fact.j2'
|
||||
dest: '/etc/ansible/facts.d/iscsi.fact'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
tags: [ 'meta::facts' ]
|
||||
|
||||
- name: Manage LVM
|
||||
ansible.builtin.include_tasks: manage_lvm.yml
|
||||
when: (((ansible_system_capabilities_enforced | d()) | bool and
|
||||
"cap_sys_admin" in ansible_system_capabilities) or
|
||||
not (ansible_system_capabilities_enforced | d(True)) | bool)
|
||||
|
||||
- name: DebOps post_tasks hook
|
||||
ansible.builtin.include_tasks: "{{ lookup('debops.debops.task_src', 'iscsi/post_main.yml') }}"
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
---
|
||||
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
- name: Unmount filesystems if requested
|
||||
ansible.posix.mount:
|
||||
name: '{{ item.mount }}'
|
||||
src: '{{ "/dev/mapper/" + item.vg + "-" + item.lv }}'
|
||||
fstype: '{{ item.fs_type | d(iscsi__default_fs_type) }}'
|
||||
state: 'absent'
|
||||
with_items: '{{ iscsi__logical_volumes }}'
|
||||
when: iscsi__logical_volumes | d(False) and
|
||||
item.vg | d() and item.lv | d() and item.size | d() and
|
||||
item.mount | d(False) and
|
||||
(item.state is defined and item.state == 'absent')
|
||||
|
||||
- name: Remove Logical Volumes if requested
|
||||
community.general.lvol:
|
||||
vg: '{{ item.vg }}'
|
||||
lv: '{{ item.lv }}'
|
||||
size: '{{ item.size }}'
|
||||
force: '{{ item.force | d(omit) }}'
|
||||
state: 'absent'
|
||||
with_items: '{{ iscsi__logical_volumes }}'
|
||||
when: iscsi__logical_volumes | d(False) and
|
||||
item.vg | d() and item.lv | d() and item.size | d() and
|
||||
item.state | d() and item.state == 'absent'
|
||||
|
||||
- name: Manage LVM Volume Groups
|
||||
community.general.lvg:
|
||||
vg: '{{ item.item.lvm_vg }}'
|
||||
pvs: '{{ item.devicenodes | join(",") }}'
|
||||
state: '{{ item.item.lvm_state | d("present") }}'
|
||||
pesize: '{{ item.item.lvm_pesize | d(omit) }}'
|
||||
force: '{{ item.item.lvm_force | d(omit) }}'
|
||||
vg_options: '{{ item.item.lvm_options | d(omit) }}'
|
||||
with_items: '{{ iscsi__register_targets.results }}'
|
||||
when: iscsi__register_targets | d(False) and iscsi__register_targets.results | d() and
|
||||
item.devicenodes | d() and item.item.lvm_vg | d()
|
||||
|
||||
- name: Manage LVM Logical Volumes
|
||||
community.general.lvol:
|
||||
vg: '{{ item.vg }}'
|
||||
lv: '{{ item.lv }}'
|
||||
size: '{{ item.size }}'
|
||||
force: '{{ item.force | d(omit) }}'
|
||||
state: 'present'
|
||||
with_items: '{{ iscsi__logical_volumes }}'
|
||||
when: iscsi__logical_volumes | d(False) and
|
||||
item.vg | d() and item.lv | d() and item.size | d() and
|
||||
(item.state is undefined or item.state != 'absent')
|
||||
|
||||
- name: Manage filesystems
|
||||
community.general.filesystem:
|
||||
dev: '{{ "/dev/mapper/" + item.vg + "-" + item.lv }}'
|
||||
fstype: '{{ item.fs_type | d(iscsi__default_fs_type) }}'
|
||||
force: '{{ item.fs_force | d(omit) }}'
|
||||
opts: '{{ item.fs_opts | d(omit) }}'
|
||||
with_items: '{{ iscsi__logical_volumes }}'
|
||||
when: iscsi__logical_volumes | d(False) and
|
||||
item.vg | d() and item.lv | d() and item.size | d() and
|
||||
(item.state is undefined or item.state != 'absent') and
|
||||
((item.mount | d() and (item.fs is undefined or item.fs | d()) or
|
||||
item.fs | d()))
|
||||
|
||||
- name: Manage mount points
|
||||
ansible.posix.mount:
|
||||
name: '{{ item.mount }}'
|
||||
src: '{{ "/dev/mapper/" + item.vg + "-" + item.lv }}'
|
||||
fstype: '{{ item.fs_type | d(iscsi__default_fs_type) }}'
|
||||
opts: '{{ item.mount_opts | d(iscsi__default_mount_options) }}'
|
||||
state: '{{ item.mount_state | d("mounted") }}'
|
||||
dump: '{{ item.mount_dump | d(omit) }}'
|
||||
passno: '{{ item.mount_passno | d(omit) }}'
|
||||
fstab: '{{ item.mount_fstab | d(omit) }}'
|
||||
with_items: '{{ iscsi__logical_volumes }}'
|
||||
when: iscsi__logical_volumes | d(False) and
|
||||
item.vg | d() and item.lv | d() and item.size | d() and
|
||||
item.mount | d(False) and
|
||||
(item.state is undefined or item.state != 'absent')
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
{% set iscsi__tpl_iqn = ansible_local.iscsi.iqn | d(iscsi__iqn) %}
|
||||
{% set iscsi__tpl_discovered_portals = [] %}
|
||||
{% if ansible_local.iscsi.discovered_portals | d() %}
|
||||
{% set iscsi__tpl_discovered_portals = ansible_local.iscsi.discovered_portals %}
|
||||
{% endif %}
|
||||
{% if iscsi__register_discover_targets | d() and iscsi__register_discover_targets.results | d() %}
|
||||
{% for element in iscsi__register_discover_targets.results %}
|
||||
{% if "item" in element.keys() %}
|
||||
{% set _ = iscsi__tpl_discovered_portals.append(element.item) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{
|
||||
"iqn":"{{ iscsi__tpl_iqn }}",
|
||||
"discovered_portals": {{ iscsi__tpl_discovered_portals | unique | to_nice_json }}
|
||||
}
|
||||
Loading…
Reference in a new issue