From 84a20416e31bb586042e12db84360bc58f49742b Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 10 Aug 2023 23:32:17 +1000 Subject: [PATCH] network and serial complete --- .../hv00_balsillie_house.yaml | 8 +++- ansible/playbooks/vp2420.yaml | 25 ++++++++++ .../roles/hypervisor_qcow/defaults/main.yaml | 6 +-- .../hypervisor_qcow/tasks/libvirt_dir.yaml | 8 ++++ ansible/roles/hypervisor_qcow/tasks/main.yaml | 46 ++++--------------- ansible/roles/serial_out/defaults/main.yaml | 5 ++ ansible/roles/serial_out/handlers/main.yaml | 6 +++ ansible/roles/serial_out/tasks/main.yaml | 27 +++++++++++ .../roles/systemd_networkd/defaults/main.yaml | 3 ++ .../roles/systemd_networkd/handlers/main.yaml | 9 ++++ .../roles/systemd_networkd/tasks/main.yaml | 39 ++++++++++++++++ .../templates/bond.netdev.j2 | 0 .../templates/bond.network.j2 | 0 .../templates/bridge.netdev.j2 | 0 .../templates/bridge.network.j2 | 0 .../templates/ethernet.link.j2 | 0 .../templates/ethernet.network.j2 | 0 .../templates/vlan.netdev.j2 | 0 .../templates/vlan.network.j2 | 0 19 files changed, 142 insertions(+), 40 deletions(-) create mode 100644 ansible/playbooks/vp2420.yaml create mode 100644 ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml create mode 100644 ansible/roles/serial_out/defaults/main.yaml create mode 100644 ansible/roles/serial_out/handlers/main.yaml create mode 100644 ansible/roles/serial_out/tasks/main.yaml create mode 100644 ansible/roles/systemd_networkd/defaults/main.yaml create mode 100644 ansible/roles/systemd_networkd/handlers/main.yaml create mode 100644 ansible/roles/systemd_networkd/tasks/main.yaml rename ansible/{playbooks => roles/systemd_networkd}/templates/bond.netdev.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/bond.network.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/bridge.netdev.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/bridge.network.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/ethernet.link.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/ethernet.network.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/vlan.netdev.j2 (100%) rename ansible/{playbooks => roles/systemd_networkd}/templates/vlan.network.j2 (100%) diff --git a/ansible/inventory/host_vars/hv00_balsillie_home/hv00_balsillie_house.yaml b/ansible/inventory/host_vars/hv00_balsillie_home/hv00_balsillie_house.yaml index 4aebf9c..16cfd74 100644 --- a/ansible/inventory/host_vars/hv00_balsillie_home/hv00_balsillie_house.yaml +++ b/ansible/inventory/host_vars/hv00_balsillie_home/hv00_balsillie_house.yaml @@ -82,4 +82,10 @@ systemd_networkd_configs: - 10.192.110.254 qemu_bridges: - br0 + - br0 + +hypervisor: + storage: dir + device: /dev/sda + +console_device: ttyS0 \ No newline at end of file diff --git a/ansible/playbooks/vp2420.yaml b/ansible/playbooks/vp2420.yaml new file mode 100644 index 0000000..6be26e0 --- /dev/null +++ b/ansible/playbooks/vp2420.yaml @@ -0,0 +1,25 @@ +--- + +# Arch install bare metal + +# Systemd networking + +- name: Setup systemd-networkd + hosts: hv00_balsillie_house + become: true + roles: + - name: systemd_networkd + vars: + ansible_host: # TODO add temp address + +# Serial console + +- name: Setup serial console + hosts: hv00_balsillie_house + become: true + roles: + - name: serial_console + +# Hypervisor setup + +# VM setup \ No newline at end of file diff --git a/ansible/roles/hypervisor_qcow/defaults/main.yaml b/ansible/roles/hypervisor_qcow/defaults/main.yaml index 24b2094..cda758f 100644 --- a/ansible/roles/hypervisor_qcow/defaults/main.yaml +++ b/ansible/roles/hypervisor_qcow/defaults/main.yaml @@ -7,6 +7,6 @@ libvirt_packages: libvirt libvirt-python -default_network_services: - Archlinux: - NetworkManager \ No newline at end of file +hypervisor: + storage: dir + device: /dev/sda \ No newline at end of file diff --git a/ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml b/ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml new file mode 100644 index 0000000..8665fff --- /dev/null +++ b/ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml @@ -0,0 +1,8 @@ +--- + +- name: Format and mount the libvirt disk if it is not root + when: hypervisor.device not in (ansible_mounts | json_query('[?mount == `/`].device')) + ansible.builtin.include_tasks: + file: libvirt_mount.yaml + + \ No newline at end of file diff --git a/ansible/roles/hypervisor_qcow/tasks/main.yaml b/ansible/roles/hypervisor_qcow/tasks/main.yaml index 10d9bd8..b6ff939 100644 --- a/ansible/roles/hypervisor_qcow/tasks/main.yaml +++ b/ansible/roles/hypervisor_qcow/tasks/main.yaml @@ -1,41 +1,5 @@ --- -- 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: @@ -74,3 +38,13 @@ community.libvirt.virt_net: name: default state: absent + +- name: Setup libvirt storage (qcow) + when: hypervisor.storage == 'dir' + ansible.builtin.include_tasks: + file: libvirt_dir.yaml + +- name: Setup libvirt storage (zfs) + when: hypervisor.storage == 'zfs' + ansible.builtin.include_tasks: + file: libvirt_zfs.yaml diff --git a/ansible/roles/serial_out/defaults/main.yaml b/ansible/roles/serial_out/defaults/main.yaml new file mode 100644 index 0000000..5adbb9a --- /dev/null +++ b/ansible/roles/serial_out/defaults/main.yaml @@ -0,0 +1,5 @@ +console_packages: + Archlinux: + - util-linux + +console_device: ttyS0 \ No newline at end of file diff --git a/ansible/roles/serial_out/handlers/main.yaml b/ansible/roles/serial_out/handlers/main.yaml new file mode 100644 index 0000000..951e5ac --- /dev/null +++ b/ansible/roles/serial_out/handlers/main.yaml @@ -0,0 +1,6 @@ +--- + +- name: Run mkinitcpio + ansible.builtin.command: + cmd: mkinitcpio -p linux + changed_when: true diff --git a/ansible/roles/serial_out/tasks/main.yaml b/ansible/roles/serial_out/tasks/main.yaml new file mode 100644 index 0000000..72ea8a2 --- /dev/null +++ b/ansible/roles/serial_out/tasks/main.yaml @@ -0,0 +1,27 @@ +--- + +# - name: Set serial output for boot loader + +- name: Add command line option for mkinitcpio config + when: ansible_distribution == 'Archlinux' + ansible.builtin.copy: + dest: /etc/cmdline.d/console.conf + content: "console={{ console_device }},115200" + owner: root + group: root + mode: '0664' + notify: + - Run mkinitcpio + +- name: Install getty provider package (Archlinux) + when: ansible_distribution == 'Archlinux' + community.general.pacman: + name: "{{ console_packages[ansible_os_family] }}" + state: present + update_cache: true + +- name: Enable the serial-getty service + ansible.builtin.service: + name: serial-getty@{{ console_device }}.service + enabled: true + state: started diff --git a/ansible/roles/systemd_networkd/defaults/main.yaml b/ansible/roles/systemd_networkd/defaults/main.yaml new file mode 100644 index 0000000..9aec84f --- /dev/null +++ b/ansible/roles/systemd_networkd/defaults/main.yaml @@ -0,0 +1,3 @@ +default_network_services: + Archlinux: + NetworkManager \ No newline at end of file diff --git a/ansible/roles/systemd_networkd/handlers/main.yaml b/ansible/roles/systemd_networkd/handlers/main.yaml new file mode 100644 index 0000000..0931ea5 --- /dev/null +++ b/ansible/roles/systemd_networkd/handlers/main.yaml @@ -0,0 +1,9 @@ +- name: Restart systemd-networkd + ansible.builtin.service: + name: systemd-networkd.service + state: restarted + +- name: Restart systemd-resolved + ansible.builtin.service: + name: systemd-resolved.service + state: restarted diff --git a/ansible/roles/systemd_networkd/tasks/main.yaml b/ansible/roles/systemd_networkd/tasks/main.yaml new file mode 100644 index 0000000..fdee12c --- /dev/null +++ b/ansible/roles/systemd_networkd/tasks/main.yaml @@ -0,0 +1,39 @@ +--- + +- 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 }}" + notify: + - Restart systemd-resolved + - Restart systemd-networkd + +- 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 }}" + enabled: true + loop: + - systemd-networkd + - systemd-resolved diff --git a/ansible/playbooks/templates/bond.netdev.j2 b/ansible/roles/systemd_networkd/templates/bond.netdev.j2 similarity index 100% rename from ansible/playbooks/templates/bond.netdev.j2 rename to ansible/roles/systemd_networkd/templates/bond.netdev.j2 diff --git a/ansible/playbooks/templates/bond.network.j2 b/ansible/roles/systemd_networkd/templates/bond.network.j2 similarity index 100% rename from ansible/playbooks/templates/bond.network.j2 rename to ansible/roles/systemd_networkd/templates/bond.network.j2 diff --git a/ansible/playbooks/templates/bridge.netdev.j2 b/ansible/roles/systemd_networkd/templates/bridge.netdev.j2 similarity index 100% rename from ansible/playbooks/templates/bridge.netdev.j2 rename to ansible/roles/systemd_networkd/templates/bridge.netdev.j2 diff --git a/ansible/playbooks/templates/bridge.network.j2 b/ansible/roles/systemd_networkd/templates/bridge.network.j2 similarity index 100% rename from ansible/playbooks/templates/bridge.network.j2 rename to ansible/roles/systemd_networkd/templates/bridge.network.j2 diff --git a/ansible/playbooks/templates/ethernet.link.j2 b/ansible/roles/systemd_networkd/templates/ethernet.link.j2 similarity index 100% rename from ansible/playbooks/templates/ethernet.link.j2 rename to ansible/roles/systemd_networkd/templates/ethernet.link.j2 diff --git a/ansible/playbooks/templates/ethernet.network.j2 b/ansible/roles/systemd_networkd/templates/ethernet.network.j2 similarity index 100% rename from ansible/playbooks/templates/ethernet.network.j2 rename to ansible/roles/systemd_networkd/templates/ethernet.network.j2 diff --git a/ansible/playbooks/templates/vlan.netdev.j2 b/ansible/roles/systemd_networkd/templates/vlan.netdev.j2 similarity index 100% rename from ansible/playbooks/templates/vlan.netdev.j2 rename to ansible/roles/systemd_networkd/templates/vlan.netdev.j2 diff --git a/ansible/playbooks/templates/vlan.network.j2 b/ansible/roles/systemd_networkd/templates/vlan.network.j2 similarity index 100% rename from ansible/playbooks/templates/vlan.network.j2 rename to ansible/roles/systemd_networkd/templates/vlan.network.j2