feat: add option to manage networkmanager config files
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f3f3b46f1e
commit
233cf83f87
@ -39,3 +39,10 @@ network_hosts_extra: []
|
|||||||
# fqdn: myhost.rknet.org
|
# fqdn: myhost.rknet.org
|
||||||
# address: 1.2.3.4
|
# address: 1.2.3.4
|
||||||
# @end
|
# @end
|
||||||
|
|
||||||
|
network_nm_config: {}
|
||||||
|
# @var network_nm_config:example: >
|
||||||
|
# network_nm_config:
|
||||||
|
# unmanaged: |
|
||||||
|
# [keyfile]
|
||||||
|
# unmanaged-devices=interface-name:ens*
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
---
|
---
|
||||||
|
- name: Set flag require_reboot
|
||||||
|
set_fact:
|
||||||
|
__network_require_reboot: True
|
||||||
|
listen: __network_host_reboot
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Restart network
|
- name: Restart network
|
||||||
shell: "{{ __network_restart_command }}"
|
shell: "{{ __network_restart_command }}"
|
||||||
async: 1
|
async: 1
|
||||||
poll: 0
|
poll: 0
|
||||||
when:
|
when:
|
||||||
|
- (not __network_require_reboot | bool) or (not network_reboot_enabled | bool)
|
||||||
- network_restart_enabled | bool
|
- network_restart_enabled | bool
|
||||||
- not require_reboot | bool
|
|
||||||
listen: __network_restart
|
listen: __network_restart
|
||||||
tags:
|
tags:
|
||||||
- skip_ansible_later
|
- skip_ansible_later
|
||||||
@ -17,8 +22,8 @@
|
|||||||
async: 1
|
async: 1
|
||||||
poll: 0
|
poll: 0
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
when: require_reboot | bool
|
when: network_reboot_enabled | bool
|
||||||
listen: __host_reboot
|
listen: __network_host_reboot
|
||||||
become: True
|
become: True
|
||||||
become_user: root
|
become_user: root
|
||||||
|
|
||||||
@ -26,7 +31,7 @@
|
|||||||
wait_for_connection:
|
wait_for_connection:
|
||||||
delay: 5
|
delay: 5
|
||||||
timeout: 300
|
timeout: 300
|
||||||
when: (require_reboot | bool) or (network_restart_enabled | bool)
|
when: (network_reboot_enabled | bool) or (network_restart_enabled | bool)
|
||||||
listen:
|
listen:
|
||||||
- __network_restart
|
- __network_restart
|
||||||
- __host_reboot
|
- __network_host_reboot
|
||||||
|
@ -12,4 +12,6 @@
|
|||||||
- "vars"
|
- "vars"
|
||||||
when: var_files
|
when: var_files
|
||||||
|
|
||||||
|
- include_tasks: nm.yml
|
||||||
|
when: __network_nmcli | bool
|
||||||
- include_tasks: setup.yml
|
- include_tasks: setup.yml
|
||||||
|
32
tasks/nm.yml
Normal file
32
tasks/nm.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: Add NetworkManager configuration
|
||||||
|
copy:
|
||||||
|
content: "{{ item.value }}"
|
||||||
|
dest: "/etc/NetworkManager/conf.d/{{ item.key }}.conf"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0640
|
||||||
|
loop: "{{ network_nm_config | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
notify: __network_host_reboot
|
||||||
|
|
||||||
|
- name: Register active NetworkManager configuration
|
||||||
|
find:
|
||||||
|
paths: /etc/NetworkManager/conf.d/
|
||||||
|
file_type: file
|
||||||
|
patterns: "*.conf"
|
||||||
|
register: __network_nm_config_active
|
||||||
|
changed_when: False
|
||||||
|
failed_when: False
|
||||||
|
|
||||||
|
- name: Remove unmanaged NetworkManager configuration
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ __network_nm_config_active.files | map(attribute='path') | list }}"
|
||||||
|
notify: __network_host_reboot
|
||||||
|
when: (item | basename | splitext | first) not in (network_nm_config | dict2items | map(attribute='key') | list)
|
||||||
|
become: True
|
||||||
|
become_user: root
|
@ -1,14 +1,10 @@
|
|||||||
---
|
---
|
||||||
- name: Set flag require_reboot
|
|
||||||
set_fact:
|
|
||||||
require_reboot: "{{ True if (network_fqdn != ansible_fqdn and network_reboot_enabled | bool) else False }}"
|
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Set hostname
|
- name: Set hostname
|
||||||
hostname:
|
hostname:
|
||||||
name: "{{ network_hostname }}"
|
name: "{{ network_hostname }}"
|
||||||
when: network_hostname
|
when: network_hostname
|
||||||
notify: __host_reboot
|
notify: __network_host_reboot
|
||||||
|
|
||||||
- name: Write hosts file
|
- name: Write hosts file
|
||||||
template:
|
template:
|
||||||
@ -17,7 +13,7 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: 0644
|
mode: 0644
|
||||||
notify: __host_reboot
|
notify: __network_host_reboot
|
||||||
|
|
||||||
- name: Add network interface configuration
|
- name: Add network interface configuration
|
||||||
template:
|
template:
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
---
|
---
|
||||||
|
__network_nmcli: False
|
||||||
__network_restart_command: systemctl restart network
|
__network_restart_command: systemctl restart network
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
__network_nmcli: True
|
||||||
__network_restart_command: |-
|
__network_restart_command: |-
|
||||||
nmcli connection reload
|
nmcli connection reload
|
||||||
{%- for file in __network_ifcfg | json_query('results[?changed==`true`].dest') %}
|
{%- for file in __network_ifcfg | json_query('results[?changed==`true`].dest') %}
|
||||||
|
Loading…
Reference in New Issue
Block a user