2023-10-06 13:40:39 +02:00
---
- name : network-interfaces | Manage additional network interfaces, Ubuntu style
tags :
- network_interface
- networking
when :
- ansible_distribution == 'Ubuntu'
- ubuntu_configure_additional_interfaces
block :
- name : network-interfaces | Check if netplan is in use
ansible.builtin.stat :
path : /etc/netplan
register : netplan_in_use
- name : network-interfaces | Check if additional interfaces have been defined
ansible.builtin.set_fact :
2023-12-04 12:20:46 +01:00
net_ints : '{% for i in ansible_interfaces %}{% if i != ansible_lo.device and i != ansible_default_ipv4.interface %}"{{ i }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %}'
2023-10-06 13:40:39 +02:00
when : netplan_in_use.stat.isdir
- name : network-interfaces | Create a dictionary of additional interfaces
ansible.builtin.set_fact :
2023-12-04 12:20:46 +01:00
new_ints : '[{% for i in ansible_interfaces %}{% if i != ansible_lo.device and i != ansible_default_ipv4.interface %}"{{ i }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %}]'
2023-10-06 18:17:59 +02:00
when : net_ints is defined and net_ints | length != 0
2023-12-04 11:52:37 +01:00
- name : network-interfaces | Print the loopback interface name
ansible.builtin.debug :
msg : "Loopback interface: {{ ansible_lo.device }}"
- name : network-interfaces | Print the name of the default interface
ansible.builtin.debug :
msg : "Loopback interface: {{ ansible_default_ipv4.interface }}"
2023-12-05 18:12:11 +01:00
- name : network-interfaces | List of interfaces other than the default one
2023-10-06 18:15:45 +02:00
ansible.builtin.debug :
msg : "Interfaces list: {{ new_ints }}"
2023-12-05 17:59:08 +01:00
- name : network-interfaces | Override the interfaces list
ansible.builtin.set_fact :
new_ints : "{{ ubuntu_configure_additional_ints_list }}"
when : ubuntu_configure_additional_ints_list | length != 0
2023-12-05 18:12:11 +01:00
- name : network-interfaces | List of interfaces that we are going to configure
ansible.builtin.debug :
msg : "Interfaces list: {{ new_ints }}"
when : ubuntu_configure_additional_ints_list | length != 0
2023-10-06 13:40:39 +02:00
- name : network-interfaces | Install the network interface file
ansible.builtin.template :
2023-12-04 12:15:01 +01:00
src : netplan-70-ansible.yaml.j2
2023-10-06 13:40:39 +02:00
dest : /etc/netplan/70-ansible.yaml
owner : root
group : root
mode : "0644"
2023-12-05 18:12:11 +01:00
when : new_ints | length != 0
2023-10-06 13:40:39 +02:00
notify : Netplan Apply
2023-10-06 18:29:12 +02:00
2023-12-04 12:21:13 +01:00
- name : network-interfaces | Force the Netplan Apply command execution
2023-10-26 13:03:15 +02:00
ansible.builtin.meta : flush_handlers
2023-10-06 18:29:12 +02:00
tags :
- network_interface
- networking