Move configuration of servers completely to ansible
With this change we no longer use user-data scripts on the provided machines. That makes it way easier for me to handle all the configuration, since I only have to run ansible. Furthermore this the burdon to think what may went wrong, since ansible is easier to debug than some arbitrary scripts which run at provisioning-time on the machines. With this change I should also think about restructuring the code a bit as well. Since it's actually easier to provide the initial software-stack for the cluster via ansible than via terraform, at least as far as I can tell right now.
This commit is contained in:
3
k3s/roles/agent-setup/defaults/main.yml
Normal file
3
k3s/roles/agent-setup/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
dns_servers: 8.8.8.8 8.8.4.4
|
||||
network_config_path: /etc/systemd/network
|
||||
|
||||
4
k3s/roles/agent-setup/handlers/main.yml
Normal file
4
k3s/roles/agent-setup/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Restart resolved
|
||||
service:
|
||||
name: systemd-resolved
|
||||
state: restarted
|
||||
29
k3s/roles/agent-setup/tasks/main.yml
Normal file
29
k3s/roles/agent-setup/tasks/main.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
- name: Set default network route
|
||||
shell: "ip route add default via {{ private_nat }}"
|
||||
ignore_errors: "yes"
|
||||
when: ansible_facts['default_ipv4']['alias'] is not defined
|
||||
|
||||
- name: Regather facts
|
||||
setup:
|
||||
when: ansible_facts['default_ipv4']['alias'] is not defined
|
||||
|
||||
- name: Gather fact target_nic
|
||||
set_fact:
|
||||
target_nic: "{{ ansible_facts['default_ipv4']['alias'] }}"
|
||||
|
||||
- name: Ensure path to configure default route
|
||||
file:
|
||||
path: "{{ network_config_path }}"
|
||||
state: directory
|
||||
|
||||
- name: Configure default route
|
||||
template:
|
||||
src: nic.network.j2
|
||||
dest: "{{ network_config_path }}/10-{{target_nic}}.network"
|
||||
|
||||
- name: Configure DNS servers
|
||||
lineinfile:
|
||||
path: /etc/systemd/resolved.conf
|
||||
regexp: '^#?\s*DNS\s*=.*'
|
||||
line: "DNS={{ dns_servers }}"
|
||||
notify: "Restart resolved"
|
||||
5
k3s/roles/agent-setup/templates/nic.network.j2
Normal file
5
k3s/roles/agent-setup/templates/nic.network.j2
Normal file
@@ -0,0 +1,5 @@
|
||||
[Match]
|
||||
Name={{ target_nic }}
|
||||
[Network]
|
||||
DHCP=yes
|
||||
Gateway={{ private_nat }}
|
||||
Reference in New Issue
Block a user