Vendor Galaxy Roles and Collections
Some checks failed
/ Ansible Lint (push) Failing after 5m45s
/ Ansible Lint (pull_request) Failing after 4m59s

This commit is contained in:
Stefan Bethke 2026-02-06 22:07:16 +01:00
commit 2aed20393f
3553 changed files with 387444 additions and 2 deletions

View file

@ -0,0 +1,20 @@
debops.libvirt - Manage libvirt client configuration
Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
Copyright (C) 2015-2016 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/.

View file

@ -0,0 +1,186 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# .. Copyright (C) 2015-2016 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-only
# .. _libvirt__ref_defaults:
# debops.libvirt default variables
# ================================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# libvirt system configuration [[[
# --------------------------------
# .. envvar:: libvirt__base_packages [[[
#
# List of base packages to install with Libvirt.
libvirt__base_packages:
- [ 'gawk', 'netcat-openbsd', 'virtinst' ]
- '{{ [] if (ansible_distribution_release in ["bullseye"])
else "virt-top" }}'
- '{{ "virt-goodies"
if (ansible_local | d() and ansible_local.python | d() and
(ansible_local.python.installed2 | d()) | bool)
else [] }}'
# ]]]
# .. envvar:: libvirt__packages [[[
#
# List of ``libvirt`` packages which will be installed on all distribution
# releases, unless overridden.
libvirt__packages: [ 'libvirt-clients' ]
# ]]]
# .. envvar:: libvirt__packages_map [[[
#
# Override list of base packages for specific distribution releases.
libvirt__packages_map:
'trusty': [ 'libvirt-bin' ]
'xenial': [ 'libvirt-bin' ]
# ]]]
# .. envvar:: libvirt__group_map [[[
#
# Mapping of default UNIX access group on different distributions.
libvirt__group_map:
'Debian': 'libvirt'
'Ubuntu': 'libvirtd'
# ]]]
# ]]]
# libvirt connection URI [[[
# --------------------------
# .. envvar:: libvirt__default_uri [[[
#
# Default connection URI (connect to :program:`libvirtd` instance on ``localhost``).
libvirt__default_uri: 'qemu:///system'
# ]]]
# .. envvar:: libvirt__connections [[[
#
# Dict with connections configured in ``~/.config/libvirt/libvirt.conf``. See
# :ref:`libvirt__connections` for more details.
libvirt__connections:
'localhost': '{{ libvirt__default_uri }}'
# ]]]
# .. envvar:: libvirt__uri [[[
#
# Name of the connection from ``libvirt__connections`` dict used by default by
# ``libvirt`` clients on the admin account.
libvirt__uri: 'localhost'
# ]]]
# ]]]
# libvirt network configuration [[[
# ---------------------------------
# .. envvar:: libvirt__networks [[[
#
# List of network definitions in ``libvirt``, specified as YAML dicts. See
# :ref:`libvirt__networks` for more details.
libvirt__networks:
- '{{ libvirt__networks_default }}'
- '{{ libvirt__networks_virt_nat }}'
# ]]]
# .. envvar:: libvirt__networks_default [[[
#
# Default DebOps network configuration for ``libvirt``. NAT that comes with
# ``libvirt`` by default is inactive, bridges configured by ``debops.ifupdown``
# are automatically added to ``libvirt`` if they are present.
libvirt__networks_default:
# Internal network configured by ``libvirt`` by default.
- name: 'default'
type: 'dnsmasq'
bridge: 'virbr0'
addresses: [ '192.168.122.1/24' ]
dhcp_range: [ '2', '-2' ]
state: 'absent'
- name: 'external'
type: 'bridge'
bridge: 'br0'
interface_present: 'br0'
- name: 'internal'
type: 'bridge'
bridge: 'br1'
interface_present: 'br1'
- name: 'nat'
type: 'bridge'
bridge: 'br2'
interface_present: 'br2'
# ]]]
# .. envvar:: libvirt__networks_virt_nat [[[
#
# An internal network behind NAT. This is a replacement configuration for
# ``default`` ``libvirt`` network, since you cannot redefine existing
# configuration, only undefine the old one and define a new one. Using
# different ``item.name`` avoids the issue of redefining the network all the
# time.
libvirt__networks_virt_nat:
- name: 'virt-nat'
type: 'dnsmasq'
bridge: 'virbr0'
addresses: [ '192.168.122.1/24' ]
domain: 'nat.{{ ansible_domain }}'
state: 'active'
forward: True
dhcp: True
# ]]]
# ]]]
# libvirt storage pool configuration [[[
# --------------------------------------
# .. envvar:: libvirt__pools [[[
#
# List of storage pool definitions in ``libvirt``, specified as YAML dicts. See
# :ref:`libvirt__pools` for more details.
libvirt__pools:
- '{{ libvirt__pools_default }}'
# ]]]
# .. envvar:: libvirt__pools_default [[[
#
# List of default storage pools configured by ``debops.libvirt``.
libvirt__pools_default:
- name: 'default'
type: 'dir'
path: '/var/lib/libvirt/images'
# ]]]
# ]]]
# Configuration for other Ansible roles [[[
# ----------------------------------------
# .. envvar:: libvirt__python__dependent_packages3 [[[
#
# Configuration for the :ref:`debops.python` Ansible role.
libvirt__python__dependent_packages3:
- 'python3-libvirt'
- 'python3-lxml'
# ]]]
# .. envvar:: libvirt__python__dependent_packages2 [[[
#
# Configuration for the :ref:`debops.python` Ansible role.
libvirt__python__dependent_packages2:
- 'python-libvirt'
- 'python-lxml'
# ]]]
# ]]]

