This commit is contained in:
ace 2021-10-27 17:08:42 +03:00
parent 0694f3649e
commit 6b9e036057
No known key found for this signature in database
GPG Key ID: 2E47CC17BA7F8CF0
3 changed files with 24 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.galaxy_install_info

View File

@ -1,9 +1,9 @@
--- ---
- name: Up interface - name: Up interface
shell: | shell: |
ifdown {{ item.name }} ; ifup {{ item.name }} ifdown {{ item }} ; ifup {{ item }}
loop: "{{ network.network_scripts.iface }}" loop: "{{ reload_interfaces | unique }}"
- name: Reload interface with nmcli - name: Reload interface with nmcli
command: nmcli conn up {{ item.conn_name }} command: nmcli conn up {{ item }}
loop: "{{ network.network_manager.iface }}" loop: "{{ reload_interfaces | unique }}"

View File

@ -1,6 +1,6 @@
--- ---
- block: - block:
- name: Configure interfaces with nmcli - name: Configure interface with nmcli
community.general.nmcli: community.general.nmcli:
conn_name: "{{ iface.conn_name }}" conn_name: "{{ iface.conn_name }}"
type: "{{ iface.type | default('ethernet') }}" type: "{{ iface.type | default('ethernet') }}"
@ -15,8 +15,12 @@
state: present state: present
notify: notify:
- Reload interface with nmcli - Reload interface with nmcli
register: configure_interface
- name: Add interface to reload list
set_fact: set_fact:
reload_interfaces: "{{ reload_interfaces + iface.conn_name }}" reload_interfaces: "{{ reload_interfaces + [ iface.conn_name ] }}"
when: configure_interface.changed
- name: Get existing ipv4 routes - name: Get existing ipv4 routes
shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }} shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }}
@ -31,9 +35,9 @@
- name: Set fact about existing and new ipv4/ipv6 routes - name: Set fact about existing and new ipv4/ipv6 routes
set_fact: set_fact:
existing_routes4: "{{ existing_routes4_res.stdout | hash('sha256') }}" existing_routes4: "{{ existing_routes4_res.stdout | hash('sha256') }}"
new_routes4: "{{ '' if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}" new_routes4: "{{ (echo.stdout | hash('sha256')) if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
existing_routes6: "{{ existing_routes6_res.stdout | hash('sha256') }}" existing_routes6: "{{ existing_routes6_res.stdout | hash('sha256') }}"
new_routes6: "{{ '' if iface.routes6 is not defined else (iface.routes6|join(', ') | hash('sha256')) }}" new_routes6: "{{ (echo.stdout | hash('sha256')) if iface.routes6 is not defined else (iface.routes6|join(', ') | hash('sha256')) }}"
#- debug: #- debug:
# msg: "{{ existing_routes4_res.stdout | hash('sha256') }}" # msg: "{{ existing_routes4_res.stdout | hash('sha256') }}"
@ -51,12 +55,21 @@
gw6: "{{ iface.gw6 | default(omit) }}" gw6: "{{ iface.gw6 | default(omit) }}"
never_default4: "{{ iface.never_default4 | default('yes') }}" never_default4: "{{ iface.never_default4 | default('yes') }}"
vlanid: "{{ iface.vlanid | default(omit) }}" vlanid: "{{ iface.vlanid | default(omit) }}"
routes4: "{{ omit if existing_routes4 == new_routes4 else iface.routes4 }}" routes4: "{{ iface.routes4 if (existing_routes4 != new_routes4) else omit }}"
routing_rules4: "{{ iface.routing_rules4 | default(omit) }}" routing_rules4: "{{ iface.routing_rules4 | default(omit) }}"
routes6: "{{ omit if existing_routes6 == new_routes6 else iface.routes6 }}" routes6: "{{ iface.routes6 if (existing_routes6 != new_routes6) else omit }}"
routing_rules6: "{{ iface.routing_rules6 | default(omit) }}" routing_rules6: "{{ iface.routing_rules6 | default(omit) }}"
mtu: "{{ iface.mtu | default(0) }}" mtu: "{{ iface.mtu | default(0) }}"
zone: "{{ iface.zone | default(omit) }}" zone: "{{ iface.zone | default(omit) }}"
state: present state: present
notify: notify:
- Reload interface with nmcli - Reload interface with nmcli
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 }}"