alpine: configure network interfaces

This commit is contained in:
Timotej Lazar 2024-06-25 00:40:13 +02:00
parent c42f9ae1f9
commit f1f9d6fa34
3 changed files with 30 additions and 0 deletions

View file

@ -1,3 +1,9 @@
- name: restart networking
service:
name: networking
state: restarted
when: "'handler' not in ansible_skip_tags"
- name: reload sshd - name: reload sshd
service: service:
name: sshd name: sshd

View file

@ -1,3 +1,9 @@
- name: Set up network interfaces
template:
dest: /etc/network/interfaces
src: interfaces.j2
notify: restart networking
- name: Set hostname - name: Set hostname
hostname: hostname:
name: '{{ dns_name }}' name: '{{ dns_name }}'
@ -20,6 +26,7 @@
- name: Install base packages - name: Install base packages
package: package:
name: name:
- acl
- git - git
- iproute2 - iproute2
- logrotate - logrotate

View file

@ -0,0 +1,17 @@
auto lo
iface lo inet loopback
{% for iface in interfaces | selectattr('enabled') %}
auto {{ iface.name }}
iface {{ iface.name }} inet static
{% for ip in iface.ip_addresses %}
address {{ ip.address }}
{% set subnet = ip.address | ipaddr('subnet') %}
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
{% set gateway = prefix.custom_fields.gateway.address %}
{% if gateway is defined %}
gateway {{ gateway | ipaddr('address') }}
{% endif %}
{% endfor %}
{% endfor %}