networkd-to-ifconfig: add variables for configuration by variables
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2f77100b47
commit
57e5791728
|
@ -35,6 +35,7 @@ The **patch** part changes incrementally at each release.
|
||||||
* mysql-oracle: backport tasks from mysql role
|
* mysql-oracle: backport tasks from mysql role
|
||||||
* mysql: activate binary logs by specifying log_bin path
|
* mysql: activate binary logs by specifying log_bin path
|
||||||
* mysql: specify a custom server_id
|
* mysql: specify a custom server_id
|
||||||
|
* networkd-to-ifconfig: add variables for configuration by variables
|
||||||
* packweb-apache: Deploy opcache.php to give some insights on PHP's opcache status
|
* packweb-apache: Deploy opcache.php to give some insights on PHP's opcache status
|
||||||
* php: variable to install the mysqlnd module instead of the default mysql module
|
* php: variable to install the mysqlnd module instead of the default mysql module
|
||||||
* postgresql : variable to install PostGIS (default: `False`)
|
* postgresql : variable to install PostGIS (default: `False`)
|
||||||
|
|
9
networkd-to-ifconfig/defaults/main.yml
Normal file
9
networkd-to-ifconfig/defaults/main.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
force_update_eni_file: False
|
||||||
|
eni_interface_name: Null
|
||||||
|
eni_ipv4_address: Null
|
||||||
|
eni_ipv4_gateway: Null
|
||||||
|
eni_ipv6_address: Null
|
||||||
|
eni_ipv6_gateway: Null
|
||||||
|
ipv6_gateway_mask: "xxxx.xxxx.xxxx.xxFF:FF:FF:FF:FF"
|
|
@ -7,26 +7,38 @@
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
msg: A /etc/network/interfaces file already exists, nothing is done.
|
msg: A /etc/network/interfaces file already exists, nothing is done.
|
||||||
when: interfaces_file.stat.exists
|
when: interfaces_file.stat.exists and not force_update_eni_file
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: "Parse addresses"
|
- name: "Look for systemd network config"
|
||||||
shell: "grep Address= /etc/systemd/network/50-default.network | cut -d'=' -f2"
|
stat:
|
||||||
register: network_address_grep
|
path: /etc/systemd/network/50-default.network
|
||||||
check_mode: no
|
register: systemd_network_file
|
||||||
|
|
||||||
- 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
|
- name: Set interface name
|
||||||
set_fact:
|
set_fact:
|
||||||
eni_interface_name: "{{ ansible_default_ipv4.interface }}"
|
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 }}"
|
- include: set_facts_from_systemd.yml
|
||||||
eni_ipv6_address: "{{ network_address_grep.stdout_lines | ipv6 | first }}"
|
when: systemd_network_file.stat.exists
|
||||||
eni_ipv6_gateway: "{{ network_gateway_grep.stdout_lines | ipv6 | first }}"
|
|
||||||
|
- include: set_facts_from_ansible.yml
|
||||||
|
when: not systemd_network_file.stat.exists
|
||||||
|
|
||||||
|
- name: Check config (IPv4)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- eni_ipv4_address | ipv4
|
||||||
|
- eni_ipv4_gateway | ipv4
|
||||||
|
msg: "IPv4 configuration is invalid"
|
||||||
|
|
||||||
|
- name: Check config (IPV6)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- eni_ipv6_address | ipv6
|
||||||
|
- eni_ipv6_gateway | ipv6
|
||||||
|
msg: "IPv6 configuration is invalid"
|
||||||
|
when: eni_ipv6_address or eni_ipv6_gateway
|
||||||
|
|
||||||
- name: "A new /etc/network/interfaces is generated"
|
- name: "A new /etc/network/interfaces is generated"
|
||||||
template:
|
template:
|
||||||
|
@ -48,7 +60,7 @@
|
||||||
enabled: True
|
enabled: True
|
||||||
state: restarted
|
state: restarted
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
msg: You should verify your configuration, then reboot the server.
|
msg: You should verify your configuration, then reboot the server.
|
||||||
when: not interfaces_file.stat.exists
|
when: force_update_eni_file or not interfaces_file.stat.exists
|
||||||
|
|
13
networkd-to-ifconfig/tasks/set_facts_from_ansible.yml
Normal file
13
networkd-to-ifconfig/tasks/set_facts_from_ansible.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: Prepare variables (IPv4)
|
||||||
|
set_fact:
|
||||||
|
eni_ipv4_address: "{{ ansible_default_ipv4.address | ipv4 }}"
|
||||||
|
eni_ipv4_gateway: "{{ ansible_default_ipv4.gateway | ipv4 }}"
|
||||||
|
when: ansible_default_ipv4
|
||||||
|
|
||||||
|
- name: Prepare variables (IPv6)
|
||||||
|
set_fact:
|
||||||
|
eni_ipv6_address: "{{ ansible_default_ipv6.address | ipv6 | first }}"
|
||||||
|
eni_ipv6_gateway: "{{ ansible_default_ipv6.gateway | ipv6 | first }}"
|
||||||
|
when: ansible_default_ipv6
|
18
networkd-to-ifconfig/tasks/set_facts_from_systemd.yml
Normal file
18
networkd-to-ifconfig/tasks/set_facts_from_systemd.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- 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_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 }}"
|
|
@ -10,8 +10,13 @@ iface {{ eni_interface_name }} inet static
|
||||||
address {{ eni_ipv4_address }}
|
address {{ eni_ipv4_address }}
|
||||||
gateway {{ eni_ipv4_gateway }}
|
gateway {{ eni_ipv4_gateway }}
|
||||||
|
|
||||||
|
{% if eni_ipv6_address and eni_ipv6_gateway %}
|
||||||
iface {{ eni_interface_name }} inet6 static
|
iface {{ eni_interface_name }} inet6 static
|
||||||
address {{ eni_ipv6_address }}
|
address {{ eni_ipv6_address }}
|
||||||
gateway {{ eni_ipv6_gateway }}
|
netmask 128
|
||||||
post-up /sbin/ip -6 route add {{ eni_ipv6_gateway }} dev {{ eni_interface_name }}
|
|
||||||
post-up /sbin/ip -6 route add default via IPV6
|
post-up /sbin/ip -f inet6 route add {{ eni_ipv6_gateway }} dev {{ eni_interface_name }}
|
||||||
|
post-up /sbin/ip -f inet6 route add default via {{ eni_ipv6_address }}
|
||||||
|
pre-down /sbin/ip -f inet6 route del {{ eni_ipv6_gateway }} dev {{ eni_interface_name }}
|
||||||
|
pre-down /sbin/ip -f inet6 route del default via {{ eni_ipv6_gateway }}
|
||||||
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue