Skip to content

Commit ffaae42

Browse files
Merge pull request #1012 from rabi/refactor_role
Refactor edpm_network_config role
2 parents 6ae9fe2 + f14dc48 commit ffaae42

File tree

13 files changed

+392
-249
lines changed

13 files changed

+392
-249
lines changed

roles/edpm_bootstrap/tasks/packages.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,3 @@
6161
- "'%verify' in rpm_verify_result.stderr"
6262
changed_when: false
6363
become: true
64-
65-
- name: Install and enable network service
66-
when:
67-
- (edpm_bootstrap_legacy_network_packages | length) > 0
68-
become: true
69-
block:
70-
- name: Deploy network-scripts required for deprecated network service
71-
ansible.builtin.dnf:
72-
name: "{{ edpm_bootstrap_legacy_network_packages }}"
73-
state: present
74-
register: edpm_bootstrap_legacy_network_packages_result
75-
until: edpm_bootstrap_legacy_network_packages_result is succeeded
76-
retries: "{{ edpm_bootstrap_download_retries }}"
77-
delay: "{{ edpm_bootstrap_download_delay }}"
78-
- name: Ensure network service is enabled
79-
ansible.builtin.systemd:
80-
name: "{{ edpm_bootstrap_network_service }}"
81-
enabled: true

roles/edpm_network_config/defaults/main.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
# All variables within this role should have a prefix of "edpm_network_config"
2121

22-
# This variable let the use choose which tool will be used to configure networking on hosts
22+
# This variable lets the user choose which tool will be used to configure networking on hosts
2323
# Accepted values are:
24-
# * os-net-config (default) -> the os-net-config will be used
25-
# * nmstate (experimental, unsupported) -> the network role from linux-system-roles/rhel-system-roles will be used to
26-
# configure networking on hosts. In particular, the nmstate tool should cover all the
27-
# supported scenario. Refer to nmstate.io for configuration snippets.
24+
# * os-net-config (default) -> the os-net-config tool will be used
25+
# - Can use either ifcfg or nmstate as internal provider based on edpm_network_config_nmstate
26+
# * nmstate (experimental, unsupported) -> the network role from linux-system-roles/rhel-system-roles will be used
27+
# directly to configure networking on hosts. Refer to nmstate.io for configuration snippets.
2828
edpm_network_config_tool: os-net-config
2929

3030
# Must be set to true to allow usage of nmstate as edpm_network_config_tool
@@ -48,6 +48,10 @@ edpm_network_config_debug: "{{ (ansible_verbosity | int) >= 2 | bool }}"
4848
edpm_network_config_hide_sensitive_logs: true
4949
edpm_network_config_interface_name: nic1
5050
edpm_network_config_manage_service: true
51+
# Controls which provider os-net-config uses internally:
52+
# * true (default) -> os-net-config uses nmstate provider (NetworkManager-based)
53+
# * false -> os-net-config uses ifcfg provider (legacy network scripts)
54+
# Note: This only applies when edpm_network_config_tool is 'os-net-config'
5155
edpm_network_config_nmstate: true
5256
edpm_network_config_os_net_config_mappings: {}
5357
edpm_network_config_safe_defaults: false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# Copyright 2020 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Reload NetworkManager
18+
become: true
19+
ansible.builtin.systemd:
20+
name: NetworkManager
21+
state: reloaded

roles/edpm_network_config/tasks/download_cache.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
---
2+
# Copyright 2023 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
216

317
- name: Download packages needed by linux-system-role - nmstate and nmsate provider
418
when: edpm_network_config_tool == 'nmstate' or edpm_network_config_nmstate | bool

roles/edpm_network_config/tasks/main.yml

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,25 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
- name: Fail when edpm_network_config_tool=nmstate unless edpm_network_config_tool_nmstate_override=true
18-
ansible.builtin.fail:
19-
msg: |
20-
edpm_network_config_tool=nmstate is experimental and not supported.
21-
Set edpm_network_config_tool_nmstate_override=true to continue anyway.
22-
when:
23-
- edpm_network_config_tool == 'nmstate'
24-
- not edpm_network_config_tool_nmstate_override|bool
17+
# Main orchestrator for network configuration
18+
# Supports three scenarios:
19+
# 1. Direct nmstate via linux-system-roles (edpm_network_config_tool: 'nmstate')
20+
# 2. os-net-config with nmstate provider (tool: 'os-net-config', edpm_network_config_nmstate: true)
21+
# 3. os-net-config with ifcfg provider (tool: 'os-net-config', edpm_network_config_nmstate: false)
2522

26-
- name: Install OVS NetworkManager plugin [nmstate and nmstate provider]
27-
when: edpm_network_config_tool == 'nmstate' or edpm_network_config_nmstate | bool
28-
become: true
29-
block:
30-
- name: Install OVS NetworkManager plugin [nmstate]
31-
ansible.builtin.dnf:
32-
name: "{{ edpm_network_config_systemrole_nmstate_dependencies }}"
33-
state: present
34-
register: nm_ovs_status
35-
until: nm_ovs_status is succeeded
36-
retries: "{{ edpm_network_config_download_retries }}"
37-
delay: "{{ edpm_network_config_download_delay }}"
38-
- name: Restart NetworkManager after plugin installation [nmstate]
39-
ansible.builtin.systemd:
40-
name: NetworkManager
41-
state: restarted
42-
when: nm_ovs_status.changed # noqa: no-handler
23+
- name: Setup common pre-configuration
24+
ansible.builtin.import_tasks: pre_config.yml
4325

44-
- name: Import DNS NetworkManager configs tasks
45-
ansible.builtin.import_tasks: dns_nm_configs.yml
26+
- name: Install required packages
27+
ansible.builtin.import_tasks: package_management.yml
4628

47-
- name: Configure network with network role from system roles [nmstate]
29+
- name: Configure network with nmstate tool
4830
when: edpm_network_config_tool == 'nmstate'
49-
become: true
50-
block:
51-
- name: Render network_state variable
52-
ansible.builtin.set_fact:
53-
network_state: "{{ edpm_network_config_template | from_yaml }}"
54-
- name: Load system-roles.network tasks [nmstate]
55-
ansible.builtin.include_role:
56-
name: "{{ lookup('ansible.builtin.env', 'EDPM_SYSTEMROLES', default='fedora.linux_system_roles') + '.network' }}"
31+
ansible.builtin.include_tasks: nmstate_tool.yml
5732

58-
- name: Disable auto-configuration of all interfaces by NetworkManager
33+
- name: Configure network with os-net-config tool
5934
when: edpm_network_config_tool == 'os-net-config'
60-
become: true
61-
block:
62-
- name: Set 'no-auto-default' in /etc/NetworkManager/NetworkManager.conf
63-
community.general.ini_file:
64-
path: /etc/NetworkManager/NetworkManager.conf
65-
state: present
66-
mode: "0644"
67-
no_extra_spaces: true
68-
section: main
69-
option: no-auto-default
70-
value: "*"
71-
backup: true
72-
register: nm_config_update
73-
- name: Restart NetworkManager
74-
ansible.builtin.systemd:
75-
name: NetworkManager
76-
state: restarted
77-
when: nm_config_update.changed # noqa: no-handler
78-
- name: Load edpm_network_config tasks for os-net-config tool
79-
ansible.builtin.include_tasks:
80-
file: network_config.yml
35+
ansible.builtin.include_tasks: os_net_config_tool.yml
36+
37+
- name: Run post-configuration tasks
38+
ansible.builtin.include_tasks: post_config.yml

roles/edpm_network_config/tasks/network_config.yml

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)