From b8224b7a6a6e2ec396bd9c2587179878b1c220c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BENEDEK=20L=C3=A1szl=C3=B3?= Date: Mon, 23 Dec 2024 15:53:44 +0100 Subject: [PATCH] resolvconf --- inventory | 26 +++++++------- roles/nfs-storage/tasks/main.yml | 35 +++++++++++++++++++ roles/nfs-storage/templates/etc-exports.j2 | 1 + .../etc-systemd-system-mnt-storage.mount.j2 | 7 ++++ roles/node/defaults/main.yml | 5 +-- roles/node/handlers/main.yml | 8 ++--- roles/node/tasks/network.yml | 23 +++++++----- roles/node/templates/etc-resolv.conf.j2 | 3 ++ .../etc-systemd-network-20-lan0.network.j2 | 4 +-- 9 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 roles/nfs-storage/tasks/main.yml create mode 100644 roles/nfs-storage/templates/etc-exports.j2 create mode 100644 roles/nfs-storage/templates/etc-systemd-system-mnt-storage.mount.j2 create mode 100644 roles/node/templates/etc-resolv.conf.j2 diff --git a/inventory b/inventory index e2c90b5..219462f 100644 --- a/inventory +++ b/inventory @@ -1,22 +1,24 @@ [nodes] -192.168.50.1 -192.168.50.2 -192.168.50.3 -# 192.168.50.11 -# 192.168.50.12 -# 192.168.50.13 +# masters +192.168.50.41 +192.168.50.42 +192.168.50.43 +# workers +# 192.168.50.44 +# 192.168.50.45 +# 192.168.50.46 [master-primary] -192.168.50.1 +192.168.50.41 # do one at a time # the k3s service restarts # on the primary when a node joins [master-secondary] -192.168.50.2 -192.168.50.3 +192.168.50.42 +192.168.50.43 [workers] -# 192.168.50.11 -# 192.168.50.12 -# 192.168.50.13 +# 192.168.50.44 +# 192.168.50.45 +# 192.168.50.46 diff --git a/roles/nfs-storage/tasks/main.yml b/roles/nfs-storage/tasks/main.yml new file mode 100644 index 0000000..71e6014 --- /dev/null +++ b/roles/nfs-storage/tasks/main.yml @@ -0,0 +1,35 @@ +- name: Install packages + ansible.builtin.apt: + name: "{{ item }}" + state: present + install_recommends: false + loop: "nfs-kernel-server rpcbind" + +- name: Check the disk for existing partitions + ansible.builtin.stat: + path: "{{ storage_disk }}1" + register: partition_exists + +- name: Format disk + community.general.filesystem: + fstype: "{{ fs_type }}" + dev: "{{ storage_disk }}" + when: not partition_exists + +- name: Create mount + ansible.builtin.template: + src: etc-systemd-system-mnt-storage.mount.j2 + dest: "/etc/systemd/system/mnt-{{ mount_path }}.mount" + mode: "0644" + +- name: Enable mount + ansible.builtin.systemd_service: + name: "mnt-{{ mount_path }}.mount" + state: started + enabled: true + +- name: Setup nfs-server + ansible.builtin.template: + src: etc-exports.j2 + dest: /etc/exports + mode: "0644" diff --git a/roles/nfs-storage/templates/etc-exports.j2 b/roles/nfs-storage/templates/etc-exports.j2 new file mode 100644 index 0000000..e91bc60 --- /dev/null +++ b/roles/nfs-storage/templates/etc-exports.j2 @@ -0,0 +1 @@ +/mnt/cluster rw,no_root_squash \ No newline at end of file diff --git a/roles/nfs-storage/templates/etc-systemd-system-mnt-storage.mount.j2 b/roles/nfs-storage/templates/etc-systemd-system-mnt-storage.mount.j2 new file mode 100644 index 0000000..50f1cf9 --- /dev/null +++ b/roles/nfs-storage/templates/etc-systemd-system-mnt-storage.mount.j2 @@ -0,0 +1,7 @@ +[Unit] +Description=mount {{ storage_disk }} at {{ mount_path }} + +[Mount] +Where={{ mount_path }} +What={{ storage_disk }}1 +Type={{ fs_type }} diff --git a/roles/node/defaults/main.yml b/roles/node/defaults/main.yml index 5847047..f9341d6 100644 --- a/roles/node/defaults/main.yml +++ b/roles/node/defaults/main.yml @@ -1,9 +1,6 @@ packages: - nfs-common - curl - - systemd-resolved # needs to be the last one - # breaks dns resolution until - # systemd-networkd is configured # hostsnames: # - ip: x.x.x.x @@ -13,6 +10,6 @@ hostnames: [] interface_name: lan0 gateway: "192.168.50.254" -dns_servers: +nameservers: - "192.168.11.1" - "1.1.1.1" diff --git a/roles/node/handlers/main.yml b/roles/node/handlers/main.yml index c0c6030..4d5e24f 100644 --- a/roles/node/handlers/main.yml +++ b/roles/node/handlers/main.yml @@ -6,7 +6,7 @@ cmd: > update-initramfs -k all -u -- name: Warn user to reboot - ansible.builtin.set_fact: - user_notify: Reboot the machine to use the new name for primary interface! - when: systemd_networkd_ifname is changed +- name: Reboot + listen: + - reboot + ansible.builtin.reboot: diff --git a/roles/node/tasks/network.yml b/roles/node/tasks/network.yml index e9c69d1..b48f479 100644 --- a/roles/node/tasks/network.yml +++ b/roles/node/tasks/network.yml @@ -1,25 +1,32 @@ +- name: Check if default interface is configured + ansible.builtin.set_fact: + interface_configured: "{{ interface_name in ansible_interfaces }}" + - name: Configure default interface name ansible.builtin.template: src: etc-systemd-network-10-lan0.link.j2 dest: /etc/systemd/network/10-lan0.link mode: "0644" - register: systemd_networkd_ifname + notify: + - update initramfs + - reboot + when: not interface_configured - name: Configure network for default interface ansible.builtin.template: src: etc-systemd-network-20-lan0.network.j2 dest: /etc/systemd/network/20-lan0.network mode: "0644" - notify: update initramfs + when: not interface_configured + +- name: Configure nameservers + ansible.builtin.template: + src: etc-resolv.conf.j2 + dest: /etc/resolv.conf + mode: "0644" - name: Enable systemd-networkd ansible.builtin.systemd_service: name: systemd-networkd enabled: true state: restarted - -- name: Enable systemd-resolved - ansible.builtin.systemd_service: - name: systemd-resolved - enabled: true - state: restarted diff --git a/roles/node/templates/etc-resolv.conf.j2 b/roles/node/templates/etc-resolv.conf.j2 new file mode 100644 index 0000000..a3e6d7c --- /dev/null +++ b/roles/node/templates/etc-resolv.conf.j2 @@ -0,0 +1,3 @@ +{% for nameserver in nameservers %} +nameserver {{ nameserver }} +{% endfor %} \ No newline at end of file diff --git a/roles/node/templates/etc-systemd-network-20-lan0.network.j2 b/roles/node/templates/etc-systemd-network-20-lan0.network.j2 index 2369054..4427bc0 100644 --- a/roles/node/templates/etc-systemd-network-20-lan0.network.j2 +++ b/roles/node/templates/etc-systemd-network-20-lan0.network.j2 @@ -4,6 +4,6 @@ Name={{ interface_name }} [Network] Address={{ ansible_default_ipv4.address|default(ansible_all_ipv4_addresses[0]) }}/24 Gateway={{ gateway }} -{% for dns in dns_servers %} -DNS={{ dns }} +{% for nameserver in nameservers %} +DNS={{ nameserver }} {% endfor %}