From 6b9e0360571017f5a2f5de1a4faef8c618b8ff4f Mon Sep 17 00:00:00 2001 From: ace Date: Wed, 27 Oct 2021 17:08:42 +0300 Subject: [PATCH] update --- .gitignore | 1 + handlers/main.yml | 8 ++++---- tasks/RedHat/network_manager.yaml | 25 +++++++++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba6d390 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.galaxy_install_info diff --git a/handlers/main.yml b/handlers/main.yml index 61240ed..a04aa4c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,9 +1,9 @@ --- - name: Up interface shell: | - ifdown {{ item.name }} ; ifup {{ item.name }} - loop: "{{ network.network_scripts.iface }}" + ifdown {{ item }} ; ifup {{ item }} + loop: "{{ reload_interfaces | unique }}" - name: Reload interface with nmcli - command: nmcli conn up {{ item.conn_name }} - loop: "{{ network.network_manager.iface }}" + command: nmcli conn up {{ item }} + loop: "{{ reload_interfaces | unique }}" diff --git a/tasks/RedHat/network_manager.yaml b/tasks/RedHat/network_manager.yaml index 79d43c1..1d335d1 100644 --- a/tasks/RedHat/network_manager.yaml +++ b/tasks/RedHat/network_manager.yaml @@ -1,6 +1,6 @@ --- - block: - - name: Configure interfaces with nmcli + - name: Configure interface with nmcli community.general.nmcli: conn_name: "{{ iface.conn_name }}" type: "{{ iface.type | default('ethernet') }}" @@ -15,8 +15,12 @@ state: present notify: - Reload interface with nmcli + register: configure_interface + + - name: Add interface to reload list 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 shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }} @@ -31,9 +35,9 @@ - name: Set fact about existing and new ipv4/ipv6 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')) }}" + 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') }}" - 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: # msg: "{{ existing_routes4_res.stdout | hash('sha256') }}" @@ -51,12 +55,21 @@ gw6: "{{ iface.gw6 | default(omit) }}" never_default4: "{{ iface.never_default4 | default('yes') }}" 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) }}" - 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) }}" mtu: "{{ iface.mtu | default(0) }}" zone: "{{ iface.zone | default(omit) }}" state: present notify: - 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 }}"