network/tasks/RedHat/network_manager.yaml

76 lines
3.1 KiB
YAML
Raw Normal View History

2021-10-26 21:34:13 +00:00
---
- block:
2021-10-27 14:08:42 +00:00
- name: Configure interface with nmcli
2021-10-26 21:34:13 +00:00
community.general.nmcli:
conn_name: "{{ iface.conn_name }}"
type: "{{ iface.type | default('ethernet') }}"
ip4: "{{ omit if iface.ip4 is not defined else (iface.ip4|join(', ')) }}"
ip6: "{{ omit if iface.ip6 is not defined else (iface.ip6|join(', ')) }}"
gw4: "{{ iface.gw4 | default(omit) }}"
gw6: "{{ iface.gw6 | default(omit) }}"
never_default4: "{{ iface.never_default4 | default('yes') }}"
vlanid: "{{ iface.vlanid | default(omit) }}"
mtu: "{{ iface.mtu | default(0) }}"
zone: "{{ iface.zone | default(omit) }}"
state: present
notify:
- Reload interface with nmcli
2021-10-27 14:08:42 +00:00
register: configure_interface
- name: Add interface to reload list
2021-10-27 13:49:17 +00:00
set_fact:
2021-10-27 14:08:42 +00:00
reload_interfaces: "{{ reload_interfaces + [ iface.conn_name ] }}"
when: configure_interface.changed
2021-10-26 21:34:13 +00:00
2021-10-27 11:31:55 +00:00
- name: Get existing ipv4 routes
2021-10-26 21:34:13 +00:00
shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }}
register: existing_routes4_res
changed_when: False
2021-10-27 11:31:55 +00:00
- name: Get existing ipv6 routes
shell: nmcli -g ipv6.routes connection show {{ iface.conn_name }}
register: existing_routes6_res
changed_when: False
2021-10-26 21:34:13 +00:00
2021-10-27 11:31:55 +00:00
- name: Set fact about existing and new ipv4/ipv6 routes
2021-10-26 21:34:13 +00:00
set_fact:
existing_routes4: "{{ existing_routes4_res.stdout | hash('sha256') }}"
2021-10-27 14:08:42 +00:00
new_routes4: "{{ (echo.stdout | hash('sha256')) if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
2021-10-27 11:31:55 +00:00
existing_routes6: "{{ existing_routes6_res.stdout | hash('sha256') }}"
2021-10-27 14:08:42 +00:00
new_routes6: "{{ (echo.stdout | hash('sha256')) if iface.routes6 is not defined else (iface.routes6|join(', ') | hash('sha256')) }}"
2021-10-26 21:34:13 +00:00
#- debug:
# msg: "{{ existing_routes4_res.stdout | hash('sha256') }}"
#- debug:
# msg: "{{ '' if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
2021-10-27 11:31:55 +00:00
- name: Update routes and rules with nmcli
2021-10-26 21:34:13 +00:00
community.general.nmcli:
conn_name: "{{ iface.conn_name }}"
type: "{{ iface.type | default('ethernet') }}"
ip4: "{{ omit if iface.ip4 is not defined else (iface.ip4|join(', ')) }}"
ip6: "{{ omit if iface.ip6 is not defined else (iface.ip6|join(', ')) }}"
gw4: "{{ iface.gw4 | default(omit) }}"
gw6: "{{ iface.gw6 | default(omit) }}"
never_default4: "{{ iface.never_default4 | default('yes') }}"
vlanid: "{{ iface.vlanid | default(omit) }}"
2021-10-27 14:08:42 +00:00
routes4: "{{ iface.routes4 if (existing_routes4 != new_routes4) else omit }}"
2021-10-26 21:34:13 +00:00
routing_rules4: "{{ iface.routing_rules4 | default(omit) }}"
2021-10-27 14:08:42 +00:00
routes6: "{{ iface.routes6 if (existing_routes6 != new_routes6) else omit }}"
2021-10-26 21:34:13 +00:00
routing_rules6: "{{ iface.routing_rules6 | default(omit) }}"
mtu: "{{ iface.mtu | default(0) }}"
zone: "{{ iface.zone | default(omit) }}"
state: present
notify:
- Reload interface with nmcli
2021-10-27 14:08:42 +00:00
register: update_routes_and_rules
- name: Add interface to reload list
set_fact:
reload_interfaces: "{{ reload_interfaces + [ iface.conn_name ] }}"
when: update_routes_and_rules.changed
- debug:
msg: "{{ reload_interfaces }}"