7c632352a0
The behaviour of the `include` module is badly defined (it try to choose between statically importing the tasks and dynamically including them) and can cause problems depending on any number of constraints (mostly if it choose the wrong behaviour). Replace it with the `import_tasks` (always statically import tasks) unless the `include` is in a loop in which case we replace it with `include_tasks` (always dynamically include tasks).
69 lines
1.8 KiB
YAML
69 lines
1.8 KiB
YAML
---
|
|
|
|
- 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
|
|
- not (force_update_eni_file | bool)
|
|
|
|
- block:
|
|
- name: "Look for systemd network config"
|
|
stat:
|
|
path: /etc/systemd/network/50-default.network
|
|
register: systemd_network_file
|
|
|
|
- name: Set interface name
|
|
set_fact:
|
|
eni_interface_name: "{{ ansible_default_ipv4.interface }}"
|
|
|
|
- import_tasks: set_facts_from_systemd.yml
|
|
when: systemd_network_file.stat.exists
|
|
|
|
- import_tasks: 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 | length > 0) or (eni_ipv6_gateway | length > 0)
|
|
|
|
- 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: (force_update_eni_file | bool) or (not interfaces_file.stat.exists)
|