diff --git a/.gitignore b/.gitignore index eca7b7c..3a65e62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vault *.tar.gz +*.qcow2 diff --git a/alpha-cluster.yaml b/alpha-cluster.yaml new file mode 100644 index 0000000..ad8d3d6 --- /dev/null +++ b/alpha-cluster.yaml @@ -0,0 +1,9 @@ +--- +# Playbook for alpha-cluster +- name: Deploy services to Alpha Cluster + hosts: alpha-control-plane + become: true + vars_files: + secrets.yaml + roles: + - role: ericomeehan.gondwanamc diff --git a/files/01_debian_cloud.cfg b/files/01_debian_cloud.cfg new file mode 100644 index 0000000..6d03a66 --- /dev/null +++ b/files/01_debian_cloud.cfg @@ -0,0 +1,13 @@ +apt: + generate_mirrorlists: true + +system_info: + default_user: + name: debian + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + lock_passwd: True + gecos: Debian + groups: [adm, audio, cdrom, dialout, dip, floppy, plugdev, sudo, video] + sudo: ["ALL=(ALL) NOPASSWD:ALL"] + shell: /bin/bash diff --git a/files/05_logging.cfg b/files/05_logging.cfg new file mode 100644 index 0000000..bf917a9 --- /dev/null +++ b/files/05_logging.cfg @@ -0,0 +1,71 @@ +## This yaml formated config file handles setting +## logger information. The values that are necessary to be set +## are seen at the bottom. The top '_log' are only used to remove +## redundency in a syslog and fallback-to-file case. +## +## The 'log_cfgs' entry defines a list of logger configs +## Each entry in the list is tried, and the first one that +## works is used. If a log_cfg list entry is an array, it will +## be joined with '\n'. +_log: + - &log_base | + [loggers] + keys=root,cloudinit + + [handlers] + keys=consoleHandler,cloudLogHandler + + [formatters] + keys=simpleFormatter,arg0Formatter + + [logger_root] + level=DEBUG + handlers=consoleHandler,cloudLogHandler + + [logger_cloudinit] + level=DEBUG + qualname=cloudinit + handlers= + propagate=1 + + [handler_consoleHandler] + class=StreamHandler + level=WARNING + formatter=arg0Formatter + args=(sys.stderr,) + + [formatter_arg0Formatter] + format=%(asctime)s - %(filename)s[%(levelname)s]: %(message)s + + [formatter_simpleFormatter] + format=[CLOUDINIT] %(filename)s[%(levelname)s]: %(message)s + - &log_file | + [handler_cloudLogHandler] + class=FileHandler + level=DEBUG + formatter=arg0Formatter + args=('/var/log/cloud-init.log', 'a', 'UTF-8') + - &log_syslog | + [handler_cloudLogHandler] + class=handlers.SysLogHandler + level=DEBUG + formatter=simpleFormatter + args=("/dev/log", handlers.SysLogHandler.LOG_USER) + +log_cfgs: +# Array entries in this list will be joined into a string +# that defines the configuration. +# +# If you want logs to go to syslog, uncomment the following line. +# - [ *log_base, *log_syslog ] +# +# The default behavior is to just log to a file. +# This mechanism that does not depend on a system service to operate. + - [ *log_base, *log_file ] +# A file path can also be used. +# - /etc/log.conf + +# This tells cloud-init to redirect its stdout and stderr to +# 'tee -a /var/log/cloud-init-output.log' so the user can see output +# there without needing to look on the console. +output: {all: '| tee -a /var/log/cloud-init-output.log'} diff --git a/group_vars/alpha.yaml b/group_vars/alpha.yaml new file mode 100644 index 0000000..87a788d --- /dev/null +++ b/group_vars/alpha.yaml @@ -0,0 +1 @@ +nfs_path: alpha diff --git a/group_vars/beta.yaml b/group_vars/beta.yaml new file mode 100644 index 0000000..0cdd134 --- /dev/null +++ b/group_vars/beta.yaml @@ -0,0 +1 @@ +nfs_path: beta diff --git a/group_vars/control_plane.yml b/group_vars/control_planes.yaml similarity index 92% rename from group_vars/control_plane.yml rename to group_vars/control_planes.yaml index d3f4924..23acfd0 100644 --- a/group_vars/control_plane.yml +++ b/group_vars/control_planes.yaml @@ -20,3 +20,6 @@ open_ports: - interface: any protocol: tcp port: 10259 +memory: + unit: MiB + value: 8192 diff --git a/group_vars/gamma.yaml b/group_vars/gamma.yaml new file mode 100644 index 0000000..bc3a38f --- /dev/null +++ b/group_vars/gamma.yaml @@ -0,0 +1 @@ +nfs_path: gamma diff --git a/group_vars/hypervisors.yaml b/group_vars/hypervisors.yaml new file mode 100644 index 0000000..130b120 --- /dev/null +++ b/group_vars/hypervisors.yaml @@ -0,0 +1,6 @@ +--- +# Group vars for hypervisors +open_ports: + - interface: any + protocol: tcp + port: 22 diff --git a/group_vars/vms.yaml b/group_vars/vms.yaml new file mode 100644 index 0000000..dd37467 --- /dev/null +++ b/group_vars/vms.yaml @@ -0,0 +1,111 @@ +--- +# Group vars for virtual machines +type: kvm +name: my_vm_name +instance_id: "iid-{{ name }}" +packages: + - openssh-server + - prometheus-node-exporter + - qemu-guest-agent +open_ports: + - interface: any + protocol: tcp + port: 22 +memory: + unit: MiB + value: 4096 +vcpu: + placement: static + value: 2 +os: + type: + arch: x86_64 + machine: pc-q35-5.2 + value: hvm + boot: + dev: hd +cpu: + mode: host-model + check: none +emulator: /usr/bin/qemu-system-x86_64 +disks: + - type: file + device: disk + driver: + name: qemu + type: qcow2 + source: + file: /var/lib/libvirt/images/{{ name }}.qcow2 + target: + dev: vda + bus: virtio + - type: file + device: cdrom + driver: + name: qemu + type: raw + source: + file: /var/lib/libvirt/images/{{ name }}.iso + target: + dev: sda + bus: sata +interfaces: + - type: network + source: + network: wan + model: + type: virtio +channels: + - type: unix + target: + type: virtio + name: org.qemu.guest_agent.0 + address: + type: virtio-serial + controller: 0 + bus: 0 + port: 1 +inputs: + - type: tablet + bus: usb + address: + type: usb + bus: 0 + port: 1 + - type: mouse + bus: ps2 + - type: keyboard + bus: ps2 +graphics: + type: spice + autoport: 'yes' + listen: + type: address + image: + compression: 'off' +video: + model: + type: qxl + ram: 65536 + vram: 65536 + vgamem: 16384 + heads: 1 + primary: yes +memballoon: + model: virtio +rng: + model: virtio + backend: + model: random + value: /dev/urandom +devices: + emulator: "{{ emulator }}" + disks: "{{ disks }}" + filesystems: "{{ filesystems }}" + interfaces: "{{ interfaces }}" + channels: "{{ channels }}" + inputs: "{{ inputs }}" + graphics: "{{ graphics }}" + video: "{{ video }}" + memballoon: "{{ memballoon }}" + rng: "{{ rng }}" diff --git a/group_vars/workers.yml b/group_vars/workers.yml index b00897d..8159a70 100644 --- a/group_vars/workers.yml +++ b/group_vars/workers.yml @@ -14,3 +14,6 @@ open_ports: - interface: any protocol: tcp port: 30000-32767 +memory: + unit: MiB + value: 16384 diff --git a/host_vars/alpha-control-plane.yaml b/host_vars/alpha-control-plane.yaml new file mode 100644 index 0000000..ea894ed --- /dev/null +++ b/host_vars/alpha-control-plane.yaml @@ -0,0 +1 @@ +name: alpha-control-plane diff --git a/host_vars/alpha-control-plane.yml b/host_vars/alpha-control-plane.yml deleted file mode 100644 index dfd9f12..0000000 --- a/host_vars/alpha-control-plane.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# Host vars for alpha-control-plane diff --git a/host_vars/alpha-worker-0.yaml b/host_vars/alpha-worker-0.yaml new file mode 100644 index 0000000..1a9fba1 --- /dev/null +++ b/host_vars/alpha-worker-0.yaml @@ -0,0 +1 @@ +name: alpha-worker-0 diff --git a/host_vars/alpha-worker-0.yml b/host_vars/alpha-worker-0.yml deleted file mode 100644 index db7be9a..0000000 --- a/host_vars/alpha-worker-0.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -# Host vars for alpha-worker-0 -nvidia_driver_needed: true -nvidia_driver_tesla: true -qemu_cluster_networks: - - name: lan - bridge: br1 - interfaces: - - eno2np1 - address: 10.0.0.2 - netmask: 255.255.255.0 - gateway: 10.0.0.254 -qemu_cluster_machines: - - name: nfs - ram_mb: 4096 - vcpus: 1 - networks: - - lan - - name: control-plane - ram_mb: 4096 - vcpus: 1 - networks: - - lan - - name: worker-0 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - - name: worker-1 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - - name: worker-2 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - - name: worker-3 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - - name: worker-4 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - - name: worker-5 - ram_mb: 16384 - vcpus: 1 - networks: - - lan diff --git a/host_vars/alpha-worker-1.yaml b/host_vars/alpha-worker-1.yaml new file mode 100644 index 0000000..6c7040e --- /dev/null +++ b/host_vars/alpha-worker-1.yaml @@ -0,0 +1 @@ +name: alpha-worker-1 diff --git a/host_vars/alpha-worker-2.yaml b/host_vars/alpha-worker-2.yaml new file mode 100644 index 0000000..3b7f0f9 --- /dev/null +++ b/host_vars/alpha-worker-2.yaml @@ -0,0 +1 @@ +name: alpha-worker-2 diff --git a/host_vars/alpha-worker-3.yaml b/host_vars/alpha-worker-3.yaml new file mode 100644 index 0000000..c9bc9ed --- /dev/null +++ b/host_vars/alpha-worker-3.yaml @@ -0,0 +1 @@ +name: alpha-worker-3 diff --git a/host_vars/alpha.yaml b/host_vars/alpha.yaml new file mode 100644 index 0000000..e69de29 diff --git a/host_vars/beta-control-plane.yaml b/host_vars/beta-control-plane.yaml new file mode 100644 index 0000000..da72e3c --- /dev/null +++ b/host_vars/beta-control-plane.yaml @@ -0,0 +1 @@ +name: beta-control-plane diff --git a/host_vars/beta-worker-0.yaml b/host_vars/beta-worker-0.yaml new file mode 100644 index 0000000..fc4643c --- /dev/null +++ b/host_vars/beta-worker-0.yaml @@ -0,0 +1 @@ +name: beta-worker-0 diff --git a/host_vars/beta-worker-1.yaml b/host_vars/beta-worker-1.yaml new file mode 100644 index 0000000..3136515 --- /dev/null +++ b/host_vars/beta-worker-1.yaml @@ -0,0 +1 @@ +name: beta-worker-1 diff --git a/host_vars/beta-worker-2.yaml b/host_vars/beta-worker-2.yaml new file mode 100644 index 0000000..494504d --- /dev/null +++ b/host_vars/beta-worker-2.yaml @@ -0,0 +1 @@ +name: beta-worker-2 diff --git a/host_vars/beta-worker-3.yaml b/host_vars/beta-worker-3.yaml new file mode 100644 index 0000000..fa4cac1 --- /dev/null +++ b/host_vars/beta-worker-3.yaml @@ -0,0 +1 @@ +name: beta-worker-3 diff --git a/host_vars/gamma-control-plane.yaml b/host_vars/gamma-control-plane.yaml new file mode 100644 index 0000000..923d624 --- /dev/null +++ b/host_vars/gamma-control-plane.yaml @@ -0,0 +1 @@ +name: gamma-control-plane diff --git a/host_vars/gamma-worker-0.yaml b/host_vars/gamma-worker-0.yaml new file mode 100644 index 0000000..e6fb694 --- /dev/null +++ b/host_vars/gamma-worker-0.yaml @@ -0,0 +1 @@ +name: gamma-worker-0 diff --git a/host_vars/gamma-worker-1.yaml b/host_vars/gamma-worker-1.yaml new file mode 100644 index 0000000..fa5c662 --- /dev/null +++ b/host_vars/gamma-worker-1.yaml @@ -0,0 +1 @@ +name: gamma-worker-1 diff --git a/host_vars/gamma-worker-2.yaml b/host_vars/gamma-worker-2.yaml new file mode 100644 index 0000000..fba0cf1 --- /dev/null +++ b/host_vars/gamma-worker-2.yaml @@ -0,0 +1 @@ +name: gamma-worker-2 diff --git a/host_vars/gamma-worker-3.yaml b/host_vars/gamma-worker-3.yaml new file mode 100644 index 0000000..15a3ab8 --- /dev/null +++ b/host_vars/gamma-worker-3.yaml @@ -0,0 +1 @@ +name: gamma-worker-3 diff --git a/host_vars/gateway.yaml b/host_vars/gateway.yaml new file mode 100644 index 0000000..b6e56f4 --- /dev/null +++ b/host_vars/gateway.yaml @@ -0,0 +1,59 @@ +--- +# Host vars for gateway +name: gateway +interfaces: + - type: network + source: + network: lan + model: + type: virtio + address: + type: pci + domain: 0x0000 + bus: 0x01 + slot: 0x00 + function: 0x0 + - type: network + source: + network: wan + model: + type: virtio + address: + type: pci + domain: 0x0000 + bus: 0x02 + slot: 0x00 + function: 0x0 + - type: network + source: + network: alpha + model: + type: virtio + address: + type: pci + domain: 0x0000 + bus: 0x03 + slot: 0x00 + function: 0x0 + - type: network + source: + network: beta + model: + type: virtio + address: + type: pci + domain: 0x0000 + bus: 0x04 + slot: 0x00 + function: 0x0 + - type: network + source: + network: gamma + model: + type: virtio + address: + type: pci + domain: 0x0000 + bus: 0x08 + slot: 0x00 + function: 0x0 diff --git a/host_vars/network-file-system.yaml b/host_vars/network-file-system.yaml new file mode 100644 index 0000000..b8220e5 --- /dev/null +++ b/host_vars/network-file-system.yaml @@ -0,0 +1,35 @@ +name: network-file-system +nfs_exports: ["/data *(rw,sync,no_root_squash)"] +mounts: + - [ vdb, /data ] +disks: + - type: file + device: disk + driver: + name: qemu + type: qcow2 + source: + file: /var/lib/libvirt/images/{{ name }}.qcow2 + target: + dev: vda + bus: virtio + - type: block + device: disk + driver: + name: qemu + type: raw + source: + dev: /dev/poweredge-t640-vg1/store-0 + target: + dev: vdb + bus: virtio + - type: file + device: cdrom + driver: + name: qemu + type: raw + source: + file: /var/lib/libvirt/images/{{ name }}.iso + target: + dev: sda + bus: sata diff --git a/host_vars/poweredge-r350.yaml b/host_vars/poweredge-r350.yaml index b508a4b..cdd837e 100644 --- a/host_vars/poweredge-r350.yaml +++ b/host_vars/poweredge-r350.yaml @@ -1,36 +1,16 @@ # Host vars for poweredge-r350 -qemu_network_networks: +libvirt_networks: - name: wan - bridge: br0 - interfaces: - - eno1np0 - use_dhcp: true + forward: + mode: bridge + bridge: + name: wan + dev: eno8303 - name: lan - bridge: br1 - interfaces: - - eno2np1 - use_dhcp: false - address: 10.0.0.1 - netmask: 255.0.0.0 - gateway: 10.0.0.254 -qemu_network_machines: - - name: gateway - ram_mb: 2048 - vcpus: 1 - networks: - - wan - - lan - disks: - - filename: gateway-vda - type: qcow2 - target_dev: vda - - name: vpn - ram_mb: 2048 - vcpus: 1 - networks: - - wan - - lan - disks: - - filename: vpn-vda - type: qcow2 - target_dev: vda + forward: + mode: bridge + bridge: + name: lan + dev: eno8403 +libvirt_guests: + - vpn diff --git a/host_vars/poweredge-t640.yaml b/host_vars/poweredge-t640.yaml index b4dc88e..dc3e2f7 100644 --- a/host_vars/poweredge-t640.yaml +++ b/host_vars/poweredge-t640.yaml @@ -1,90 +1,26 @@ --- # Host vars for poweredge-t640 -nvidia_driver_needed: true -nvidia_driver_tesla: true -qemu_network_networks: - - name: lan - bridge: br1 - interfaces: - - eno2np1 - use_dhcp: false - address: 10.0.0.0 - netmask: 255.255.0.0 - gateway: 10.0.0.1 -qemu_network_disks: - - name: nfs-vda - type: qcow2 - from: eom-base.qcow2 - - name: nfs-vdb - type: qcow2 - size: 16T - - name: control-plane-vda - type: qcow2 - from: eom-base.qcow2 - - name: worker-0-vda - type: qcow2 - from: eom-base.qcow2 - - name: worker-1-vda - type: qcow2 - from: eom-base.qcow2 - - name: worker-2-vda - type: qcow2 - from: eom-base.qcow2 -qemu_network_machines: - - name: nfs - ram_mb: 4096 - vcpus: 1 - networks: - - lan - disks: - - filename: nfs-vda - type: qcow2 - target_dev: vda - - filename: nfs-vdb - type: qcow2 - target_dev: vda - - name: control-plane - ram_mb: 4096 - vcpus: 1 - networks: - - lan - disks: - - filename: control-plane-vda - type: qcow2 - target_dev: vda - - name: worker-0 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - disks: - - filename: worker-0-vda - type: qcow2 - target_dev: vda - - name: worker-1 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - disks: - - filename: worker-1-vda - type: qcow2 - target_dev: vda - - name: worker-2 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - disks: - - filename: worker-2-vda - type: qcow2 - target_dev: vda - - name: worker-3 - ram_mb: 16384 - vcpus: 1 - networks: - - lan - disks: - - filename: worker-3-vda - type: qcow2 - target_dev: vda +libvirt_networks: + - name: wan + forward: + mode: bridge + bridge: + name: wan + dev: eno1np0 +libvirt_guests: + - network-file-system + - alpha-control-plane + - alpha-worker-0 + - alpha-worker-1 + - alpha-worker-2 + - alpha-worker-3 + - beta-control-plane + - beta-worker-0 + - beta-worker-1 + - beta-worker-2 + - beta-worker-3 + - gamma-control-plane + - gamma-worker-0 + - gamma-worker-1 + - gamma-worker-2 + - gamma-worker-3 diff --git a/host_vars/vpn.yaml b/host_vars/vpn.yaml new file mode 100644 index 0000000..dbae9e7 --- /dev/null +++ b/host_vars/vpn.yaml @@ -0,0 +1,18 @@ +--- +# Host vars for vpn +name: vpn +packages: + - openssh-server + - openvpn + - prometheus-node-exporter +interfaces: + - type: network + source: + network: wan + model: + type: virtio + - type: network + source: + network: lan + model: + type: virtio diff --git a/hypervisors.yaml b/hypervisors.yaml new file mode 100644 index 0000000..320be74 --- /dev/null +++ b/hypervisors.yaml @@ -0,0 +1,251 @@ +--- +# 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 diff --git a/inventories/attlocal.yml b/inventories/attlocal.yml index e4c911c..22a6107 100644 --- a/inventories/attlocal.yml +++ b/inventories/attlocal.yml @@ -4,40 +4,58 @@ all: workstations: hosts: latitude-7230: - ansible-host: 192.168.1.123 inspiron-3670: - ansible-host: 192.168.1.210 imac: - ansible-host: 192.168.1.139 - servers: + + hypervisors: hosts: poweredge-r350: - ansible-host: 192.168.1.137 poweredge-t640: - ansible-host: 192.168.1.138 + vms: hosts: - gateway: - ansible-host: 10.0.0.1 + network-file-system: vpn: - ansible-host: 10.0.0.2 - nfs: - ansible-host: 10.0.0.3 - load_balancers: - children: - alpha: - hosts: - alpha-load-balancer: - ansible-host: 10.0.1.0 + children: clusters: children: + control_planes: + hosts: + alpha-control-plane: + beta-control-plane: + gamma-control-plane: + workers: + hosts: + alpha-worker-0: + alpha-worker-1: + alpha-worker-2: + alpha-worker-3: + beta-worker-0: + beta-worker-1: + beta-worker-2: + beta-worker-3: + gamma-worker-0: + gamma-worker-1: + gamma-worker-2: + gamma-worker-3: alpha: hosts: alpha-control-plane: - ansible-host: 10.0.1.1 alpha-worker-0: - ansible-host: 10.0.1.2 alpha-worker-1: - ansible-host: 10.0.1.3 alpha-worker-2: - ansible-host: 10.0.1.4 + alpha-worker-3: + beta: + hosts: + beta-control-plane: + beta-worker-0: + beta-worker-1: + beta-worker-2: + beta-worker-3: + gamma: + hosts: + gamma-control-plane: + gamma-worker-0: + gamma-worker-1: + gamma-worker-2: + gamma-worker-3: diff --git a/kubernetes.yaml b/kubernetes.yaml new file mode 100644 index 0000000..ab9c62b --- /dev/null +++ b/kubernetes.yaml @@ -0,0 +1,60 @@ +--- +# Playbook for Kubernetes +- 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: alpha + become: true + roles: + - role: geerlingguy.kubernetes + +- name: Install Helm + hosts: control_planes + become: true + roles: + - role: geerlingguy.helm diff --git a/nfs.yaml b/nfs.yaml new file mode 100644 index 0000000..1297a43 --- /dev/null +++ b/nfs.yaml @@ -0,0 +1,5 @@ +- name: Configure NFS + hosts: network-file-system + become: true + roles: + - role: geerlingguy.nfs diff --git a/poweredge-r350.yaml b/poweredge-r350.yaml new file mode 100644 index 0000000..b97f675 --- /dev/null +++ b/poweredge-r350.yaml @@ -0,0 +1,110 @@ +--- +# Playbook for poweredge-r350 +# This is being used to test vm deployments +- name: Deploy virtual machines + hosts: poweredge-r350 + 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 for guests + get_url: + url: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 + dest: "/var/lib/libvirt/images/{{ item }}.qcow2" + force: true + loop: "{{ libvirt_guests }}" + + - name: Create cloud-config directory for guests + file: + path: "/var/lib/libvirt/configs/{{ item }}" + state: directory + loop: "{{ libvirt_guests }}" + + - name: Copy cloud-config templates for guests + template: + src: eom_cloud.cfg.j2 + dest: "/var/lib/libvirt/configs/{{ domain.name }}/user-data" + force: true + loop: "{{ libvirt_guests }}" + vars: + domain: "{{ hostvars[item] }}" + + - name: Copy cloud-config templates for guests + template: + src: meta-data.j2 + dest: "/var/lib/libvirt/configs/{{ domain.name }}/meta-data" + force: true + loop: "{{ libvirt_guests }}" + vars: + domain: "{{ hostvars[item] }}" + + - name: Generate iso for guests + command: "genisoimage -output /var/lib/libvirt/images/{{ item }}.iso -volid cidata -joliet -rock /var/lib/libvirt/configs/{{ item }}/user-data /var/lib/libvirt/configs/{{ item }}/meta-data" + loop: "{{ libvirt_guests }}" + + - name: Copy logging config for guests + copy: + src: 05_logging.cfg + dest: "/var/lib/libvirt/configs/{{ item }}/05_logging.cfg" + 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 }}" diff --git a/poweredge-t640.yaml b/poweredge-t640.yaml new file mode 100644 index 0000000..2045bab --- /dev/null +++ b/poweredge-t640.yaml @@ -0,0 +1,5 @@ +- name: Install nvidia + hosts: poweredge-t640 + become: true + roles: + - role: ericomeehan.nvidia_driver diff --git a/qemu-base.yaml b/qemu-base.yaml new file mode 100644 index 0000000..598a81c --- /dev/null +++ b/qemu-base.yaml @@ -0,0 +1,12 @@ +--- +# Create base image for QEMU +- name: Install dependencies +- name: Download Debian installation image +- name: Create virtual disk for image +- name: Boot installation media with preseed +- name: Wait for installation completion +- name: Initialize base image + roles: + - role: ericomeehan.debian + - role: ericomeehan.ericomeehan +- name: Shut down base image diff --git a/qemu.yaml b/qemu.yaml index c820bc7..6347912 100644 --- a/qemu.yaml +++ b/qemu.yaml @@ -1,28 +1,20 @@ --- -# Playbook for QEMU -- name: Prepare virtualization environment - hosts: alpha-worker-0 +- name: Test QEMU + hosts: localhost become: true - vars: - qemu_network_networks: - - name: lan - bridge: br1 - interfaces: - - eno2np1 - use_dhcp: false - address: 10.0.0.2 - netmask: 255.255.255.0 - gateway: 10.0.0.254 - qemu_network_machines: - - name: nfs - ram_mb: 4096 + tasks: + - name: Deploy test vm + community.libvirt.virt: + name: test + state: running + persistent: true + memory: 4096 vcpus: 1 - networks: - - lan + os_type: linux disks: - - filename: nfs-vda - type: qcow2 - target_dev: vda - - filename: nfs-vdb - type: qcow2 - target_dev: vda + - name: test + size: 8 + format: qcow2 + cdrom: + - url: https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.7.0-amd64-netinst.iso + diff --git a/roles/ericomeehan.libvirt-factory b/roles/ericomeehan.libvirt-factory new file mode 120000 index 0000000..3066ea0 --- /dev/null +++ b/roles/ericomeehan.libvirt-factory @@ -0,0 +1 @@ +/home/eric/Desktop/ansible-role-libvirt-vm \ No newline at end of file diff --git a/roles/ericomeehan.nvidia_driver b/roles/ericomeehan.nvidia_driver index 8946eef..4b9534a 160000 --- a/roles/ericomeehan.nvidia_driver +++ b/roles/ericomeehan.nvidia_driver @@ -1 +1 @@ -Subproject commit 8946eefeb5442761edef6853665074e1306391a0 +Subproject commit 4b9534a27ef2c7a096f58959d9762647f524b96d diff --git a/templates/interfaces.j2 b/templates/interfaces.j2 new file mode 100644 index 0000000..3ab0513 --- /dev/null +++ b/templates/interfaces.j2 @@ -0,0 +1,21 @@ +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +source /etc/network/interfaces.d/* + +# The loopback network interface +auto lo +iface lo inet loopback + +# Libvirt networks +{% for network in libvirt_networks %} +{% if network.bridge.dev is defined %} +auto {{ network.bridge.dev }} +iface {{ network.bridge.dev }} inet manual + +auto {{ network.bridge.name }} +iface {{ network.bridge.name }} inet dhcp + bridge_ports {{ network.bridge.dev }} + +{% endif %} +{% endfor %} diff --git a/templates/libvirt-network.xml.j2 b/templates/libvirt-network.xml.j2 new file mode 100644 index 0000000..cc240fb --- /dev/null +++ b/templates/libvirt-network.xml.j2 @@ -0,0 +1,14 @@ + + {{ item.name }} + + {% if item.bridge.dev is defined %} + + {% else %} + + + + + + + {% endif %} + diff --git a/templates/libvirt-vm.xml.j2 b/templates/libvirt-vm.xml.j2 new file mode 100644 index 0000000..2835523 --- /dev/null +++ b/templates/libvirt-vm.xml.j2 @@ -0,0 +1,108 @@ + + {{ domain.name }} + {{ domain.memory.value }} + {{ domain.vcpu.value }} + + {{ domain.os.type.value }} + + + + + {{ domain.devices.emulator }} + {% if domain.devices.disks is defined %} + {% for disk in domain.devices.disks %} + + + {% if disk.source.protocol is defined %} + + + + {% elif disk.source.dev is defined %} + + {% else %} + + {% endif %} + + {% if disk.address is defined %} +
+ {% endif %} + + {% endfor %} + {% endif %} + {% if domain.filesystems is defined %} + {% for filesystem in domain.filesystems %} + + + + + {% endfor %} + {% endif %} + {% if domain.devices.interfaces is defined %} + {% for interface in domain.devices.interfaces %} + + + + {% if interface.address is defined %} +
+ {% endif %} + + {% endfor %} + {% endif %} + {% if domain.devices.channels is defined %} + {% for channel in domain.devices.channels %} + + + {% if channel.address is defined %} +
+ {% endif %} + + {% endfor %} + {% endif %} + {% if domain.devices.inputs is defined %} + {% for input in domain.devices.inputs %} + + {% if input.address is defined %} +
+ {% endif %} + + {% endfor %} + {% endif %} + {% if domain.devices.graphics is defined %} + + + + + {% endif %} + {% if domain.devices.video is defined %} +