This commit is contained in:
ace 2021-10-27 17:19:40 +03:00
parent 6b9e036057
commit ccb0e81fbe
No known key found for this signature in database
GPG Key ID: 2E47CC17BA7F8CF0
5 changed files with 54 additions and 41 deletions

View File

@ -1,5 +1,5 @@
---
- name: Up interface
- name: Reload interface with ifdown ; ifup
shell: |
ifdown {{ item }} ; ifup {{ item }}
loop: "{{ reload_interfaces | unique }}"

View File

@ -5,20 +5,17 @@
name: network-scripts
state: present
- include_tasks: network_scripts.yaml
- name: Create routing table in rt_tables
template:
src: rt_tables.j2
dest: /etc/iproute2/rt_tables
- name: Configure interfaces and routes with network-scripts
include: network_scripts.yaml iface={{ item }}
loop: "{{ network.network_scripts.iface }}"
when: network.network_scripts is defined
- name: Set blank routes symbol
command: echo -n
register: echo
changed_when: false
- name: Create array for interfaces to reload
set_fact:
reload_interfaces: []
changed_when: false
- name: Configure interfaces and routes with nmcli
include: network_manager.yaml iface={{ item }}
when: network.network_manager is defined

View File

@ -1,6 +1,6 @@
---
- block:
- name: Configure interface with nmcli
- name: "{{ iface.conn_name }} | Configure interface with nmcli"
community.general.nmcli:
conn_name: "{{ iface.conn_name }}"
type: "{{ iface.type | default('ethernet') }}"
@ -17,22 +17,22 @@
- Reload interface with nmcli
register: configure_interface
- name: Add interface to reload list
- name: "{{ iface.conn_name }} | Add interface to reload list"
set_fact:
reload_interfaces: "{{ reload_interfaces + [ iface.conn_name ] }}"
when: configure_interface.changed
- name: Get existing ipv4 routes
- name: "{{ iface.conn_name }} | Get existing ipv4 routes"
shell: nmcli -g ipv4.routes connection show {{ iface.conn_name }}
register: existing_routes4_res
changed_when: False
- name: Get existing ipv6 routes
- name: "{{ iface.conn_name }} | Get existing ipv6 routes"
shell: nmcli -g ipv6.routes connection show {{ iface.conn_name }}
register: existing_routes6_res
changed_when: False
- name: Set fact about existing and new ipv4/ipv6 routes
- name: "{{ iface.conn_name }} | Set fact about existing and new ipv4/ipv6 routes"
set_fact:
existing_routes4: "{{ existing_routes4_res.stdout | hash('sha256') }}"
new_routes4: "{{ (echo.stdout | hash('sha256')) if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
@ -45,7 +45,7 @@
#- debug:
# msg: "{{ '' if iface.routes4 is not defined else (iface.routes4|join(', ') | hash('sha256')) }}"
- name: Update routes and rules with nmcli
- name: "{{ iface.conn_name }} | Update routes and rules with nmcli"
community.general.nmcli:
conn_name: "{{ iface.conn_name }}"
type: "{{ iface.type | default('ethernet') }}"
@ -66,10 +66,10 @@
- Reload interface with nmcli
register: update_routes_and_rules
- name: Add interface to reload list
- name: "{{ iface.conn_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 }}"
#- debug:
# msg: "{{ reload_interfaces }}"

View File

@ -1,34 +1,40 @@
---
- block:
- name: Create interfaces config files
- name: "{{ iface.name }} | Configure interface"
template:
src: "ifcfg-{{ item.type | default('ethernet') }}.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}"
src: "ifcfg-{{ iface.type | default('ethernet') }}.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ iface.name }}"
notify:
- Up interface
loop: "{{ network.network_scripts.iface }}"
- Reload interface with ifdown ; ifup
register: configure_interface
- name: Create routing table in rt_tables
template:
src: rt_tables.j2
dest: /etc/iproute2/rt_tables
notify:
- Up interface
- name: "{{ iface.name }} | Add interface to reload list"
set_fact:
reload_interfaces: "{{ reload_interfaces + [ iface.name ] }}"
when: configure_interface.changed
- name: Create routing rules for interfaces
- name: "{{ iface.name }} | Create routing rules for interface"
template:
src: rule.j2
dest: "/etc/sysconfig/network-scripts/rule-{{ item.name }}"
dest: "/etc/sysconfig/network-scripts/rule-{{ iface.name }}"
notify:
- Up interface
loop: "{{ network.network_scripts.iface }}"
- Reload interface with ifdown ; ifup
register: create_routing_rules
- name: Create routes for interfaces
- name: "{{ iface.name }} | Add interface to reload list"
set_fact:
reload_interfaces: "{{ reload_interfaces + [ iface.name ] }}"
when: create_routing_rules.changed
- name: "{{ iface.name }} | Create routes for interface"
template:
src: route.j2
dest: "/etc/sysconfig/network-scripts/route-{{ item.name }}"
dest: "/etc/sysconfig/network-scripts/route-{{ iface.name }}"
notify:
- Up interface
loop: "{{ network.network_scripts.iface }}"
- Reload interface with ifdown ; ifup
register: create_routes
when: network.network_scripts is defined
- name: "{{ iface.name }} | Add interface to reload list"
set_fact:
reload_interfaces: "{{ reload_interfaces + [ iface.name ] }}"
when: create_routes.changed

View File

@ -1,3 +1,13 @@
---
- name: Set blank routes symbol
command: echo -n
register: echo
changed_when: false
- name: Create array for interfaces to reload
set_fact:
reload_interfaces: []
changed_when: false
- name: Include interfaces configuration tasks
include: "{{ ansible_os_family }}/{{ ansible_distribution_version }}.yaml"