xoxys.network/tasks/setup.yml
Robert Kaussow 9dea3340ae
Some checks failed
continuous-integration/drone/push Build is failing
fix: apply network changes on systems using nm
2022-10-10 15:17:16 +02:00

59 lines
1.6 KiB
YAML

---
- name: Set flag require_reboot
set_fact:
require_reboot: "{{ True if (network_fqdn != ansible_fqdn and network_reboot_enabled | bool) else False }}"
- block:
- name: Set hostname
hostname:
name: "{{ network_hostname }}"
when: network_hostname
notify: __host_reboot
- name: Write hosts file
template:
src: etc/hosts.j2
dest: /etc/hosts
owner: root
group: root
mode: 0644
notify: __host_reboot
- name: Add network interface configuration
template:
src: etc/sysconfig/network-scrips/ifcfg.j2
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.key }}"
owner: root
group: root
mode: 0644
loop: "{{ network_interfaces | dict2items }}"
loop_control:
label: "{{ item.key }}"
when: item.key in ansible_interfaces or item.key.split(":")[0] in ansible_interfaces
register: __network_ifcfg
notify: __network_restart
- name: Add static routes
copy:
content: "{{ item.value }}"
dest: "/etc/sysconfig/network-scripts/route-{{ item.key }}"
owner: root
group: root
mode: 0644
loop: "{{ network_routes | dict2items }}"
loop_control:
label: "{{ item.key }}"
when: item.key in ansible_interfaces
notify: __network_restart
- name: Set DNS servers
template:
src: etc/resolv.conf.j2
dest: /etc/resolv.conf
owner: root
group: root
mode: 0644
when: network_resolve_enabled | bool
become: True
become_user: root