From 1204730924436ef9e1c7c49c9557837f9a5ed0e8 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 8 Feb 2023 00:40:09 -0800 Subject: fork https://github.com/mattsta/mailweb --- ansible/roles/network/tasks/main.yml | 40 ++++++++++++++++++++++ .../roles/network/templates/network/custom.link | 6 ++++ .../roles/network/templates/network/custom.network | 38 ++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 ansible/roles/network/tasks/main.yml create mode 100644 ansible/roles/network/templates/network/custom.link create mode 100644 ansible/roles/network/templates/network/custom.network (limited to 'ansible/roles/network') diff --git a/ansible/roles/network/tasks/main.yml b/ansible/roles/network/tasks/main.yml new file mode 100644 index 0000000..5aaaeff --- /dev/null +++ b/ansible/roles/network/tasks/main.yml @@ -0,0 +1,40 @@ +--- +#- name: plop netplan +# copy: +# src: "{{ inventory_hostname }}.yaml" +# dest: "/etc/netplan/20-customNetworking.yaml" +# register: netplanCopy +# +#- name: generate netplan +# command: netplan generate +# register: netplanGenerated +# when: netplanCopy.changed +# +#- name: apply netplan +# command: netplan apply +# when: netplanGenerated.changed + +- name: configure public network link through systemd directly + template: + src: network/custom.link + dest: "/etc/systemd/network/custom-{{ network.ethernets.interface }}.link" + register: networkUpdated + +- name: configure public network address through systemd directly + template: + src: network/custom.network + dest: "/etc/systemd/network/custom-{{ network.ethernets.interface }}.network" + register: networkUpdated + +- name: reload network since configuration changed + command: systemctl restart systemd-networkd + when: networkUpdated.changed + +- name: re-query ansible facts since system changed + setup: + gather_subset: + - "!all" + - "!min" + - network + when: networkUpdated.changed + diff --git a/ansible/roles/network/templates/network/custom.link b/ansible/roles/network/templates/network/custom.link new file mode 100644 index 0000000..e3bc5a8 --- /dev/null +++ b/ansible/roles/network/templates/network/custom.link @@ -0,0 +1,6 @@ +[Match] +OriginalName={{ network.ethernets.interface }} + +[Link] +WakeOnLan=off +MACAddress={{ network.ethernets.macaddress }} diff --git a/ansible/roles/network/templates/network/custom.network b/ansible/roles/network/templates/network/custom.network new file mode 100644 index 0000000..5a8b74e --- /dev/null +++ b/ansible/roles/network/templates/network/custom.network @@ -0,0 +1,38 @@ +[Match] +Name={{ network.ethernets.interface }} + +#{% for net in network.ethernets.networks %} +#[Network] +#Address={{ net.subnet }} +#{% if net.gateway is defined %} +#Gateway={{ net.gateway }} +#{% endif %} +# +#{% endfor %} + + +{% for addr in network.ethernets.addresses %} +[Address] +Address={{ addr }} + +{% endfor %} + +{% for net in network.ethernets.networks %} +[Network] +Address={{ net.subnet }} +{% if net.gateway is defined %} +Gateway={{ net.gateway }} +{% endif %} + +{% endfor %} + + +{% for route in network.ethernets.routes %} +[Route] +Destination={{ route.to }} +Gateway={{ route.via }} +{% if route['on-link'] %} +GatewayOnlink=true +{% endif %} + +{% endfor %} -- cgit v1.2.3