41 lines
1.7 KiB
YAML
41 lines
1.7 KiB
YAML
---
|
|
- 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:
|
|
net_ints: "{% for i in ansible_interfaces %}{% if i != ansible_lo.device or i != ansible_default_ipv4.interface %}{{ i }}{% if not loop.last %},{% endif %}{% endif %}{% endfor %}"
|
|
when: netplan_in_use.stat.isdir
|
|
- name: network-interfaces | Create a dictionary of additional interfaces
|
|
ansible.builtin.set_fact:
|
|
new_ints: "[{% for i in ansible_interfaces %}{% if i != ansible_lo.device or i != ansible_default_ipv4.interface %}{{ i }}{% if not loop.last %},{% endif %}{% endif %}{% endfor %}]"
|
|
when: net_ints is defined and net_ints | length != 0
|
|
- name: network-interfaces | Print the additional interfaces
|
|
ansible.builtin.debug:
|
|
msg: "Interfaces list: {{ new_ints }}"
|
|
- name: network-interfaces | Install the network interface file
|
|
ansible.builtin.template:
|
|
src: 70-ansible.yaml.j2
|
|
dest: /etc/netplan/70-ansible.yaml
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
when: ubuntu_netplan_interfaces is defined and ubuntu_netplan_interfaces | length != 0
|
|
notify: Netplan Apply
|
|
|
|
- name: Force the Netplan Apply command execution
|
|
ansible.builtin.meta: flush_handlers
|
|
tags:
|
|
- network_interface
|
|
- networking
|
|
|