Commit 6201647b authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos Committed by Kristian Klausen
Browse files

New shared networking role.



This is shared between common and install_arch roles

Closed: #288
Signed-off-by: Leonidas Spyropoulos's avatarLeonidas Spyropoulos <artafinde@gmail.com>
parent 208a5339
---
configure_network: 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
systemd:
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
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:
......
......@@ -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
......
../../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
......@@ -10,6 +10,7 @@ Wants=systemd-networkd.service
[Service]
ExecStart=/usr/local/bin/hcloud-init
Type=oneshot
RemainAfterExit=yes
StandardOutput=journal
StandardError=journal
......
---
- name: restart networkd
systemd:
name: systemd-networkd
state: restarted
daemon_reload: true
when: chroot_path | length == 0
---
- 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: 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 owner=root group=root mode=0644
- 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment