From db2b3b7ee14f22b91d9f2279817866811c574515 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 12 May 2018 17:08:07 -0500 Subject: [PATCH 01/12] netplan systemd-networkd static support --- roles/2-common/tasks/packages.yml | 1 + roles/network/tasks/sysd-netd-debian.yml | 12 ++++++++++++ roles/network/templates/network/cloud-init.j2 | 11 +++++++++++ 3 files changed, 24 insertions(+) create mode 100644 roles/network/templates/network/cloud-init.j2 diff --git a/roles/2-common/tasks/packages.yml b/roles/2-common/tasks/packages.yml index 05c38f359..fdb840965 100644 --- a/roles/2-common/tasks/packages.yml +++ b/roles/2-common/tasks/packages.yml @@ -61,6 +61,7 @@ - bzip2 - i2c-tools - bridge-utils + - netmask - usbutils - hostapd - wget diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 68af9fc45..d536ef859 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -28,6 +28,18 @@ state: stopped when: is_ubuntu_18 +- name: Static IP computing CIDR + shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}' + when: wan_ip != "dhcp" + register: CIDR + +- name: Supply static template + template: + dest: /etc/netplan/50-cloud-init.yaml + src: network/cloud-init.j2 + backup: yes + when: wan_ip != "dhcp" + - name: Reload systemd systemd: daemon_reload: yes diff --git a/roles/network/templates/network/cloud-init.j2 b/roles/network/templates/network/cloud-init.j2 new file mode 100644 index 000000000..c0c95e48c --- /dev/null +++ b/roles/network/templates/network/cloud-init.j2 @@ -0,0 +1,11 @@ +network: + ethernets: + {{ iiab_wan_iface }}: + dhcp4: false + dhcp6: false + addresses: [{{ wan_ip }}/{{ CIDR.stdout }}] + gateway4: {{ wan_gateway }} + nameservers: + addresses: [{{ wan_nameserver }}] + optional: true + version: 2 From 1082dd2aa4956909dddb8aa3cc320f510685d363 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 12 May 2018 22:21:06 -0500 Subject: [PATCH 02/12] allow the console to back out of static --- roles/network/tasks/sysd-netd-debian.yml | 8 ++++++-- roles/network/templates/network/cloud-init.j2 | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index d536ef859..77b3243b1 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -33,12 +33,16 @@ when: wan_ip != "dhcp" register: CIDR +# ICO will always set gui_static_wan_ip away from the default of 'unset' while +# gui_static_wan turns dhcp on/off through wan_ip in computed_network and +# overrides gui_static_wan_ip that is present. Changing wan_ip in local_vars +# is a oneway street to static. - name: Supply static template template: dest: /etc/netplan/50-cloud-init.yaml src: network/cloud-init.j2 - backup: yes - when: wan_ip != "dhcp" + backup: no + when: wan_ip != "dhcp" or gui_static_wan_ip == "undefined" - name: Reload systemd systemd: diff --git a/roles/network/templates/network/cloud-init.j2 b/roles/network/templates/network/cloud-init.j2 index c0c95e48c..6032871e1 100644 --- a/roles/network/templates/network/cloud-init.j2 +++ b/roles/network/templates/network/cloud-init.j2 @@ -1,3 +1,4 @@ +{% if wan_ip != "dhcp" %} network: ethernets: {{ iiab_wan_iface }}: @@ -9,3 +10,12 @@ network: addresses: [{{ wan_nameserver }}] optional: true version: 2 +{% else %} +network: + ethernets: + {{ iiab_wan_iface }}: + addresses: [] + dhcp4: true + optional: true + version: 2 +{% endif %} From aad974777a20a9066d1721d46444472665ba5a2f Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 12 May 2018 22:28:24 -0500 Subject: [PATCH 03/12] needed for dhcp now --- roles/network/tasks/sysd-netd-debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 77b3243b1..d3fd3b95d 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -30,8 +30,8 @@ - name: Static IP computing CIDR shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}' - when: wan_ip != "dhcp" register: CIDR + when: wan_ip != "dhcp" or gui_static_wan_ip == "undefined" # ICO will always set gui_static_wan_ip away from the default of 'unset' while # gui_static_wan turns dhcp on/off through wan_ip in computed_network and From ff7022b563e83c047d4cbe4faa6ee575fe5444cf Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 12 May 2018 23:10:41 -0500 Subject: [PATCH 04/12] get rid of the stall with 'dhcp' --- roles/network/defaults/main.yml | 1 + roles/network/tasks/sysd-netd-debian.yml | 7 ++++++- roles/network/templates/network/cloud-init.j2 | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/roles/network/defaults/main.yml b/roles/network/defaults/main.yml index 76c0a14ad..4524918df 100644 --- a/roles/network/defaults/main.yml +++ b/roles/network/defaults/main.yml @@ -4,6 +4,7 @@ wireless_lan_present: False strict_networking: False iiab_demo_mode: False gui_static_wan: False +wan_cidr: # Set defaults for discovery process as strings wifi1: "not found-1" diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index d3fd3b95d..dee106845 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -31,7 +31,12 @@ - name: Static IP computing CIDR shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}' register: CIDR - when: wan_ip != "dhcp" or gui_static_wan_ip == "undefined" + when: wan_ip != "dhcp" + +- name: Static IP setting CIDR + set_fact: + wan_cidr: "{{ CIDR.stdout }}" + when: wan_ip != "dhcp" # ICO will always set gui_static_wan_ip away from the default of 'unset' while # gui_static_wan turns dhcp on/off through wan_ip in computed_network and diff --git a/roles/network/templates/network/cloud-init.j2 b/roles/network/templates/network/cloud-init.j2 index 6032871e1..850c2ab40 100644 --- a/roles/network/templates/network/cloud-init.j2 +++ b/roles/network/templates/network/cloud-init.j2 @@ -4,7 +4,7 @@ network: {{ iiab_wan_iface }}: dhcp4: false dhcp6: false - addresses: [{{ wan_ip }}/{{ CIDR.stdout }}] + addresses: [{{ wan_ip }}/{{ wan_cidr }}] gateway4: {{ wan_gateway }} nameservers: addresses: [{{ wan_nameserver }}] From 72145ce13ebf884e5426ec9e7a3a92ff46fba75b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 10:56:55 -0500 Subject: [PATCH 05/12] update template to match distro --- roles/network/templates/network/cloud-init.j2 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/roles/network/templates/network/cloud-init.j2 b/roles/network/templates/network/cloud-init.j2 index 850c2ab40..32fc6f7d0 100644 --- a/roles/network/templates/network/cloud-init.j2 +++ b/roles/network/templates/network/cloud-init.j2 @@ -2,12 +2,14 @@ network: ethernets: {{ iiab_wan_iface }}: - dhcp4: false - dhcp6: false - addresses: [{{ wan_ip }}/{{ wan_cidr }}] + addresses: + - {{ wan_ip }}/{{ wan_cidr }} gateway4: {{ wan_gateway }} nameservers: - addresses: [{{ wan_nameserver }}] + addresses: + - {{ wan_nameserver }} + search: + - {{ iiab_domain }} optional: true version: 2 {% else %} From 90ffdb9f694208b254d5b74f7eb88d800de59441 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 11:43:42 -0500 Subject: [PATCH 06/12] netplan file change only for ubuntu-18 --- roles/network/tasks/sysd-netd-debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index dee106845..0eae56ea2 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -47,7 +47,7 @@ dest: /etc/netplan/50-cloud-init.yaml src: network/cloud-init.j2 backup: no - when: wan_ip != "dhcp" or gui_static_wan_ip == "undefined" + when: (wan_ip != "dhcp" or gui_static_wan_ip == "undefined") and is_ubuntu_18 - name: Reload systemd systemd: From 506ce3ffd3b7b2e767633cd7489b76e819790277 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 15:24:19 -0500 Subject: [PATCH 07/12] debian-9 networking restart workaround --- roles/network/tasks/debian.yml | 5 +++++ roles/network/templates/network/debian-auto.j2 | 1 + 2 files changed, 6 insertions(+) create mode 100644 roles/network/templates/network/debian-auto.j2 diff --git a/roles/network/tasks/debian.yml b/roles/network/tasks/debian.yml index e2103047d..8830dcaa9 100644 --- a/roles/network/tasks/debian.yml +++ b/roles/network/tasks/debian.yml @@ -44,6 +44,11 @@ src=network/rpi.j2 when: is_rpi and iiab_lan_iface == "br0" +- name: Workaround auto issue on Debian-9 + template: dest=/etc/network/interfaces.d/patch_auto + src=network/debian-auto + when: iiab_wan_iface != "none" and is_debian_9 + - name: bind may be affected service: name={{ dns_service }} state=stopped when: named_install and dnsmasq_enabled diff --git a/roles/network/templates/network/debian-auto.j2 b/roles/network/templates/network/debian-auto.j2 new file mode 100644 index 000000000..3aaa4fde6 --- /dev/null +++ b/roles/network/templates/network/debian-auto.j2 @@ -0,0 +1 @@ +auto {{ iiab_wan_iface }} From 0c578c6a7d38afbad879e58fb3ea703b6545e7ac Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 16:11:02 -0500 Subject: [PATCH 08/12] debian-9 clear out interfaces when static ip --- roles/network/tasks/debian.yml | 7 +++++++ roles/network/templates/network/systemd.j2 | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/roles/network/tasks/debian.yml b/roles/network/tasks/debian.yml index 8830dcaa9..c5ffbadc9 100644 --- a/roles/network/tasks/debian.yml +++ b/roles/network/tasks/debian.yml @@ -49,6 +49,13 @@ src=network/debian-auto when: iiab_wan_iface != "none" and is_debian_9 +- name: Clearing out /etc/network/interfaces for static addresses (is_debian_9) + lineinfile: + state: absent + path: /etc/network/interfaces + regexp: "{{ iiab_wan_iface }}" + when: wan_ip != "dhcp" and iiab_wan_iface != "none" and is_debian_9 + - name: bind may be affected service: name={{ dns_service }} state=stopped when: named_install and dnsmasq_enabled diff --git a/roles/network/templates/network/systemd.j2 b/roles/network/templates/network/systemd.j2 index 9f9e143d6..9424d13e9 100644 --- a/roles/network/templates/network/systemd.j2 +++ b/roles/network/templates/network/systemd.j2 @@ -34,7 +34,7 @@ iface {{ iiab_wan_iface }} inet dhcp {% endif %} # end dhcp clients # static wan -{% if wan_ip != "dhcp" and dhcpcd_result != "enabled" and wan_in_interfaces == "false" %} +{% if wan_ip != "dhcp" and dhcpcd_result != "enabled" %} auto {{ iiab_wan_iface }} iface {{ iiab_wan_iface }} inet static address {{ wan_ip }} From e7fc6cc36de89a36993c5f58eebb4d5185f9a294 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 17:20:59 -0500 Subject: [PATCH 09/12] ensure we want to use dhcp in template --- roles/network/templates/network/systemd.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/network/systemd.j2 b/roles/network/templates/network/systemd.j2 index 9424d13e9..f5552e86d 100644 --- a/roles/network/templates/network/systemd.j2 +++ b/roles/network/templates/network/systemd.j2 @@ -27,7 +27,7 @@ iface br0 inet static {% if dhcpcd_result == "enabled" or wan_in_interfaces %} # client or user defined {% endif %} -{% if dhcpcd_result != "enabled" and not wan_in_interfaces %} +{% if dhcpcd_result != "enabled" and not wan_in_interfaces %} and wan_ip == "dhcp" #cover butt auto {{ iiab_wan_iface }} iface {{ iiab_wan_iface }} inet dhcp From 450a3468394acc74ef127870d06c332722b7a393 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 20:50:37 -0500 Subject: [PATCH 10/12] NetworkManager support for wan static ip address --- roles/network/tasks/NM-debian.yml | 34 ++++++++++++++++++++ roles/network/templates/network/NM-static.j2 | 20 ++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 roles/network/templates/network/NM-static.j2 diff --git a/roles/network/tasks/NM-debian.yml b/roles/network/tasks/NM-debian.yml index 72f91683d..0c095a4bb 100644 --- a/roles/network/tasks/NM-debian.yml +++ b/roles/network/tasks/NM-debian.yml @@ -17,6 +17,7 @@ dest: /etc/NetworkManager/system-connections/ src: network/bridge-br0 mode: 0600 + when: iiab_network_mode != "Appliance" - name: Remove br0 in Appliance Mode for NetworkManager file: @@ -24,6 +25,39 @@ state: absent when: iiab_network_mode == "Appliance" +- name: Removing static for NetworkManager + file: + dest: /etc/NetworkManager/system-connections/iiab-static + state: absent + when: wan_ip == "dhcp" + +- name: Static IP computing CIDR + shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}' + register: CIDR + when: wan_ip != "dhcp" + +- name: Static IP setting CIDR + set_fact: + wan_cidr: "{{ CIDR.stdout }}" + when: wan_ip != "dhcp" + +- name: Create uuid for NM's keyfile store static + shell: uuidgen + register: uuid_response2 + when: wan_ip != "dhcp" + +- name: Put the uuid in place + set_fact: + gen_uuid2: "{{ uuid_response2.stdout_lines[0] }}" + when: wan_ip != "dhcp" + +- name: Copy static template for NetworkManager + template: + dest: /etc/NetworkManager/system-connections/iiab-static + src: network/NM-static.j2 + mode: 0600 + when: wan_ip != "dhcp" + - name: Stop wpa_supplicant service service: name: wpa_supplicant diff --git a/roles/network/templates/network/NM-static.j2 b/roles/network/templates/network/NM-static.j2 new file mode 100644 index 000000000..d7aa9c914 --- /dev/null +++ b/roles/network/templates/network/NM-static.j2 @@ -0,0 +1,20 @@ +[connection] +id=iiab-wan-static +uuid={{ gen_uuid2 }} +type=802-3-ethernet +interface-name={{ iiab_wan_device }} +permissions= + +[ipv4] +method=manual +dns={{ wan_nameserver }}; +dns-search={{ iiab_domain }}; +addresses1={{ wan_ip }};{{ wan_cidr }};{{ wan_gateway }}; +may-fail=true + +[802-3-ethernet] +duplex=full + +[ipv6] +method=link-local +may-fail=true From 7d0cfc0f93dccb70dd7528d6544eaf461ed5d344 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 13 May 2018 21:12:25 -0500 Subject: [PATCH 11/12] systemd-networkd support for wan static ip address --- roles/network/tasks/sysd-netd-debian.yml | 12 ++++++++++++ .../network/templates/network/systemd-static-net.j2 | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 roles/network/templates/network/systemd-static-net.j2 diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 0eae56ea2..ae5c17f34 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -49,6 +49,18 @@ backup: no when: (wan_ip != "dhcp" or gui_static_wan_ip == "undefined") and is_ubuntu_18 +- name: Remove static WAN template + file: + state: absent + dest: /etc/systemd/network/IIAB-Static.network + when: wan_ip == "dhcp" and not is_ubuntu_18 + +- name: Supply static WAN template + template: + dest: /etc/systemd/network/IIAB-Static.network + src: network/systemd-static-net.j2 + when: wan_ip != "dhcp" and not is_ubuntu_18 + - name: Reload systemd systemd: daemon_reload: yes diff --git a/roles/network/templates/network/systemd-static-net.j2 b/roles/network/templates/network/systemd-static-net.j2 new file mode 100644 index 000000000..64274f5e5 --- /dev/null +++ b/roles/network/templates/network/systemd-static-net.j2 @@ -0,0 +1,12 @@ +# /etc/systemd/network/IIAB-static.network +[Match] +Name={{ iiab_wan_iface }} + +[Network] +Address={{ wan_ip }}/{{ wan_cidr }} +Gateway={{ wan_gateway }} +LinkLocalAddressing=yes +DNS={{ wan_namserver }} +Domains={{ iiab_domain }} + + From 7f02aa573ff4be75e2aecad56077ca2131d3e4c7 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 14 May 2018 09:36:44 -0500 Subject: [PATCH 12/12] correct typo --- roles/network/templates/network/NM-static.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/network/NM-static.j2 b/roles/network/templates/network/NM-static.j2 index d7aa9c914..3669ed66c 100644 --- a/roles/network/templates/network/NM-static.j2 +++ b/roles/network/templates/network/NM-static.j2 @@ -2,7 +2,7 @@ id=iiab-wan-static uuid={{ gen_uuid2 }} type=802-3-ethernet -interface-name={{ iiab_wan_device }} +interface-name={{ iiab_wan_iface }} permissions= [ipv4]