View file

@ -0,0 +1,31 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# 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, Robin Schneider'
description: 'Manage local or remote libvirt instance'
company: 'DebOps'
license: 'GPL-3.0-only'
min_ansible_version: '2.2.0'
platforms:
- name: 'Ubuntu'
versions: [ 'all' ]
- name: 'Debian'
versions: [ 'all' ]
galaxy_tags:
- system
- virtualization

View file

@ -0,0 +1,50 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Import DebOps secret role
ansible.builtin.import_role:
name: 'secret'
- name: Install libvirt support
ansible.builtin.package:
name: '{{ q("flattened", (libvirt__base_packages
+ (libvirt__packages_map[ansible_distribution_release]
| d(libvirt__packages)))) }}'
state: 'present'
register: libvirt__register_packages
until: libvirt__register_packages is succeeded
- name: Create configuration directory
ansible.builtin.file:
path: '~/.config/libvirt'
state: 'directory'
mode: '0755'
become: False
- name: Generate libvirt.conf configuration
ansible.builtin.template:
src: 'home/config/libvirt/libvirt.conf.j2'
dest: '~/.config/libvirt/libvirt.conf'
mode: '0644'
become: False
- name: Get list of groups admin account belongs to
ansible.builtin.command: groups
register: libvirt__register_groups
changed_when: False
check_mode: False
become: False
tags: [ 'role::libvirt:networks', 'role::libvirt:pools' ]
- name: Manage libvirt networks
ansible.builtin.include_tasks: manage_networks.yml
when: libvirt__group_map[ansible_distribution] in libvirt__register_groups.stdout.split(" ")
tags: [ 'role::libvirt:networks' ]
- name: Manage libvirt pools
ansible.builtin.include_tasks: manage_pools.yml
when: libvirt__group_map[ansible_distribution] in libvirt__register_groups.stdout.split(" ")
tags: [ 'role::libvirt:pools' ]

View file

@ -0,0 +1,60 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Stop networks if requested
community.libvirt.virt_net:
name: '{{ item.name }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'inactive'
loop: '{{ q("flattened", libvirt__networks) }}'
become: False
when: (item.name | d() and (item.state | d() in ['inactive', 'undefined', 'absent']))
- name: Undefine networks if requested
community.libvirt.virt_net:
name: '{{ item.name }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'absent'
loop: '{{ q("flattened", libvirt__networks) }}'
become: False
when: (item.name | d() and (item.state | d() in ['undefined', 'absent']))
- name: Define networks
community.libvirt.virt_net:
name: '{{ item.name }}'
xml: '{{ lookup("template", "lookup/network/" + item.type + ".xml.j2") }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'present'
loop: '{{ q("flattened", libvirt__networks) }}'
become: False
when: ((item.name | d()) and
(item.state | d("active") not in ['undefined', 'absent']) and
(item.interface_present is undefined or
(item.interface_present in ansible_interfaces and not item.uri | d())))
- name: Start networks if not started
community.libvirt.virt_net:
name: '{{ item.name }}'
state: 'active'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
loop: '{{ q("flattened", libvirt__networks) }}'
become: False
when: ((item.name | d()) and
(item.state is undefined or item.state in ['active']) and
(item.interface_present is undefined or
(item.interface_present in ansible_interfaces and not item.uri | d())))
- name: Set autostart attribute on networks
community.libvirt.virt_net:
name: '{{ item.name }}'
autostart: '{{ "yes" if (item.autostart | d(True)) else "no" }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
loop: '{{ q("flattened", libvirt__networks) }}'
become: False
when: ((item.name | d()) and
(item.state is undefined or item.state not in ['undefined', 'absent']) and
(item.interface_present is undefined or
(item.interface_present in ansible_interfaces and not item.uri | d())))

