78 lines
2.5 KiB
YAML
78 lines
2.5 KiB
YAML
# tasks file for network-interfaces
|
|
---
|
|
- name: create directory
|
|
file:
|
|
path: "{{ network_interfaces_interface_path }}"
|
|
state: directory
|
|
when: network_interfaces_interfaces | length > 0
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-create-directory
|
|
|
|
- name: all interfaces
|
|
template:
|
|
src: etc/network/interfaces.j2
|
|
dest: "{{ network_interfaces_all_interfaces_path }}"
|
|
notify: restart network-interfaces
|
|
when: network_interfaces_interfaces | length > 0
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-all-interfaces
|
|
|
|
- name: list network interfaces
|
|
command: find {{ network_interfaces_interface_path }} -type f
|
|
changed_when: false
|
|
when: network_interfaces_interfaces | length > 0
|
|
register: _network_interfaces_existing_files
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-list-network-interfaces
|
|
|
|
- name: configurations
|
|
template:
|
|
src: etc/network/interfaces.d/device.j2
|
|
dest: "{{ network_interfaces_interface_path }}/device-{{ item.device }}-{{ item.family | default('inet') }}"
|
|
with_items: "{{ network_interfaces_interfaces }}"
|
|
register: _network_interfaces_configuration_result
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-configurations
|
|
|
|
- name: configured files
|
|
set_fact:
|
|
network_interfaces_configured_files: >
|
|
[{% for item in _network_interfaces_configuration_result.results | default([]) -%}
|
|
{{ item.dest | default(item.path) | string }}{{ '' if loop.last else ',' }}
|
|
{%- endfor %}]
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-configured-files
|
|
|
|
- name: remove configurations
|
|
file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
when: network_interfaces_manage_devices and (item not in network_interfaces_configured_files)
|
|
with_items: "{{ _network_interfaces_existing_files.stdout_lines | default([]) }}"
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-remove-configurations
|
|
|
|
- name: restart devices
|
|
shell: >
|
|
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle
|
|
&& ip addr flush {{ item.item.device }}
|
|
&& (ifdown {{ item.item.device }} --exclude=lo || true) && ifup {{ item.item.device }} --exclude=lo
|
|
when: item.changed and item.item.auto | default(true)
|
|
with_items: "{{ _network_interfaces_configuration_result.results | default([]) }}"
|
|
tags:
|
|
- configuration
|
|
- network-interfaces
|
|
- network-interfaces-restart-devices
|