xoxys.network/tasks/setup.yml

52 lines
1.3 KiB
YAML
Raw Normal View History

---
2024-02-18 12:02:37 +00:00
- name: Set hostname
ansible.builtin.hostname:
name: "{{ network_hostname }}"
when: network_hostname
notify: __network_host_reboot
2024-02-18 12:02:37 +00:00
- name: Write hosts file
ansible.builtin.template:
src: etc/hosts.j2
dest: /etc/hosts
owner: root
group: root
mode: "0644"
notify: __network_host_reboot
2024-02-18 12:02:37 +00:00
- name: Add network interface configuration
ansible.builtin.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
2024-02-18 12:02:37 +00:00
- name: Add static routes
ansible.builtin.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
2024-02-18 12:02:37 +00:00
- name: Set DNS servers
ansible.builtin.template:
src: etc/resolv.conf.j2
dest: /etc/resolv.conf
owner: root
group: root
mode: "0644"
when: network_resolve_enabled | bool