View file

@ -0,0 +1,79 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Stop storage pools if requested
community.libvirt.virt_pool:
name: '{{ item.name }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'inactive'
loop: '{{ q("flattened", libvirt__pools) }}'
become: False
register: libvirt__register_stop
when: ((item.name | d()) and (item.state | d() in ['inactive', 'undefined', 'absent']))
- name: Delete storage pools if requested
community.libvirt.virt_pool: # noqa no-handler
name: '{{ item.item.name }}'
uri: '{{ libvirt__connections[item.item.uri | d(libvirt__uri)] }}'
command: 'delete'
mode: '{{ item.item.mode | d(omit) }}'
loop: '{{ q("flattened", libvirt__register_stop.results) }}'
become: False
when: (item is changed and item.item.name | d() and item.item.delete | d(False) and
item.item.state | d() in ['undefined'] and
item.item.type in ['dir', 'nfs', 'logical'])
- name: Undefine storage pools if requested
community.libvirt.virt_pool:
name: '{{ item.name }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'absent'
loop: '{{ q("flattened", libvirt__pools) }}'
become: False
when: ((item.name | d()) and (item.state | d() in ['undefined', 'absent']))
- name: Define storage pools
community.libvirt.virt_pool:
name: '{{ item.name }}'
xml: '{{ lookup("template", "lookup/pool/" + item.type + ".xml.j2") }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
state: 'present'
loop: '{{ q("flattened", libvirt__pools) }}'
become: False
register: libvirt__register_define
when: ((item.name | d()) and (item.state | d('active') not in ['undefined', 'absent']))
- name: Build new storage pools
community.libvirt.virt_pool: # noqa no-handler
name: '{{ item.item.name }}'
uri: '{{ libvirt__connections[item.item.uri | d(libvirt__uri)] }}'
command: 'build'
mode: '{{ item.item.mode | d(omit) }}'
loop: '{{ q("flattened", libvirt__register_define.results) }}'
become: False
when: (item is changed and item.item.name | d() and
(item.item.state | d('active') not in ['undefined', 'absent']) and
(item.item.build | d(True)) and
(item.item.type in ['dir', 'nfs'] or
(item.item.type == 'logical' and item.item.devices | d())))
- name: Start storage pools if not started
community.libvirt.virt_pool:
name: '{{ item.name }}'
state: 'active'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
loop: '{{ q("flattened", libvirt__pools) }}'
become: False
when: (item.name | d() and item.state | d('active') in ['active'])
- name: Set autostart attribute on storage pools
community.libvirt.virt_pool:
name: '{{ item.name }}'
autostart: '{{ "yes" if (item.autostart | d(True)) else "no" }}'
uri: '{{ libvirt__connections[item.uri | d(libvirt__uri)] }}'
loop: '{{ q("flattened", libvirt__pools) }}'
become: False
when: (item.name | d() and item.state | d('active') not in ['undefined', 'absent'])

View file

@ -0,0 +1,31 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
# {{ ansible_managed }}
# This can be used to setup URI aliases for frequently
# used connection URIs. Aliases may contain only the
# characters a-Z, 0-9, _, -.
#
# Following the '=' may be any valid libvirt connection
# URI, including arbitrary parameters
#uri_aliases = [
# "hail=qemu+ssh://root@hail.cloud.example.com/system",
# "sleet=qemu+ssh://root@sleet.cloud.example.com/system",
#]
uri_aliases = [
{% for key, value in libvirt__connections.items() %}
"{{ key + '=' + value }}",
{% endfor %}
]
# This can be used to prevent probing of the hypervisor
# driver when no URI is supplied by the application.
#uri_default = "qemu:///system"
{% if libvirt__uri | d() %}
uri_default = "{{ libvirt__connections[libvirt__uri] }}"
{% endif %}

