Files
ansible-role-common/tasks/networking.yml

102 lines
2.9 KiB
YAML
Raw Normal View History

---
2023-10-05 17:33:18 +13:00
- name: What is virtualization type?
debug:
2023-10-05 17:34:57 +13:00
msg: "Virtualization is: {{ ansible_virtualization_type }}"
- name: Ensure Network Setup (RedHat only)
template:
2022-11-02 12:07:24 +13:00
src: "{{ network_config.src }}"
dest: "{{ network_config.dest }}"
mode: "{{ network_config.mode }}"
backup: yes
with_items:
2022-04-03 13:20:47 +12:00
- {
src: etc.sysconfig.network.j2,
dest: /etc/sysconfig/network,
2022-04-03 13:20:47 +12:00
mode: u+rw,
a+r,
}
when: >
2024-04-24 14:50:04 +12:00
ansible_virtualization_type != "docker"
and ansible_virtualization_type != "container"
and ansible_os_family == "RedHat"
loop_control:
loop_var: network_config
tags: dns
- name: Ensure Resolvers Configured
template:
src: "{{ network_config.src }}"
dest: "{{ network_config.dest }}"
mode: "{{ network_config.mode }}"
backup: yes
with_items:
2022-04-03 13:20:47 +12:00
- { src: etc.resolv.conf.j2, dest: /etc/resolv.conf, mode: u+rw, a+r }
when: >
2024-04-24 14:50:04 +12:00
ansible_virtualization_type != "docker"
and ansible_virtualization_type != "container"
2022-11-02 12:07:24 +13:00
loop_control:
loop_var: network_config
tags: dns
- name: Ensure hosts file correct
lineinfile:
dest: /etc/hosts
2022-11-02 12:07:24 +13:00
regexp: "{{ hosts_config.regexp }}"
line: "{{ hosts_config.line }}"
backrefs: yes
backup: yes
with_items:
2022-04-03 13:20:47 +12:00
- {
regexp: "^127.0.0.1.+localdomain4$",
line: "127.0.0.1 localhost {{ inventory_hostname }}",
}
2022-04-03 13:20:47 +12:00
- {
regexp: "^::1.+localdomain6$",
line: "::1 localhost {{ inventory_hostname }}",
}
2022-04-03 13:20:47 +12:00
- {
regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_default_ipv4.address.split('.')[-1] }}$",
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}",
}
2022-04-03 13:20:47 +12:00
- {
regexp: "^127.0.0.1.+{{ ansible_nodename.split('.')[0] }}$",
line: "127.0.0.1 localhost {{ inventory_hostname }}",
}
2022-04-03 13:20:47 +12:00
- {
regexp: "^::1.+{{ ansible_nodename.split('.')[0] }}$",
line: "::1 localhost {{ inventory_hostname }}",
}
2022-04-03 13:20:47 +12:00
- {
regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_nodename.split('.')[0] }}$",
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}",
}
2022-11-02 12:07:24 +13:00
loop_control:
loop_var: hosts_config
when: ansible_virtualization_type != "docker" and ansible_virtualization_type != "container"
- name: Ensure NetworkManager does not fiddle DNS
ini_file:
dest: /etc/NetworkManager/NetworkManager.conf
section: "main"
option: "dns"
value: "none"
backup: yes
when: (ansible_os_family == "RedHat" and ansible_distribution_major_version == "7")
notify:
2023-10-08 22:34:46 +13:00
- Restart NetworkManager
changed_when: false
- name: Ensure correct permissions (hosts/resolv.conf)
file:
2022-11-02 12:07:24 +13:00
path: "{{ perm_config }}"
state: touch
mode: u+rw,g+r,a+r
with_items:
- /etc/resolv.conf
- /etc/hosts
2022-11-02 12:07:24 +13:00
loop_control:
loop_var: perm_config
changed_when: false
2022-04-03 13:20:47 +12:00
tags: dns