new hypervisor wip

This commit is contained in:
2023-08-09 18:38:34 +10:00
parent 590a50cd1a
commit 5007f0b68e
14 changed files with 233 additions and 52 deletions

View File

@ -0,0 +1,5 @@
---
iso_source:
ntp_servers:
- time.example.com

View File

@ -1,2 +0,0 @@
---
iso_source:

View File

@ -0,0 +1,12 @@
libvirt_packages:
arch:
qemu-base
openbsd-netcat
swtpm
gettext
libvirt
libvirt-python
default_network_services:
Archlinux:
NetworkManager

View File

@ -0,0 +1,76 @@
---
- name: Clear systemd-networkd config directory
ansible.builtin.file:
path: "/etc/systemd/network/"
state: "{{ item }}"
owner: root
group: root
mode: '0755'
with_items:
- absent
- directory
- name: Create systemd-networkd config files
ansible.builtin.template:
src: "{{ item.src }}"
dest: /etc/systemd/network/"{{ item.name }}"
owner: root
group: root
mode: '0644'
loop: "{{ systemd_networkd_configs }}"
- name: Disable non-systemd networking services
ansible.builtin.service:
name: "{{ item }}"
state: stopped
enabled: false
loop: "{{ default_network_services[ansible_os_family] }}"
- name: Enable systemd networking
ansible.builtin.service:
name: "{{ item }}"
state: started
enabled: true
loop:
- systemd-networkd
- systemd-resolved
- name: Install libvirt packages (Arch)
when: ansible_os_distribution == 'Archlinux'
community.general.pacman:
name: "{{ libvirt_packages['Arch'] }}"
state: present
update_cache: true
- name: Add user to libvirt group
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: libvirt
append: true
- name: Add bridge(s) to qemu_bridge_helper
when: qemu_bridges is defined
ansible.builtin.lineinfile:
path: /etc/qemu/bridge.conf
line: "{{ item }}"
state: present
backup: false
insertafter: EOF
loop: "{{ qemu_bridges | default(['virbr0']) }}"
- name: Start and enable libvirt service
ansible.builtin.service:
name: libvirtd.service
state: started
enabled: true
- name: Stop the default libvirt network
community.libvirt.virt_net:
name: default
state: inactive
- name: Remove default libvirt network
community.libvirt.virt_net:
name: default
state: absent

View File

@ -0,0 +1,9 @@
[NetDev]
Name=br0
Kind=bridge
[Bridge]
DefaultPVID=none
VLANFiltering={{ item.vlan_filtering }}
VLANProtocol=802.1q
STP={{ item.stp }}

View File

@ -0,0 +1,6 @@
[Match]
PermanentMACAddress={{ item.mac_address }}
[Link]
MACAddressPolicy=permanent
MACAddress={{ item.mac_address }}
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.link', '') }}

View File

@ -0,0 +1,12 @@
[Match]
MACAddress={{ item.mac_address }}
[Link]
ARP={{ item.arp }}
[Network]
DHCP=no
if item.bond
Bond={{ item.bond }}
if item.bridge
Bridge={{ item.bridge }}