Allow configuring network interfaces
This commit is contained in:
parent
d28d667b8d
commit
f3b2b68b64
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
interfaces:
|
||||
xgei0.100:
|
||||
ipv4:
|
||||
method: static
|
||||
address: 192.0.2.2/24
|
||||
nameservers:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
||||
gateway: 192.0.2.1
|
||||
metric: 500
|
||||
ipv6:
|
||||
method: static
|
||||
address: 2001:db8::2/64
|
||||
nameservers:
|
||||
- 2001:4860:4860::8888
|
||||
- 2001:4860:4860::8844
|
||||
gateway: 2001:db8::1
|
||||
metric: 600
|
||||
xgei0.101:
|
||||
ipv4:
|
||||
method: manual
|
||||
ipv6:
|
||||
method: auto
|
|
@ -1 +1 @@
|
|||
ansible-lint roles/*/tasks/main.yml
|
||||
ansible-lint roles/*/tasks/main.yml host_vars/**/*.yml group_vars/**/*.yml roles/*/handlers/main.yml
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
---
|
||||
- name: update initramfs
|
||||
- name: Restart networking
|
||||
ansible.builtin.service:
|
||||
name: networking
|
||||
state: restarted
|
||||
|
||||
- name: Update initramfs
|
||||
ansible.builtin.command: "update-initramfs -u"
|
||||
changed_when: true
|
||||
# register: restart_required
|
||||
|
||||
- name: trigger udev add
|
||||
- name: Trigger udev add
|
||||
ansible.builtin.command: "udevadm trigger --action=add"
|
||||
changed_when: true
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
---
|
||||
- name: Check whether vlan config is valid
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.value.name is defined if item.value.type == "eth"
|
||||
- item.value.parent is defined if item.value.type == "vlan"
|
||||
- item.value.parent in interfaces if item.value.parent is defined
|
||||
with_items:
|
||||
- interfaces
|
||||
|
||||
- name: Create physical interfaces
|
||||
community.general.interfaces_file:
|
||||
- name: Create interface files
|
||||
ansible.builtin.template:
|
||||
src: interface.conf.j2
|
||||
dest: "/etc/network/interfaces.d/{{ item.key }}.conf"
|
||||
iface: "{{ item.value.name }}"
|
||||
mode: "644"
|
||||
with_items:
|
||||
- interfaces | select(item.value.type != "vlan")
|
||||
|
||||
- name: Create vlan interfaces
|
||||
community.general.interfaces_file:
|
||||
dest: "/etc/network/interfaces.d/{{ item.key }}.conf"
|
||||
iface: "{{ interfaces[item.value.parent].name }}.{{ item.value.vlan_id }}"
|
||||
with_items:
|
||||
- interfaces | select(item.value.type == "vlan")
|
||||
|
||||
- name: Restart networking
|
||||
ansible.builtin.notify:
|
||||
- restart networking
|
||||
- "{{ interfaces | dict2items }}"
|
||||
notify:
|
||||
- Restart networking
|
||||
|
|
|
@ -30,3 +30,7 @@
|
|||
- name: Configure udev rules
|
||||
ansible.builtin.include_tasks: udev.yml
|
||||
when: udev_rules is defined
|
||||
|
||||
- name: Configure network interfaces
|
||||
ansible.builtin.include_tasks: interfaces.yml
|
||||
when: interfaces is defined
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
with_items:
|
||||
- "{{ udev_rules | dict2items }}"
|
||||
notify:
|
||||
- update initramfs
|
||||
- trigger udev add
|
||||
- Update initramfs
|
||||
- Trigger udev add
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
{% if not(item.shutdown is defined) or not(item.shutdown) %}
|
||||
auto {{ item.key }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'ipv4' in item.value %}
|
||||
{%- set props = item.value.ipv4 -%}
|
||||
iface {{ item.key }} inet {{ props.method }}
|
||||
{% if props.method == 'static' %}
|
||||
address {{ props.address }}
|
||||
{% if 'nameservers' in props -%}
|
||||
dns-nameservers {{ props.nameservers | join(' ') }}
|
||||
{% endif -%}
|
||||
{% if 'gateway' in props -%}
|
||||
{% if not(props.metric is defined) -%}
|
||||
gateway {{ props.gateway }}
|
||||
{% else -%}
|
||||
post-up /sbin/ip route add default via {{ props.gateway }} dev {{ item.key }} metric {{ props.metric }}
|
||||
post-down /sbin/ip route del default via {{ props.gateway }} dev {{ item.key }} metric {{ props.metric }}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{%- endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if 'ipv6' in item.value -%}
|
||||
{%- set props = item.value.ipv6 -%}
|
||||
iface {{ item.key }} inet6 {{ props.method }}
|
||||
{% if props.method == 'static' %}
|
||||
address {{ props.address }}
|
||||
{% if 'nameservers' in props -%}
|
||||
dns-nameservers {{ props.nameservers | join(' ') }}
|
||||
{% endif -%}
|
||||
{% if 'gateway' in props -%}
|
||||
{% if not(props.metric is defined) -%}
|
||||
gateway {{ props.gateway }}
|
||||
{% else -%}
|
||||
post-up /sbin/ip -6 route add default via {{ props.gateway }} dev {{ item.key }} metric {{ props.metric }}
|
||||
post-down /sbin/ip -6 route del default via {{ props.gateway }} dev {{ item.key }} metric {{ props.metric }}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{%- endif %}
|
||||
{% endif %}
|
Loading…
Reference in New Issue