38 lines
1.3 KiB
YAML
38 lines
1.3 KiB
YAML
---
|
|
- name: Write Alpine network interfaces
|
|
vars:
|
|
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
|
ansible.builtin.copy:
|
|
dest: /mnt/etc/network/interfaces
|
|
mode: "0644"
|
|
content: |
|
|
auto lo
|
|
iface lo inet loopback
|
|
{% for iface in system_cfg.network.interfaces %}
|
|
{% set inv_name = iface.name | default('') | string %}
|
|
{% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %}
|
|
{% set iface_name = inv_name if inv_name | length > 0 else det_name %}
|
|
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
|
|
|
|
auto {{ iface_name }}
|
|
iface {{ iface_name }} inet {{ 'static' if has_static else 'dhcp' }}
|
|
{% if has_static %}
|
|
address {{ iface.ip }}/{{ iface.prefix }}
|
|
{% if iface.gateway | default('') | string | length %}
|
|
gateway {{ iface.gateway }}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
- name: Set Alpine DNS resolvers
|
|
vars:
|
|
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
|
when: configuration_dns_list | length > 0
|
|
ansible.builtin.copy:
|
|
dest: /mnt/etc/resolv.conf
|
|
mode: "0644"
|
|
content: |
|
|
{% for resolver in configuration_dns_list %}
|
|
nameserver {{ resolver }}
|
|
{% endfor %}
|