diff --git a/host_vars/gemini.archlinux.org/misc b/host_vars/gemini.archlinux.org/misc index 3eae8550fd69fc7ee92279a59c9f38025a39c35d..f92791e5b6a240528d3cef9e42df678caad60ea0 100644 --- a/host_vars/gemini.archlinux.org/misc +++ b/host_vars/gemini.archlinux.org/misc @@ -8,7 +8,6 @@ ipv6_netmask: "/128" ipv4_gateway: "49.12.124.65" ipv6_gateway: "fe80::1" filesystem: "btrfs" -network_interface: "en*" system_disks: - /dev/sda - /dev/sdb diff --git a/host_vars/mail.archlinux.org/misc b/host_vars/mail.archlinux.org/misc index b33a2e7e13a426ca13358a9fb8faf78a66733ed6..59af3f7a6eab2b0da394496ab0f99c1aac9d8b32 100644 --- a/host_vars/mail.archlinux.org/misc +++ b/host_vars/mail.archlinux.org/misc @@ -10,6 +10,5 @@ fail2ban_jails: ipv4_address: "95.216.189.61" ipv6_address: "2a01:4f9:c010:3052::1" -dns_servers: ["127.0.0.1"] wireguard_address: 10.0.0.14 wireguard_public_key: +RJ/ZNRmw2uCHxSjJZHftk7lWUl5nJ6VSZww8GPwhEI= diff --git a/host_vars/packer-base-image b/host_vars/packer-base-image index a333b739ae482ba915f0a6aafc56dc57ba2da1a5..29cd7e8df52899559855e99570d0bd019f5d9ec4 100644 --- a/host_vars/packer-base-image +++ b/host_vars/packer-base-image @@ -2,7 +2,6 @@ hostname: "archlinux-packer" dhcp: true -network_interface: "en*" filesystem: btrfs system_disks: - /dev/sda diff --git a/host_vars/secure-runner1.archlinux.org/misc b/host_vars/secure-runner1.archlinux.org/misc index d7bd5a2e2d2f92eb8e9affac10663799bcafecf5..8dd2ec7ac388d924c7087ddfd0b376b680ba3f1f 100644 --- a/host_vars/secure-runner1.archlinux.org/misc +++ b/host_vars/secure-runner1.archlinux.org/misc @@ -8,7 +8,6 @@ ipv6_netmask: "/128" ipv4_gateway: "116.202.134.129" ipv6_gateway: "fe80::1" filesystem: "btrfs" -network_interface: "en*" system_disks: - /dev/nvme0n1 - /dev/nvme1n1 diff --git a/roles/common/defaults/main.yml b/roles/common/defaults/main.yml index 0760ecf91b273da0151ce1815ae6f02e2b984605..ee917a2f5e956259d7cf4c8318f0138ef0426c33 100644 --- a/roles/common/defaults/main.yml +++ b/roles/common/defaults/main.yml @@ -1,5 +1,3 @@ --- configure_network: false enable_zram_swap: false -network_interface: "e*" -dns_servers: [] diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml index a55336f43169d8a9e89740c9676b9612e1d6f672..27008abdcaed38ae448e10d295f8c18c25709257 100644 --- a/roles/common/handlers/main.yml +++ b/roles/common/handlers/main.yml @@ -1,11 +1,5 @@ --- -- name: restart networkd - systemd: - name: systemd-networkd - state: restarted - daemon_reload: true - - name: restart journald systemd: name: systemd-journald diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 11b4e884dfe35d3a62622f148eebdfab781f6705..b6a5e35a4d5917baca3a2e962ed9d2a2a17856da 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,9 +1,5 @@ --- -- 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 pacman: name=inetutils state=present @@ -63,32 +59,10 @@ - name: generate ssh key for root command: ssh-keygen -b 4096 -N "" -f /root/.ssh/id_rsa creates="/root/.ssh/id_rsa" -- name: configure network - template: src=10-static-ethernet.network.j2 dest=/etc/systemd/network/10-static-ethernet.network owner=root group=root mode=0644 - notify: - - 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'}}" +- name: configure networking + include_role: + name: networking when: configure_network - tags: - - this - name: configure tcp receive window limits sysctl: diff --git a/roles/install_arch/defaults/main.yml b/roles/install_arch/defaults/main.yml deleted file mode 100644 index f04986c3543552dfecbecac209fad6ed6236bce0..0000000000000000000000000000000000000000 --- a/roles/install_arch/defaults/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -network_interface: "e*" -dns_servers: [] diff --git a/roles/install_arch/tasks/main.yml b/roles/install_arch/tasks/main.yml index 2f416a5d3d1c066ad13ea0637bb8679567697683..bf8c3838a8ca5f95263be2e0ec533139909dfc5a 100644 --- a/roles/install_arch/tasks/main.yml +++ b/roles/install_arch/tasks/main.yml @@ -122,27 +122,11 @@ register: chroot_mkinitcpio changed_when: "chroot_mkinitcpio.rc == 0" -- name: configure network (static) - template: src=10-static-ethernet.network.j2 dest=/mnt/etc/systemd/network/10-static-ethernet.network owner=root group=root mode=0644 - when: not dhcp|default(false) - -- name: configure network (dhcp) - 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: configure networking + include_role: + name: networking + vars: + chroot_path: "/mnt" - name: provide default mount options (btrfs) lineinfile: @@ -180,9 +164,6 @@ - name: configure sshd 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 command: yes | chroot /mnt pacman -Scc register: chroot_pacman_clean_cache diff --git a/roles/install_arch/templates/10-dhcp-ethernet.network.j2 b/roles/install_arch/templates/10-dhcp-ethernet.network.j2 deleted file mode 120000 index a152d98ea42e3f102f1fcd04590a1bbd7f0ca5f8..0000000000000000000000000000000000000000 --- a/roles/install_arch/templates/10-dhcp-ethernet.network.j2 +++ /dev/null @@ -1 +0,0 @@ -../../common/templates/10-dhcp-ethernet.network.j2 \ No newline at end of file diff --git a/roles/install_arch/templates/10-static-ethernet.network.j2 b/roles/install_arch/templates/10-static-ethernet.network.j2 deleted file mode 120000 index d73e3a3b2dfe323519561a0ac57de85658c9b6de..0000000000000000000000000000000000000000 --- a/roles/install_arch/templates/10-static-ethernet.network.j2 +++ /dev/null @@ -1 +0,0 @@ -../../common/templates/10-static-ethernet.network.j2 \ No newline at end of file diff --git a/roles/networking/defaults/main.yml b/roles/networking/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..fbd1d6f54d359e89fe5b97ddf67e08f5033e66ef --- /dev/null +++ b/roles/networking/defaults/main.yml @@ -0,0 +1,3 @@ +--- +chroot_path: "" +network_interface: "en*" diff --git a/roles/install_arch/files/hcloud-init b/roles/networking/files/hcloud-init similarity index 100% rename from roles/install_arch/files/hcloud-init rename to roles/networking/files/hcloud-init diff --git a/roles/install_arch/files/hcloud-init.service b/roles/networking/files/hcloud-init.service similarity index 95% rename from roles/install_arch/files/hcloud-init.service rename to roles/networking/files/hcloud-init.service index 54d433f50381547c20ebc5222699c055c2b2b398..a293cedb60621d810cae063d1f8113b9f19af2e0 100644 --- a/roles/install_arch/files/hcloud-init.service +++ b/roles/networking/files/hcloud-init.service @@ -10,6 +10,7 @@ Wants=systemd-networkd.service [Service] ExecStart=/usr/local/bin/hcloud-init Type=oneshot +RemainAfterExit=yes StandardOutput=journal StandardError=journal diff --git a/roles/networking/handlers/main.yml b/roles/networking/handlers/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..ebbc6ef0ca904cf75932d1952d641b43a416532f --- /dev/null +++ b/roles/networking/handlers/main.yml @@ -0,0 +1,8 @@ +--- + +- name: restart networkd + systemd: + name: systemd-networkd + state: restarted + daemon_reload: true + when: chroot_path | length == 0 diff --git a/roles/networking/tasks/main.yml b/roles/networking/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..843f1a8cfcd5808eb58b1b9dad6ccf3309ca2efe --- /dev/null +++ b/roles/networking/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- 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 diff --git a/roles/common/templates/10-dhcp-ethernet.network.j2 b/roles/networking/templates/10-dhcp-ethernet.network.j2 similarity index 100% rename from roles/common/templates/10-dhcp-ethernet.network.j2 rename to roles/networking/templates/10-dhcp-ethernet.network.j2 diff --git a/roles/common/templates/10-static-ethernet.network.j2 b/roles/networking/templates/10-static-ethernet.network.j2 similarity index 91% rename from roles/common/templates/10-static-ethernet.network.j2 rename to roles/networking/templates/10-static-ethernet.network.j2 index a2351104471558e0316c50f5b0e582f09277bd09..50cf9658560b15f4823654dccd761a714ffb7812 100644 --- a/roles/common/templates/10-static-ethernet.network.j2 +++ b/roles/networking/templates/10-static-ethernet.network.j2 @@ -2,9 +2,6 @@ Name={{ network_interface }} [Network] -{% for server in dns_servers %} -DNS={{server}} -{% endfor %} Gateway={{ ipv4_gateway }} {% if ipv6_gateway is defined %} Gateway={{ ipv6_gateway }} diff --git a/roles/common/templates/resolv.conf.j2 b/roles/networking/templates/resolv.conf.j2 similarity index 100% rename from roles/common/templates/resolv.conf.j2 rename to roles/networking/templates/resolv.conf.j2