mirror of
https://gitea.0xace.cc/ansible-galaxy/network.git
synced 2024-11-24 22:36:38 +00:00
55 lines
2.2 KiB
YAML
55 lines
2.2 KiB
YAML
---
|
|
- block:
|
|
- name: Configure interfaces with nmcli
|
|
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
|
|
|
|
- name: Get existing routes
|
|
shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }}
|
|
register: existing_routes4_res
|
|
changed_when: False
|
|
|
|
- name: Set fact about existing and new routes
|
|
set_fact:
|
|
existing_routes4: "{{ existing_routes4_res.stdout | hash('sha256') }}"
|
|
new_routes4: "{{ '' if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
|
|
|
|
#- debug:
|
|
# msg: "{{ existing_routes4_res.stdout | hash('sha256') }}"
|
|
|
|
#- debug:
|
|
# msg: "{{ '' if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
|
|
|
|
- name: Add routes and rules with nmcli
|
|
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) }}"
|
|
routes4: "{{ iface.routes4 | default(omit) }}"
|
|
routing_rules4: "{{ iface.routing_rules4 | default(omit) }}"
|
|
routes6: "{{ iface.routes6 | default(omit) }}"
|
|
routing_rules6: "{{ iface.routing_rules6 | default(omit) }}"
|
|
mtu: "{{ iface.mtu | default(0) }}"
|
|
zone: "{{ iface.zone | default(omit) }}"
|
|
state: present
|
|
when: existing_routes4 != new_routes4
|
|
notify:
|
|
- Reload interface with nmcli
|