-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathmain.yml
222 lines (201 loc) · 7.45 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# SPDX-License-Identifier: BSD-3-Clause
# get service facts, used in defaults/main.yml
---
- name: Ensure ansible_facts used by role
include_tasks: tasks/set_facts.yml
- name: Print network provider
debug:
msg: "Using network provider: {{ network_provider }}"
- name: Abort applying the network state configuration if using the
`network_state` variable with the initscripts provider
fail:
msg: Only the `nm` provider supports using the `network_state` variable
when:
- network_state != {}
- network_provider == "initscripts"
- name: Abort applying the network state configuration if the system version
of the managed host is below 8
fail:
msg: The `network_state` variable uses nmstate backend which is only
supported since RHEL-8
when:
- network_state != {}
- ansible_distribution_major_version | int < 8
- name: Abort applying teaming configuration if the system version
of the managed host is EL10 or later
fail:
msg: >-
Teaming is not supported in
{{ ansible_distribution }}-{{ ansible_distribution_major_version }} -
use bonding instead
when:
- ansible_distribution_major_version | int > 9
- ansible_distribution in __network_rh_distros
- network_connections | selectattr("type", "defined") |
selectattr("type", "match", "^team$") | list | length > 0 or
network_state.get("interfaces", []) | selectattr("type", "defined") |
selectattr("type", "match", "^team$") | list | length > 0
- name: Check if updates for network packages are available through the DNF
package manager due to wireless or team interfaces
dnf:
update_cache: true
name: "{{ network_packages }}"
state: latest # noqa package-latest
register: dnf_package_update_info
check_mode: true
when:
- ansible_distribution == 'Fedora' or
ansible_distribution_major_version | int > 7
- __network_wireless_connections_defined
or __network_team_connections_defined
- not __network_is_ostree
- name: Check if updates for network packages are available through the YUM
package manager due to wireless or team interfaces
yum:
update_cache: true
name: "{{ network_packages }}" # noqa package-latest
state: latest
register: yum_package_update_info
check_mode: true
when:
- ansible_distribution_major_version | int < 8
- __network_wireless_connections_defined
or __network_team_connections_defined
- not __network_is_ostree
- name: Ask user's consent to restart NetworkManager due to wireless or team
interfaces
fail:
msg: NetworkManager needs to be restarted to be able to proceed
because wireless and team interfaces are defined. This might
disturb the connectivity of the managed system. Please set
`network_allow_restart` to `true` if you are prepared for this.
Notice that the necessary action is to install NetworkManager-wifi or
NetworkManager-team plugin and to restart NetworkManager.
register: __network_service_restart_requested
when:
- __network_wireless_connections_defined
or __network_team_connections_defined
- network_provider == "nm"
- not network_allow_restart
- dnf_package_update_info is changed or yum_package_update_info is changed
# Depending on the plugins, checking installed packages might be slow
# for example subscription manager might slow this down
# Therefore install packages only when rpm does not find them
- name: Install packages
package:
name: "{{ network_packages }}"
state: present
use: "{{ (__network_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- not network_packages is subset(ansible_facts.packages.keys())
register: __network_package_install
until: __network_package_install is success
retries: 6
delay: 10
- name: Install NetworkManager and nmstate when using network_state variable
package:
name:
- NetworkManager
- nmstate
state: present
use: "{{ (__network_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- network_state != {}
- ansible_distribution == 'Fedora' and
ansible_distribution_major_version | int > 27 or
ansible_distribution != 'Fedora' and
ansible_distribution_major_version | int > 7
- name: Install python3-libnmstate when using network_state variable
package:
name:
- python3-libnmstate
state: present
use: "{{ (__network_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- network_state != {}
- ansible_distribution == 'Fedora' and
ansible_distribution_major_version | int > 34 or
ansible_distribution != 'Fedora' and
ansible_distribution_major_version | int > 8
# If network packages changed and wireless or team connections are specified,
# NetworkManager must be restarted, and the user needs to explicitly consent
# to restart NetworkManager by setting `network_allow_restart` to `true`
- name: Restart NetworkManager due to wireless or team interfaces
service:
name: NetworkManager
state: restarted
when:
- __network_wireless_connections_defined
or __network_team_connections_defined
- network_provider == "nm"
- network_allow_restart
# ansible-lint wants this to be a handler, but this is not appropriate as
# NetworkManager must be restarted prior to the connections being created.
# see (https://docs.ansible.com/ansible-lint/rules/default_rules.html)
- __network_package_install.changed # noqa no-handler
- name: Enable and start NetworkManager
service:
name: "{{ network_service_name }}"
state: started
enabled: true
when:
- network_provider == "nm" or network_state != {}
no_log: true
# If any 802.1x connections are used, the wpa_supplicant
# service is required to be running
- name: Enable and start wpa_supplicant
service:
name: wpa_supplicant
state: started
enabled: true
when:
- network_provider == "nm"
- __network_wpa_supplicant_required
- name: Enable network service
service:
name: "{{ network_service_name }}"
enabled: true
when:
- network_provider == "initscripts"
no_log: true
- name: Ensure initscripts network file dependency is present
copy:
dest: /etc/sysconfig/network
content: "# Created by network system role"
mode: "0644"
force: false
when:
- network_provider == "initscripts"
- name: Configure networking connection profiles
network_connections:
provider: "{{ network_provider | mandatory }}"
ignore_errors: "{{ network_ignore_errors | default(omit) }}"
force_state_change: "{{ network_force_state_change | default(omit) }}"
connections: "{{ network_connections | default([]) }}"
__debug_flags: "{{ __network_debug_flags | default(omit) }}"
__header: "{{ __lsr_ansible_managed }}"
vars:
__lsr_ansible_managed: "{{ lookup('template', 'get_ansible_managed.j2') }}"
register: __network_connections_result
- name: Configure networking state
network_state:
desired_state: "{{ network_state }}"
register: __network_state_result
when: network_state != {}
- name: Show stderr messages for the network_connections
debug:
var: __network_connections_result.stderr_lines
- name: Show debug messages for the network_connections
debug:
var: __network_connections_result
verbosity: 1
- name: Show debug messages for the network_state
debug:
var: __network_state_result
verbosity: 1
when: network_state != {}
- name: Re-test connectivity
ping: