diff --git a/metal/group_vars/all/all.yml b/metal/group_vars/all/all.yml index 1c9fb20..852a1ab 100644 --- a/metal/group_vars/all/all.yml +++ b/metal/group_vars/all/all.yml @@ -1,5 +1,5 @@ ansible_ssh_private_key_file: ~/.ssh/id_rsa -ssh_public_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" +ssh_public_key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}" # Network config subnet: "192.168.6.0" diff --git a/metal/install-os.yml b/metal/install-os.yml index ccaf2ac..5c858d1 100644 --- a/metal/install-os.yml +++ b/metal/install-os.yml @@ -9,8 +9,13 @@ roles: - wol-wake -- name: Clean up playbook execution +- name: Clean up PXE environment hosts: localhost gather_facts: false roles: - - pxe-cleanup \ No newline at end of file + - pxe-cleanup + +- name: Configure networking + hosts: metal + roles: + - systemd-networkd \ No newline at end of file diff --git a/metal/inventories/lab.yml b/metal/inventories/lab.yml index e17d518..059098f 100644 --- a/metal/inventories/lab.yml +++ b/metal/inventories/lab.yml @@ -2,9 +2,25 @@ metal: children: masters: hosts: - lab-mini-1: {ansible_host: 192.168.6.21, mac: '4c:52:62:1c:bf:6c', disk: '/dev/sda'} - lab-mini-2: {ansible_host: 192.168.6.22, mac: '4c:52:62:0f:09:6d', disk: '/dev/sda'} - lab-mini-3: {ansible_host: 192.168.6.23, mac: '4c:52:62:0f:0a:23', disk: '/dev/sda'} + lab-mini-1: + ansible_host: 192.168.6.21 + mac: '4c:52:62:1c:bf:6c' + disk: '/dev/nvme0n1' + ansible_become_pass: '{{ vault_ansible_become_password }}' + lab-mini-2: + ansible_host: 192.168.6.22 + mac: '4c:52:62:0f:09:6d' + disk: '/dev/nvme0n1' + ansible_become_pass: '{{ vault_ansible_become_password }}' + lab-mini-3: + ansible_host: 192.168.6.23 + mac: '4c:52:62:0f:0a:23' + disk: '/dev/nvme0n1' + ansible_become_pass: '{{ vault_ansible_become_password }}' workers: hosts: - lab-mini-4: {ansible_host: 192.168.6.24, mac: '90:1b:0e:f8:e8:af', disk: '/dev/sda'} \ No newline at end of file + lab-mini-4: + ansible_host: 192.168.6.24 + mac: '90:1b:0e:f8:e8:af' + disk: '/dev/nvme0n1' + ansible_become_pass: '{{ vault_ansible_become_password }}' diff --git a/metal/roles/systemd-networkd/tasks/main.yaml b/metal/roles/systemd-networkd/tasks/main.yaml new file mode 100644 index 0000000..11aed8e --- /dev/null +++ b/metal/roles/systemd-networkd/tasks/main.yaml @@ -0,0 +1,28 @@ +- name: "Configure systemd-networkd" + become: true + block: + - name: "Render network config" + template: + src: default.network.j2 + dest: "/etc/systemd/network/default.network" + mode: 0644 + + - name: "Enable systemd-networkd" + ansible.builtin.systemd: + name: systemd-networkd + enabled: true + + - name: "Remove /etc/network" + ansible.builtin.file: + path: /etc/network + state: absent + + - name: "Reboot with systemd-networkd configured" + ansible.builtin.reboot: + reboot_timeout: 180 + + - name: "Remove ifupdown" + ansible.builtin.apt: + name: ifupdown + state: absent + purge: true \ No newline at end of file diff --git a/metal/roles/systemd-networkd/templates/default.network.j2 b/metal/roles/systemd-networkd/templates/default.network.j2 new file mode 100644 index 0000000..13187cd --- /dev/null +++ b/metal/roles/systemd-networkd/templates/default.network.j2 @@ -0,0 +1,7 @@ +[Match] +MACAddress={{ hostvars[inventory_hostname]['mac'] }} + +[Network] +Address={{ hostvars[inventory_hostname]['ansible_host'] }}/{{ (hostvars[inventory_hostname]['ansible_host'] + '/' + netmask) | ansible.utils.ipaddr('prefix') }} +Gateway={{ gateway }} +DNS={{ nameserver }} \ No newline at end of file