Add a role to switch from networkd to ifconfig

projet6062
Jérémy Lecour 4 years ago committed by Jérémy Lecour
parent 98a0893f43
commit d6e71353dd
  1. 1
      CHANGELOG.md
  2. 9
      networkd-to-ifconfig/README.md
  3. 19
      networkd-to-ifconfig/meta/main.yml
  4. 54
      networkd-to-ifconfig/tasks/main.yml
  5. 17
      networkd-to-ifconfig/templates/interfaces.j2

@ -15,6 +15,7 @@ The **patch** part changes incrementally at each release.
* evolinux-base: better shell history
* evolinux-users: add user to /etc/aliases
* mysql: add a variable to prevent mysql from restarting
* networkd-to-ifconfig: add a role to switch from networkd to ifconfig
* webapps/evoadmin-web: add users to /etc/aliases
### Changed

@ -0,0 +1,9 @@
# networkd-to-ifconfig
Switch back from systemd "networkd" to plain old /etc/network/interfaces.
The role does nothing if an /etc/network/interfaces file is present.
You should always double-check if everything seems OK, then reboot.
Caveat: a public IPv4 and a public IPv6 are expected.

@ -0,0 +1,19 @@
galaxy_info:
author: Evolix
description: Switch back from systemd "networkd" to plain old /etc/network/interfaces.
issue_tracker_url: https://forge.evolix.org/projects/ansible-roles/issues
license: GPLv2
min_ansible_version: 2.2
platforms:
- name: Debian
versions:
- stretch
dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.

@ -0,0 +1,54 @@
---
- name: Check state of /etc/network/interfaces
stat:
path: /etc/network/interfaces
register: interfaces_file
- debug:
msg: A /etc/network/interfaces file already exists, nothing is done.
when: interfaces_file.stat.exists
- block:
- name: "Parse addresses"
shell: "grep Address= /etc/systemd/network/50-default.network | cut -d'=' -f2"
register: network_address_grep
check_mode: no
- name: "Parse gateways"
shell: "grep Gateway= /etc/systemd/network/50-default.network | cut -d'=' -f2"
register: network_gateway_grep
check_mode: no
- name: Prepare variables
set_fact:
eni_interface_name: "{{ ansible_default_ipv4.interface }}"
eni_ipv4_address: "{{ network_address_grep.stdout_lines | ipv4 | first }}"
eni_ipv4_gateway: "{{ network_gateway_grep.stdout_lines | ipv4 | first }}"
eni_ipv6_address: "{{ network_address_grep.stdout_lines | ipv6 | first }}"
eni_ipv6_gateway: "{{ network_gateway_grep.stdout_lines | ipv6 | first }}"
- name: "A new /etc/network/interfaces is generated"
template:
src: interfaces.j2
dest: /etc/network/interfaces
mode: "0644"
owner: root
group: root
- name: "Systemd 'networkd' unit is stopped and disabled"
systemd:
name: systemd-networkd.service
enabled: False
state: stopped
- name: "Systemd 'networking' unit is restarted (it often results in error)"
systemd:
name: networking
enabled: True
state: restarted
ignore_errors: True
- debug:
msg: You should verify your configuration, then reboot the server.
when: not interfaces_file.stat.exists

@ -0,0 +1,17 @@
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
iface lo inet loopback
# The primary network interface
auto {{ eni_interface_name }}
iface {{ eni_interface_name }} inet static
address {{ eni_ipv4_address }}
gateway {{ eni_ipv4_gateway }}
iface {{ eni_interface_name }} inet6 static
address {{ eni_ipv6_address }}
gateway {{ eni_ipv6_gateway }}
post-up /sbin/ip -6 route add {{ eni_ipv6_gateway }} dev {{ eni_interface_name }}
post-up /sbin/ip -6 route add default via IPV6
Loading…
Cancel
Save