Skip to content

Commit

Permalink
feat: Consolidate all in interfaces (Debian)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme BECOT committed Oct 6, 2022
1 parent ecf8c21 commit eaf758b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ interfaces_setup_filter: "{{ omit }}"

# An optional gather_subset parameter to pass to the setup module.
interfaces_setup_gather_subset: "{{ omit }}"

# An option to merge all configurations setup with merge: true
# in the global interfaces file (Debian-Family only)
interfaces_merge: false
```
Note: The values for the list are listed in the examples below.
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ interfaces_pause_time: 0
interfaces_setup_filter: "{{ omit }}"
interfaces_setup_gather_subset: "{{ omit }}"
interfaces_bond_setup_slaves: true
interfaces_merge: false
12 changes: 12 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@
group: root
mode: 0644
tags: configuration
when: not interfaces_merge

- name: Debian | Create the directory for interface cfg files
become: true
file:
path: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}'
state: directory
tags: configuration

- name: Debian | Ensure lo single configuration file
copy:
dest: /etc/network/interfaces.d/ifcfg-lo
mode: 0644
content: |
# Loopback
auto lo
iface lo inet loopback
when: interfaces_merge
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@
when: interfaces_ether_interfaces is defined
tags: configuration

- name: Debian | Merge configuration in interface file
assemble:
src: "{{ interfaces_net_path['debian'] }}"
dest: /etc/network/interfaces
tags: configuration
when:
- ansible_facts.os_family | lower == 'debian'
- interfaces_merge

- import_tasks: 'service.yml'
tags: service
8 changes: 5 additions & 3 deletions templates/bond_Debian.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# {{ ansible_managed }}
{% if not interfaces_merge %}# {{ ansible_managed }}
{% else %}# Bond - {{ item.device }}
{% endif %}

auto {{ item.device }}
{% if item.bootproto == 'manual' %}
Expand Down Expand Up @@ -57,7 +59,7 @@ bond-slaves none
bond-slaves {{ item.bond_slaves|join(' ') }}
{% endif %}

{% if item.route is defined %}
{%- if item.route is defined %}
{% for i in item.route %}
{# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #}
{% set prefix = ('0.0.0.0/' ~ i.netmask) | ipaddr('prefix') %}
Expand All @@ -78,7 +80,7 @@ down ip route del {{ route }}
{% endfor %}
{% endif %}

{% if item.rules is defined %}
{%- if item.rules is defined %}
{% for rule in item.rules %}
up ip rule add {{ rule }}
down ip rule del {{ rule }}
Expand Down
6 changes: 5 additions & 1 deletion templates/bond_slave_Debian.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# {{ ansible_managed }}
{% if not interfaces_merge %}# {{ ansible_managed }}
{% else %}# Bond Slave - {{ item.0.device }}/{{ item.1 }}
{% endif %}

auto {{ item.1 }}
iface {{ item.1 }} inet manual
{% if ansible_facts.distribution_major_version | int < 11 %}
bond-master {{ item.0.device }}
{% endif %}
8 changes: 5 additions & 3 deletions templates/bridge_Debian.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# {{ ansible_managed }}
{% if not interfaces_merge %}# {{ ansible_managed }}
{% else %}# Bridge - {{ item.device }}
{% endif %}

auto {{ item.device }}
{% if item.bootproto == 'dhcp' %}
Expand Down Expand Up @@ -39,7 +41,7 @@ bridge_fd {{ item.fd }}
bridge-vlan-aware {{ item.vlan_aware }}
{% endif %}

{% if item.route is defined %}
{%- if item.route is defined %}
{% for i in item.route %}
{# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #}
{% set prefix = ('0.0.0.0/' ~ i.netmask) | ipaddr('prefix') %}
Expand All @@ -60,7 +62,7 @@ down ip route del {{ route }}
{% endfor %}
{% endif %}

{% if item.rules is defined %}
{%- if item.rules is defined %}
{% for rule in item.rules %}
up ip rule add {{ rule }}
down ip rule del {{ rule }}
Expand Down
4 changes: 3 additions & 1 deletion templates/bridge_port_Debian.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# {{ ansible_managed }}
{% if not interfaces_merge %}# {{ ansible_managed }}
{% else %}# Bridge Port - {{ item.0.device }}/{{ item.1 }}
{% endif %}

auto {{ item.1 }}
iface {{ item.1 }} inet manual
Expand Down
4 changes: 3 additions & 1 deletion templates/ethernet_Debian.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# {{ ansible_managed }}
{% if not interfaces_merge %}# {{ ansible_managed }}
{% else %}# Ethernet - {{ item.device }}
{% endif %}

{{ item.allowclass | default('auto') }} {{ item.device }}
{% if item.bootproto == 'dhcp' %}
Expand Down

0 comments on commit eaf758b

Please sign in to comment.