View file

@ -0,0 +1,13 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<network>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
<bridge name="{{ item.bridge }}" />
<forward mode="bridge" />
</network>

View file

@ -0,0 +1,14 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<network>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
<forward mode="bridge">
<interface dev="{{ item.bridge }}" />
</forward>
</network>

View file

@ -0,0 +1,49 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
{% set libvirt__tpl_dhcp_range_start = 10 %}
{% set libvirt__tpl_dhcp_range_end = 250 %}
{% if item.dhcp_range | d() %}
{% set libvirt__tpl_dhcp_range_start = item.dhcp_range[0] | int %}
{% set libvirt__tpl_dhcp_range_end = item.dhcp_range[1] | int %}
{% endif %}
<network>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
{% if item.bridge | d() %}
<bridge name="{{ item.bridge }}"/>
{% endif %}
{% if item.forward | d() %}
<forward mode="{{ item.forward_mode | d('nat') }}"/>
{% endif %}
{% if item.domain | d() %}
<domain name="{{ item.domain }}" localOnly="{{ "yes" if item.domain_local | d() else "no" }}"/>
{% endif %}
{% if item.addresses | d() %}
{% for subnet in item.addresses | ansible.utils.ipv4('host/prefix') %}
<ip family="ipv4" address="{{ subnet | ansible.utils.ipaddr('address') }}" netmask="{{ subnet | ansible.utils.ipaddr('netmask') }}">
{% if item.dhcp | d() and loop.first %}
<dhcp>
{% if item.bootp | d() %}
<bootp file="{{ item.bootp_file | d('/undionly.kpxe') }}"{% if item.bootp_server | d() %} server="{{ item.bootp_server }}"{% endif %}/>
{% endif %}
<range start="{{ subnet | ansible.utils.ipaddr(libvirt__tpl_dhcp_range_start) | ansible.utils.ipaddr('address') }}" end="{{ subnet | ansible.utils.ipaddr(libvirt__tpl_dhcp_range_end) | ansible.utils.ipaddr('address') }}"/>
</dhcp>
{% endif %}
</ip>
{% endfor %}
{% for subnet in item.addresses | ansible.utils.ipv6('host/prefix') %}
<ip family="ipv6" address="{{ subnet | ansible.utils.ipaddr('address') }}" prefix="{{ subnet | ansible.utils.ipaddr('prefix') }}">
{% if item.dhcp | d() and loop.first %}
<dhcp>
<range start="{{ subnet | ansible.utils.ipaddr(libvirt__tpl_dhcp_range_start) | ansible.utils.ipaddr('address') }}" end="{{ subnet | ansible.utils.ipaddr(libvirt__tpl_dhcp_range_end) | ansible.utils.ipaddr('address') }}"/>
</dhcp>
{% endif %}
</ip>
{% endfor %}
{% endif %}
</network>

View file

@ -0,0 +1,14 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<pool type='dir'>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
<target>
<path>{{ item.path }}</path>
</target>
</pool>

View file

@ -0,0 +1,35 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<pool type='logical'>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
{% if item.device | d() or item.devices | d() %}
<source>
{% if item.device | d() %}
{% if item.device is string %}
<device path="{{ item.device }}"/>
{% else %}
{% for device in item.device %}
<device path="{{ device }}"/>
{% endfor %}
{% endif %}
{% elif item.devices | d() %}
{% if item.devices is string %}
<device path="{{ item.devices }}"/>
{% else %}
{% for device in item.devices %}
<device path="{{ device }}"/>
{% endfor %}
{% endif %}
{% endif %}
</source>
{% endif %}
<target>
<path>/dev/{{ item.name }}</path>
</target>
</pool>

View file

@ -0,0 +1,19 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<pool type='netfs'>
<name>{{ item.name }}</name>
{% if item.uuid | d() %}
<uuid>{{ item.uuid }}</uuid>
{% endif %}
<source>
<host name="{{ item.host }}"{% if item.port | d() %} port="{{ item.port }}"{% endif %}/>
<dir path="{{ item.src }}"/>
<format type="nfs"/>
</source>
<target>
<path>{{ item.path }}</path>
</target>
</pool>

View file

@ -0,0 +1,11 @@
{# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
<pool type="zfs">
<name>{{ item.name }}</name>
<source>
<name>{{ item.zpoolname }}</name>
</source>
</pool>