From 6ed2bd7dd06e4e9f648cec524e2b7cb5d5d6ca86 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Thu, 8 Jul 2021 02:13:11 +0200 Subject: [PATCH] network config for raspy --- host_vars/rossum/networking.yml | 3 +- roles/networking/handlers/main.yml | 5 ++ roles/networking/tasks/main.yml | 10 ++++ .../templates/raspbian_dhcpcd.conf.j2 | 56 +++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 roles/networking/templates/raspbian_dhcpcd.conf.j2 diff --git a/host_vars/rossum/networking.yml b/host_vars/rossum/networking.yml index 4618905..0aa717a 100644 --- a/host_vars/rossum/networking.yml +++ b/host_vars/rossum/networking.yml @@ -4,8 +4,7 @@ interfaces: ipv4: 192.168.0.50 netmaskv4: 24 type: static - routes: - - {subnet: 0.0.0.0, netmask: 0, gateway: 10.0.2.1} + gateway: 10.0.2.1 wg0: ipv4: "{{ intranet.subnets.physical.subnets.rossum.ipv4 }}" netmaskv4: "{{ intranet.netmaskv4 }}" diff --git a/roles/networking/handlers/main.yml b/roles/networking/handlers/main.yml index 2bf721b..a38fd58 100644 --- a/roles/networking/handlers/main.yml +++ b/roles/networking/handlers/main.yml @@ -2,3 +2,8 @@ - name: Reload network interfaces debian become: true command: /sbin/ifreload -a + +- name: Restart dhcpcd raspbian + systemd: + name: dhcpcd + state: restarted diff --git a/roles/networking/tasks/main.yml b/roles/networking/tasks/main.yml index 1ca7eb2..0b7668a 100644 --- a/roles/networking/tasks/main.yml +++ b/roles/networking/tasks/main.yml @@ -48,3 +48,13 @@ notify: Reload network interfaces debian when: ansible_facts["lsb"]["id"] == "Debian" +- name: Create dhcpcd config files + ansible.builtin.template: + src: "raspbian_dhcpcd.conf.j2" + dest: "/etc/dhcpcd.conf" + owner: root + group: netdev + mode: '664' + notify: Restart dhcpcd raspbian + when: ansible_facts["lsb"]["id"] == "Raspbian" + diff --git a/roles/networking/templates/raspbian_dhcpcd.conf.j2 b/roles/networking/templates/raspbian_dhcpcd.conf.j2 new file mode 100644 index 0000000..226e804 --- /dev/null +++ b/roles/networking/templates/raspbian_dhcpcd.conf.j2 @@ -0,0 +1,56 @@ +{{ ansible_managed | comment }} + +# A sample configuration for dhcpcd. +# See dhcpcd.conf(5) for details. + +# Allow users of this group to interact with dhcpcd via the control socket. +#controlgroup wheel + +# Inform the DHCP server of our hostname for DDNS. +hostname + +# Use the hardware address of the interface for the Client ID. +clientid +# or +# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. +# Some non-RFC compliant DHCP servers do not reply with this set. +# In this case, comment out duid and enable clientid above. +#duid + +# Persist interface configuration when dhcpcd exits. +persistent + +# Rapid commit support. +# Safe to enable by default because it requires the equivalent option set +# on the server to actually work. +option rapid_commit + +# A list of options to request from the DHCP server. +option domain_name_servers, domain_name, domain_search, host_name +option classless_static_routes +# Respect the network MTU. This is applied to DHCP routes. +option interface_mtu + +# Most distributions have NTP support. +#option ntp_servers + +# A ServerID is required by RFC2131. +require dhcp_server_identifier + +# Generate SLAAC address using the Hardware Address of the interface +#slaac hwaddr +# OR generate Stable Private IPv6 Addresses based from the DUID +slaac private + +{% for item in lookup('dict', interfaces) %} +{% if item.value.type == 'static' %} +interface {{ item.key }} +{% if 'ipv4' in item.value %} +static ip_address={{ item.value.ipv4 }}/{{ item.value.netmaskv4 }} +{% endif %} +{% if 'gateway' in item.value %} +static routers={{ item.value.gateway }} +{% endif %} + +{% endif %} +{% endfor %}