Skip to content
Snippets Groups Projects
Commit 1f2203c4 authored by Kristian Klausen's avatar Kristian Klausen :tada:
Browse files

Merge branch 'networking-role' into 'master'

New networking role shared.

Closes #288

See merge request !355
parents 208a5339 a8369f31
No related branches found
No related tags found
1 merge request!355New networking role shared.
Pipeline #10043 passed
Showing
with 61 additions and 73 deletions
...@@ -8,7 +8,6 @@ ipv6_netmask: "/128" ...@@ -8,7 +8,6 @@ ipv6_netmask: "/128"
ipv4_gateway: "49.12.124.65" ipv4_gateway: "49.12.124.65"
ipv6_gateway: "fe80::1" ipv6_gateway: "fe80::1"
filesystem: "btrfs" filesystem: "btrfs"
network_interface: "en*"
system_disks: system_disks:
- /dev/sda - /dev/sda
- /dev/sdb - /dev/sdb
......
...@@ -10,6 +10,5 @@ fail2ban_jails: ...@@ -10,6 +10,5 @@ fail2ban_jails:
ipv4_address: "95.216.189.61" ipv4_address: "95.216.189.61"
ipv6_address: "2a01:4f9:c010:3052::1" ipv6_address: "2a01:4f9:c010:3052::1"
dns_servers: ["127.0.0.1"]
wireguard_address: 10.0.0.14 wireguard_address: 10.0.0.14
wireguard_public_key: +RJ/ZNRmw2uCHxSjJZHftk7lWUl5nJ6VSZww8GPwhEI= wireguard_public_key: +RJ/ZNRmw2uCHxSjJZHftk7lWUl5nJ6VSZww8GPwhEI=
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
hostname: "archlinux-packer" hostname: "archlinux-packer"
dhcp: true dhcp: true
network_interface: "en*"
filesystem: btrfs filesystem: btrfs
system_disks: system_disks:
- /dev/sda - /dev/sda
...@@ -8,7 +8,6 @@ ipv6_netmask: "/128" ...@@ -8,7 +8,6 @@ ipv6_netmask: "/128"
ipv4_gateway: "116.202.134.129" ipv4_gateway: "116.202.134.129"
ipv6_gateway: "fe80::1" ipv6_gateway: "fe80::1"
filesystem: "btrfs" filesystem: "btrfs"
network_interface: "en*"
system_disks: system_disks:
- /dev/nvme0n1 - /dev/nvme0n1
- /dev/nvme1n1 - /dev/nvme1n1
......
--- ---
configure_network: false configure_network: false
enable_zram_swap: false enable_zram_swap: false
network_interface: "e*"
dns_servers: []
--- ---
- name: restart networkd
systemd:
name: systemd-networkd
state: restarted
daemon_reload: true
- name: restart journald - name: restart journald
systemd: systemd:
name: systemd-journald name: systemd-journald
......
--- ---
- name: set fact for local dns resolver in use
set_fact:
host_has_local_dns_resolver: "{{ dns_servers|length == 1 and '127.0.0.1' in dns_servers }}"
- name: install inetutils for hostname - name: install inetutils for hostname
pacman: name=inetutils state=present pacman: name=inetutils state=present
...@@ -63,32 +59,10 @@ ...@@ -63,32 +59,10 @@
- name: generate ssh key for root - name: generate ssh key for root
command: ssh-keygen -b 4096 -N "" -f /root/.ssh/id_rsa creates="/root/.ssh/id_rsa" command: ssh-keygen -b 4096 -N "" -f /root/.ssh/id_rsa creates="/root/.ssh/id_rsa"
- name: configure network - name: configure networking
template: src=10-static-ethernet.network.j2 dest=/etc/systemd/network/10-static-ethernet.network owner=root group=root mode=0644 include_role:
notify: name: networking
- restart networkd
when: configure_network
- name: create symlink to resolv.conf
file: src=/run/systemd/resolve/stub-resolv.conf dest=/etc/resolv.conf state=link force=yes owner=root group=root mode=0755
when: configure_network and not host_has_local_dns_resolver
- name: create resolv.conf
template: src=resolv.conf.j2 dest=/etc/resolv.conf owner=root group=root mode=0644
when: configure_network and host_has_local_dns_resolver
- name: start networkd
service: name=systemd-networkd state=started enabled=yes
when: configure_network
- name: start resolved
service:
name: systemd-resolved
state: "{{'stopped' if host_has_local_dns_resolver else 'started'}}"
enabled: "{{'no' if host_has_local_dns_resolver else 'yes'}}"
when: configure_network when: configure_network
tags:
- this
- name: configure tcp receive window limits - name: configure tcp receive window limits
sysctl: sysctl:
......
---
network_interface: "e*"
dns_servers: []
...@@ -122,27 +122,11 @@ ...@@ -122,27 +122,11 @@
register: chroot_mkinitcpio register: chroot_mkinitcpio
changed_when: "chroot_mkinitcpio.rc == 0" changed_when: "chroot_mkinitcpio.rc == 0"
- name: configure network (static) - name: configure networking
template: src=10-static-ethernet.network.j2 dest=/mnt/etc/systemd/network/10-static-ethernet.network owner=root group=root mode=0644 include_role:
when: not dhcp|default(false) name: networking
vars:
- name: configure network (dhcp) chroot_path: "/mnt"
template: src=10-dhcp-ethernet.network.j2 dest=/mnt/etc/systemd/network/10-dhcp-ethernet.network owner=root group=root mode=0644
when: dhcp|default(false)
- name: install hcloud-init
copy: src=hcloud-init dest=/mnt/usr/local/bin/hcloud-init owner=root group=root mode=0755
when: "'hcloud' in group_names or inventory_hostname == 'packer-base-image'"
- name: install hcloud-init.service
copy: src=hcloud-init.service dest=/mnt/etc/systemd/system/hcloud-init.service owner=root group=root mode=0644
when: "'hcloud' in group_names or inventory_hostname == 'packer-base-image'"
- name: enable hcloud-init inside chroot
command: chroot /mnt systemctl enable hcloud-init
register: chroot_systemd_services
changed_when: "chroot_systemd_services.rc == 0"
when: "'hcloud' in group_names or inventory_hostname == 'packer-base-image'"
- name: provide default mount options (btrfs) - name: provide default mount options (btrfs)
lineinfile: lineinfile:
...@@ -180,9 +164,6 @@ ...@@ -180,9 +164,6 @@
- name: configure sshd - name: configure sshd
template: src=sshd_config.j2 dest=/mnt/etc/ssh/sshd_config owner=root group=root mode=0644 template: src=sshd_config.j2 dest=/mnt/etc/ssh/sshd_config owner=root group=root mode=0644
- name: create symlink to resolv.conf
file: src=/run/systemd/resolve/stub-resolv.conf dest=/mnt/etc/resolv.conf state=link force=yes owner=root group=root mode=0644
- name: clean pacman cache - name: clean pacman cache
command: yes | chroot /mnt pacman -Scc command: yes | chroot /mnt pacman -Scc
register: chroot_pacman_clean_cache register: chroot_pacman_clean_cache
......
../../common/templates/10-dhcp-ethernet.network.j2
\ No newline at end of file
../../common/templates/10-static-ethernet.network.j2
\ No newline at end of file
---
chroot_path: ""
network_interface: "en*"
...@@ -10,6 +10,7 @@ Wants=systemd-networkd.service ...@@ -10,6 +10,7 @@ Wants=systemd-networkd.service
[Service] [Service]
ExecStart=/usr/local/bin/hcloud-init ExecStart=/usr/local/bin/hcloud-init
Type=oneshot Type=oneshot
RemainAfterExit=yes
StandardOutput=journal StandardOutput=journal
StandardError=journal StandardError=journal
......
---
- name: restart networkd
systemd:
name: systemd-networkd
state: restarted
daemon_reload: true
when: chroot_path | length == 0
---
- name: configure network (static)
template: src=10-static-ethernet.network.j2 dest={{ chroot_path }}/etc/systemd/network/10-static-ethernet.network owner=root group=root mode=0644
notify:
- restart networkd
when: not dhcp|default(false)
- name: configure network (dhcp)
template: src=10-dhcp-ethernet.network.j2 dest={{ chroot_path }}/etc/systemd/network/10-dhcp-ethernet.network owner=root group=root mode=0644
notify:
- restart networkd
when: dhcp|default(false)
- name: create symlink to resolv.conf
file: src=/run/systemd/resolve/stub-resolv.conf dest={{ chroot_path }}/etc/resolv.conf state=link force=yes follow=no owner=root group=root
- name: install hcloud-init
copy: src=hcloud-init dest={{ chroot_path }}/usr/local/bin/hcloud-init owner=root group=root mode=0755
when: "'hcloud' in group_names or inventory_hostname == 'packer-base-image'"
- name: install hcloud-init.service
copy: src=hcloud-init.service dest={{ chroot_path }}/etc/systemd/system/hcloud-init.service owner=root group=root mode=0644
when: "'hcloud' in group_names or inventory_hostname == 'packer-base-image'"
- name: enable hcloud-init inside chroot
command: chroot {{ chroot_path }} systemctl enable hcloud-init
register: chroot_systemd_services
changed_when: "chroot_systemd_services.rc == 0"
when: chroot_path | length != 0 and ("'hcloud' in group_names or inventory_hostname == 'packer-base-image'")
- name: start and enable hcloud-init
service: name=hcloud-init daemon_reload=yes state=started enabled=yes
when: chroot_path | length == 0
- name: start and enable networkd
service: name=systemd-networkd state=started enabled=yes
when: chroot_path | length == 0
- name: start and enable resolved
service: name=systemd-resolved state=started enabled=yes
when: chroot_path | length == 0
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
Name={{ network_interface }} Name={{ network_interface }}
[Network] [Network]
{% for server in dns_servers %}
DNS={{server}}
{% endfor %}
Gateway={{ ipv4_gateway }} Gateway={{ ipv4_gateway }}
{% if ipv6_gateway is defined %} {% if ipv6_gateway is defined %}
Gateway={{ ipv6_gateway }} Gateway={{ ipv6_gateway }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment