ansible-roles/networkd-to-ifconfig/tasks/main.yml
Jérémy Lecour ee21973371
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2777|524|2253|2462|:+1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/223//ansiblelint">Evolix » ansible-roles » unstable #223</a>
gitea/ansible-roles/pipeline/head This commit looks good
Use FQCN
Fully Qualified Collection Name
2023-03-20 23:33:19 +01:00

69 lines
2 KiB
YAML

---
- name: Check state of /etc/network/interfaces
ansible.builtin.stat:
path: /etc/network/interfaces
register: interfaces_file
- ansible.builtin.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"
ansible.builtin.stat:
path: /etc/systemd/network/50-default.network
register: systemd_network_file
- name: Set interface name
ansible.builtin.set_fact:
eni_interface_name: "{{ ansible_default_ipv4.interface }}"
- ansible.builtin.include: set_facts_from_systemd.yml
when: systemd_network_file.stat.exists
- ansible.builtin.include: set_facts_from_ansible.yml
when: not systemd_network_file.stat.exists
- name: Check config (IPv4)
ansible.builtin.assert:
that:
- eni_ipv4_address | ipv4
- eni_ipv4_gateway | ipv4
msg: "IPv4 configuration is invalid"
- name: Check config (IPV6)
ansible.builtin.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"
ansible.builtin.template:
src: interfaces.j2
dest: /etc/network/interfaces
mode: "0644"
owner: root
group: root
- name: "Systemd 'networkd' unit is stopped and disabled"
ansible.builtin.systemd:
name: systemd-networkd.service
enabled: False
state: stopped
- name: "Systemd 'networking' unit is restarted (it often results in error)"
ansible.builtin.systemd:
name: networking
enabled: True
state: restarted
ignore_errors: True
- ansible.builtin.debug:
msg: You should verify your configuration, then reboot the server.
when: (force_update_eni_file | bool) or (not interfaces_file.stat.exists)