252 lines
6.4 KiB
YAML
252 lines
6.4 KiB
YAML
---
|
|
# Playbook for hypervisors
|
|
- name: Initialize hypervisors
|
|
hosts: hypervisors
|
|
become: true
|
|
roles:
|
|
- role: ericomeehan.debian
|
|
- role: ericomeehan.ericomeehan
|
|
|
|
- name: Deploy virtual machines
|
|
hosts: hypervisors
|
|
become: true
|
|
vars_files:
|
|
- ../secrets.yaml
|
|
pre_tasks:
|
|
- name: Install packages for virtualization
|
|
apt:
|
|
update_cache: yes
|
|
name:
|
|
- bridge-utils
|
|
- genisoimage
|
|
- qemu-utils
|
|
- qemu-system-x86
|
|
- libvirt-daemon-system
|
|
- python3-libvirt
|
|
- python3-lxml
|
|
state: present
|
|
|
|
- name: Enable IPv4 packet forwarding
|
|
lineinfile:
|
|
path: /etc/sysctl.conf
|
|
line: 'net.ipv4.ip_forward = 1'
|
|
state: present
|
|
|
|
- name: Enable IPv6 packet forwarding
|
|
lineinfile:
|
|
path: /etc/sysctl.conf
|
|
line: 'net.ipv6.conf.all.forwarding = 1'
|
|
state: present
|
|
|
|
- name: Reload sysctl configuration
|
|
command: sysctl --system
|
|
|
|
- name: Define libvirt networks
|
|
community.libvirt.virt_net:
|
|
name: "{{ item.name }}"
|
|
command: define
|
|
xml: "{{ lookup('template', 'libvirt-network.xml.j2') }}"
|
|
loop: "{{ libvirt_networks }}"
|
|
|
|
- name: Create libvirt networks
|
|
community.libvirt.virt_net:
|
|
name: "{{ item.name }}"
|
|
command: create
|
|
loop: "{{ libvirt_networks }}"
|
|
|
|
- name: Autostart libvirt networks
|
|
community.libvirt.virt_net:
|
|
name: "{{ item.name }}"
|
|
autostart: true
|
|
loop: "{{ libvirt_networks }}"
|
|
|
|
- name: Download base image
|
|
get_url:
|
|
url: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
|
|
dest: /var/lib/libvirt/images/debian-12-generic-amd64.qcow2
|
|
force: true
|
|
|
|
- name: Copy base image
|
|
copy:
|
|
src: /var/lib/libvirt/images/debian-12-generic-amd64.qcow2
|
|
remote_src: true
|
|
dest: "/var/lib/libvirt/images/{{ item }}.qcow2"
|
|
force: true
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Resize images
|
|
command: "qemu-img resize -f qcow2 /var/lib/libvirt/images/{{ item }}.qcow2 16G"
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Create cloud-config directory
|
|
file:
|
|
path: "/tmp/{{ item }}"
|
|
state: directory
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Copy cloud-config user-data template
|
|
template:
|
|
src: user-data.j2
|
|
dest: "/tmp/{{ domain.name }}/user-data"
|
|
force: true
|
|
loop: "{{ libvirt_guests }}"
|
|
vars:
|
|
domain: "{{ hostvars[item] }}"
|
|
|
|
- name: Copy cloud-config meta-data template
|
|
template:
|
|
src: meta-data.j2
|
|
dest: "/tmp/{{ domain.name }}/meta-data"
|
|
force: true
|
|
loop: "{{ libvirt_guests }}"
|
|
vars:
|
|
domain: "{{ hostvars[item] }}"
|
|
|
|
- name: Generate iso
|
|
command: "genisoimage -output /var/lib/libvirt/images/{{ item }}.iso -volid cidata -joliet -rock /tmp/{{ item }}/user-data /tmp/{{ item }}/meta-data"
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Define libvirt virtual machine
|
|
community.libvirt.virt:
|
|
command: define
|
|
xml: "{{ lookup('template', 'libvirt-vm.xml.j2') }}"
|
|
loop: "{{ libvirt_guests }}"
|
|
vars:
|
|
domain: "{{ hostvars[item] }}"
|
|
|
|
- name: Create libvirt virtual machine
|
|
community.libvirt.virt:
|
|
name: "{{ item }}"
|
|
command: create
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Autostart libvirt virtual machines
|
|
community.libvirt.virt:
|
|
name: "{{ item }}"
|
|
autostart: true
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Wait for guest initialization
|
|
wait_for:
|
|
timeout: 300
|
|
|
|
- name: Reset libvirt virtual machines for filesystem resize
|
|
command: "virsh reset {{ item }}"
|
|
loop: "{{ libvirt_guests }}"
|
|
|
|
- name: Copy SSH keys
|
|
hosts: localhost
|
|
tasks:
|
|
- name: Wait for manual tasks
|
|
pause:
|
|
prompt: "Press Enter to continue..."
|
|
|
|
- name: Initialize virtual machines
|
|
hosts: vms
|
|
become: true
|
|
pre_tasks:
|
|
- name: Append text from files/motd to the beginning of remote motd file
|
|
blockinfile:
|
|
path: /etc/motd
|
|
marker: ""
|
|
block: |
|
|
{{ lookup('file', 'motd') }}
|
|
|
|
roles:
|
|
- role: ericomeehan.ericomeehan
|
|
|
|
- name: Initialize Network File Systems
|
|
hosts: network-file-system
|
|
become: true
|
|
roles:
|
|
- role: geerlingguy.nfs
|
|
|
|
- name: Initialize Kubernetes clusters
|
|
hosts: clusters
|
|
become: true
|
|
pre_tasks:
|
|
- name: Enable IPv4 packet forwarding
|
|
lineinfile:
|
|
path: /etc/sysctl.conf
|
|
line: 'net.ipv4.ip_forward = 1'
|
|
state: present
|
|
|
|
- name: Enable IPv6 packet forwarding
|
|
lineinfile:
|
|
path: /etc/sysctl.conf
|
|
line: 'net.ipv6.conf.all.forwarding = 1'
|
|
state: present
|
|
|
|
- name: Reload sysctl configuration
|
|
command: sysctl --system
|
|
|
|
- name: Enable br_netfilter kernel module
|
|
command: modprobe br_netfilter
|
|
|
|
- name: Add the module to a configuration file for persistence
|
|
lineinfile:
|
|
path: /etc/modules-load.d/modules.conf
|
|
line: "br_netfilter"
|
|
|
|
- name: Install kubernetes library
|
|
apt:
|
|
name: python3-kubernetes
|
|
state: present
|
|
|
|
roles:
|
|
- role: geerlingguy.containerd
|
|
|
|
- name: Alpha Cluster
|
|
hosts: alpha
|
|
become: true
|
|
roles:
|
|
- role: geerlingguy.kubernetes
|
|
|
|
- name: Beta Cluster
|
|
hosts: beta
|
|
become: true
|
|
roles:
|
|
- role: geerlingguy.kubernetes
|
|
|
|
- name: Gamma Cluster
|
|
hosts: gamma
|
|
become: true
|
|
roles:
|
|
- role: geerlingguy.kubernetes
|
|
|
|
- name: Install Helm
|
|
hosts: control_planes
|
|
become: true
|
|
roles:
|
|
- role: geerlingguy.helm
|
|
|
|
- name: Install NFS Common
|
|
hosts: workers
|
|
become: true
|
|
tasks:
|
|
- name: Install nfs-common
|
|
apt:
|
|
name: nfs-common
|
|
state: present
|
|
|
|
- name: Configure default storage class
|
|
hosts: control-planes
|
|
become: true
|
|
tasks:
|
|
- name: Install helm repo
|
|
kubernetes.core.helm_repository:
|
|
name: nfs-subdir-external-provisioner
|
|
repo_url: https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
|
|
|
|
- name: Deploy nfs provisioner
|
|
kubernetes.core.helm:
|
|
name: nfs-subdir-external-provisioner
|
|
chart_ref: nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
|
|
release_namespace: default
|
|
values:
|
|
nfs:
|
|
server: network-file-system
|
|
path: "/data/{{ nfs_path }}"
|
|
storageClass:
|
|
defaultClass: true
|