Refactor netplan
This commit is contained in:
parent
db8c7f4f63
commit
6108475fbd
@ -6,6 +6,23 @@ network_netplan_config_path: "{{ network_netplan_etc_path }}/ansible.yaml"
|
||||
network_netplan_default_config_path: "{{ network_netplan_etc_path }}/01-netcfg.yaml"
|
||||
# network_netplan_default_config_state: absent
|
||||
|
||||
network_netplan:
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: false
|
||||
dhcp6: false
|
||||
accept-ra: true
|
||||
addresses:
|
||||
- "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask) | ansible.utils.ipaddr('prefix') }}"
|
||||
- "{{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}"
|
||||
routes:
|
||||
- to: default
|
||||
via: "{{ ansible_default_ipv4.gateway }}"
|
||||
nameservers:
|
||||
addresses: "{{ network_dns_nameservers }}"
|
||||
|
||||
network_interfaces:
|
||||
- name: eth0
|
||||
inet4:
|
||||
@ -15,6 +32,7 @@ network_interfaces:
|
||||
gateway: "{{ ansible_default_ipv4.gateway }}"
|
||||
inet6:
|
||||
dhcp: false
|
||||
accept_ra: true
|
||||
address:
|
||||
- "{{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}"
|
||||
gateway: "{{ ansible_default_ipv6.gateway }}"
|
||||
|
@ -5,14 +5,14 @@
|
||||
state: "{{ network_netplan_default_config_state | default('absent') }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
mode: '0400'
|
||||
notify: netplan apply
|
||||
|
||||
- name: Configure netplan
|
||||
ansible.builtin.template:
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ network_netplan_config_path }}"
|
||||
src: netplan.yaml.j2
|
||||
content: "{{ network_netplan | to_nice_yaml }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
mode: '0400'
|
||||
notify: netplan apply
|
||||
|
@ -1,16 +1,19 @@
|
||||
---
|
||||
network:
|
||||
version: "{{ network_netplan_version | default(2) }}"
|
||||
renderer: "{{ network_netplan_renderer | default("networkd") }}"
|
||||
version: {{ network_netplan_version | default(2) }}
|
||||
renderer: {{ network_netplan_renderer | default('networkd') }}
|
||||
{% if network_interfaces is defined and network_interfaces | length %}
|
||||
ethernets:
|
||||
{% for iface in network_interfaces %}
|
||||
{{ iface['name'] }}:
|
||||
{% if iface['inet4']['dhcp'] is defined %}
|
||||
dhcp4: "{{ iface['inet4']['dhcp'] | ternary('yes', 'no') }}"
|
||||
dhcp4: {{ iface['inet4']['dhcp'] | ternary('true', 'false') }}
|
||||
{% endif %}
|
||||
{% if iface['inet4']['dhcp'] is defined %}
|
||||
dhcp6: "{{ iface['inet6']['dhcp'] | ternary('yes', 'no') }}"
|
||||
dhcp6: {{ iface['inet6']['dhcp'] | ternary('true', 'false') }}
|
||||
{% endif %}
|
||||
{% if iface['inet6']['accept_ra'] is defined %}
|
||||
accept-ra: {{ iface['inet6']['accept_ra'] | ternary('true', 'false') }}
|
||||
{% endif %}
|
||||
{% if iface['inet4']['address'] is defined or iface['inet6']['address'] is defined %}
|
||||
addresses:
|
||||
@ -22,10 +25,10 @@ network:
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if iface['inet4']['gateway'] is defined %}
|
||||
gateway4: "{{ iface['inet4']['gateway'] }}"
|
||||
gateway4: {{ iface['inet4']['gateway'] }}
|
||||
{% endif %}
|
||||
{% if iface['inet6']['gateway'] is defined %}
|
||||
gateway6: "{{ iface['inet6']['gateway'] }}"
|
||||
gateway6: {{ iface['inet6']['gateway'] }}
|
||||
{% endif %}
|
||||
{% if network_dns_nameservers is defined %}
|
||||
nameservers:
|
||||
|
Loading…
Reference in New Issue
Block a user