Skip to content

Commit 33b76a3

Browse files
authored
[Linux] Disabled IPv6 for SLED 15.7 and increased timeout for network adapter disconnection (#703)
Signed-off-by: Qi Zhang <[email protected]>
1 parent 16a6ad1 commit 33b76a3

10 files changed

+229
-222
lines changed

linux/guest_customization/linux_gosc_workflow.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777

7878
- name: "Get guest OS network manager"
7979
include_tasks: ../utils/get_network_manager.yml
80-
when: guest_os_network_manager is undefined
80+
when: >-
81+
guest_os_network_manager is undefined or
82+
not guest_os_network_manager
8183
8284
- name: "Handle known issues with workarounds"
8385
include_tasks: handle_gosc_known_issues.yml

linux/network_device_ops/apply_new_network_config.yml

Lines changed: 97 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,68 @@
66
#
77
- name: "Get guest network device manager"
88
include_tasks: ../utils/get_network_manager.yml
9+
when: >-
10+
guest_os_network_manager is undefined or
11+
not guest_os_network_manager
912
10-
- name: "Add network connection for {{ guest_os_ansible_distribution }}"
13+
- name: "Add network connection for new {{ adapter_type }} network adapter on {{ vm_guest_os_distribution }}"
1114
when: guest_os_network_manager == "NetworkManager"
1215
block:
13-
- name: "Add network connection with static IP address"
14-
block:
15-
- name: "Add a network connection with static IP address for {{ new_network_adapter }}"
16-
ansible.builtin.shell: >-
17-
nmcli connection add type ethernet
18-
ifname {{ new_network_adapter }}
19-
con-name {{ new_network_adapter }}
20-
ip4 {{ new_nic_ipv4 }}/{{ new_nic_net_prefix }}
21-
gw4 {{ new_nic_gateway }}
22-
delegate_to: "{{ vm_guest_ip }}"
23-
register: nm_add_static_conn
24-
25-
- name: "Set result of adding network connection with static IP address"
26-
ansible.builtin.set_fact:
27-
nm_add_connection: "{{ nm_add_static_conn }}"
28-
when:
29-
- new_nic_ipv4 is defined and new_nic_ipv4
30-
- new_nic_net_prefix is defined and new_nic_net_prefix
31-
- new_nic_gateway is defined and new_nic_gateway
16+
- name: "Set fact of IPv6 config in network connection for new {{ adapter_type }} network adapter"
17+
ansible.builtin.set_fact:
18+
nmcli_ipv6_method: >-
19+
{{
20+
(guest_os_ansible_distribution == 'SLED' and
21+
guest_os_ansible_distribution_ver == '15.7') |
22+
ternary('ipv6.method disabled', '')
23+
}}
24+
25+
- name: "Set fact of command for adding network connection with static IP addresss"
26+
ansible.builtin.set_fact:
27+
nmcli_connection_add_cmd: >-
28+
nmcli connection add type ethernet ifname {{ new_network_adapter }}
29+
con-name {{ new_network_adapter }} ipv4.method manual
30+
ipv4.addresses {{ new_nic_ipv4 }}/{{ new_nic_net_prefix }}
31+
ipv4.gateway {{ new_nic_gateway }} {{ nmcli_ipv6_method }}
32+
when: new_nic_ipv4_method == 'static'
33+
34+
- name: "Set fact of command for adding network connection with DHCP IP addresss"
35+
ansible.builtin.set_fact:
36+
nmcli_connection_add_cmd: >-
37+
nmcli connection add type ethernet ifname {{ new_network_adapter }}
38+
con-name {{ new_network_adapter }} {{ nmcli_ipv6_method }}
39+
when: new_nic_ipv4_method == 'dhcp'
3240

33-
- name: "Add network connection with DHCP IP address"
34-
block:
35-
- name: "Add a network connection with DHCP IP address for {{ new_network_adapter }}"
36-
ansible.builtin.shell: >-
37-
nmcli connection add type ethernet
38-
ifname {{ new_network_adapter }}
39-
con-name {{ new_network_adapter }}
40-
delegate_to: "{{ vm_guest_ip }}"
41-
register: nm_add_dhcp_conn
42-
43-
- name: "Set result of adding network connection with DHCP IP address"
44-
ansible.builtin.set_fact:
45-
nm_add_connection: "{{ nm_add_dhcp_conn }}"
46-
when: >-
47-
(new_nic_ipv4 is undefined or not new_nic_ipv4) or
48-
(new_nic_net_prefix is undefined or not new_nic_net_prefix) or
49-
(new_nic_gateway is undefined or not new_nic_gateway)
50-
51-
- name: "Check network connection is added for {{ new_network_adapter }}"
52-
ansible.builtin.assert:
53-
that:
54-
- nm_add_connection is defined
55-
- nm_add_connection.rc is defined
56-
- nm_add_connection.rc == 0
57-
fail_msg: "Failed to add network connection on VM {{ vm_name }}"
58-
success_msg: "{{ nm_add_connection.stdout |
59-
default('Successfully added network connection on VM ' ~ vm_name) }}"
41+
- name: "Add a network connection for new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
42+
ansible.builtin.shell: "{{ nmcli_connection_add_cmd }}"
43+
delegate_to: "{{ vm_guest_ip }}"
44+
register: nmcli_connection_add_result
6045

6146
# Set network config file in guest OS except VMware Photon OS
62-
- name: "Set network config file for {{ guest_os_ansible_distribution }}"
47+
- name: "Set network config file for new {{ adapter_type }} network adapter on {{ vm_guest_os_distribution }}"
6348
when:
6449
- guest_os_network_manager != "NetworkManager"
65-
- guest_os_ansible_distribution not in ["VMware Photon OS", "Astra Linux (Orel)"]
50+
- guest_os_ansible_distribution not in ["VMware Photon OS", "FreeBSD", "Astra Linux (Orel)"]
6651
block:
67-
- name: "Initialize fact of network config tempate"
52+
- name: "Initialize fact of network config template"
6853
ansible.builtin.set_fact:
6954
network_config_template: ""
7055

71-
- name: "Get network config file for '{{ new_network_adapter }}'"
56+
- name: "Get network config file for new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
7257
include_tasks: ../utils/get_network_config_file.yml
7358
vars:
7459
network_adapter_name: "{{ new_network_adapter }}"
7560

76-
- name: "Set fact of the network config template for {{ guest_os_ansible_distribution }}"
77-
ansible.builtin.set_fact:
78-
network_config_template: rhel_network_conf.j2
79-
when: guest_os_family == "RedHat"
80-
81-
- name: "Set fact of the network config template for {{ guest_os_ansible_distribution }}"
82-
ansible.builtin.set_fact:
83-
network_config_template: debian_network_conf.j2
84-
when: >
85-
(guest_os_ansible_distribution == "Debian") or
86-
(guest_os_ansible_distribution == "Pardus GNU/Linux") or
87-
(guest_os_ansible_distribution == "Ubuntu" and
88-
guest_os_with_gui is defined and guest_os_with_gui)
89-
90-
- name: "Set fact of the network config template for Ubuntu server"
91-
ansible.builtin.set_fact:
92-
network_config_template: ubuntu_netplan_conf.j2
93-
when:
94-
- guest_os_ansible_distribution == "Ubuntu"
95-
- guest_os_with_gui is defined and not guest_os_with_gui
96-
97-
- name: "Set fact of the network config template for SLE"
61+
- name: "Set fact of the network config template on {{ vm_guest_os_distribution }}"
9862
ansible.builtin.set_fact:
99-
network_config_template: sles_network_conf.j2
100-
when: guest_os_family == "Suse"
63+
network_config_template: "{{ guest_os_family | lower }}_network_conf.j2"
64+
when: guest_os_family in ["RedHat", "Suse", "Debian"]
10165

102-
- name: "Set fact of the network config template for Flatcar"
66+
- name: "Set fact of the network config template on {{ vm_guest_os_distribution }}"
10367
ansible.builtin.set_fact:
10468
network_config_template: flatcar_network_conf.j2
10569
when: guest_os_ansible_distribution == 'Flatcar'
10670

107-
- name: "Set fact of the network config template for FreeBSD"
108-
ansible.builtin.set_fact:
109-
network_config_template: freebsd_network_conf.j2
110-
when: guest_os_family == "FreeBSD"
111-
11271
- name: "Create or update network config file for new network interface"
11372
when:
11473
- network_config_template
@@ -120,13 +79,13 @@
12079
dest: "{{ network_config_path }}"
12180
mode: "0666"
12281
delegate_to: "{{ vm_guest_ip }}"
123-
82+
12483
- name: "Get content of network config file '{{ network_config_path }}'"
12584
ansible.builtin.command: "cat {{ network_config_path }}"
12685
register: network_config
12786
changed_when: false
12887
delegate_to: "{{ vm_guest_ip }}"
129-
88+
13089
- name: "Print content of network config file '{{ network_config_path }}'"
13190
ansible.builtin.debug: var=network_config.stdout_lines
13291

@@ -149,53 +108,64 @@
149108
seconds: 60
150109

151110
# Update VM's guest IP
152-
- include_tasks: ../../common/update_inventory.yml
111+
- name: "Update VM's guest IP"
112+
include_tasks: ../../common/update_inventory.yml
153113

154-
- name: "Apply new network configuration file for FreeBSD"
114+
- name: "Apply new network config for FreeBSD"
155115
when: guest_os_ansible_distribution == "FreeBSD"
156116
block:
157-
- name: "Apply new vmxnet3 network configuration for FreeBSD"
158-
when: adapter_type == "vmxnet3"
117+
- name: "Set new {{ adapter_type }} network adapter with static IPv4 address"
118+
when: new_nic_ipv4_method == "static"
159119
block:
160-
- name: "Restart network"
161-
ansible.builtin.command: "/etc/netstart"
120+
- name: "Set new {{ adapter_type }} network adapter with static IPv4 address"
121+
ansible.builtin.shell: 'sysrc ifconfig_{{ new_network_adapter }}="inet {{ new_nic_ipv4 }}/{{ new_nic_net_prefix }}"'
162122
delegate_to: "{{ vm_guest_ip }}"
163-
async: 60
164-
poll: 20
123+
124+
- name: "Restart network and routing on {{ vm_guest_os_distribution }}"
125+
ansible.builtin.shell: "service netif restart && service routing restart && dhclient {{ eth0_name }}"
126+
delegate_to: "{{ vm_guest_ip }}"
127+
async: 20
128+
poll: 0
165129
ignore_errors: true
166-
register: restart_network_result
167-
168-
- name: "Display the result to restart network"
169-
ansible.builtin.debug: var=restart_network_result
170-
when: enable_debug is defined and enable_debug
171130

172-
- name: "Update VM's guest IP after apply new network configuration"
131+
- name: "Sleep 60s for network restarting on {{ vm_guest_os_distribution }}"
132+
ansible.builtin.pause:
133+
seconds: 60
134+
135+
- name: "Update VM's guest IP in case it's changed"
173136
include_tasks: ../../common/update_inventory.yml
174137

175-
- name: "Reboot to apply new e1000e network configuration for FreeBSD"
176-
include_tasks: ../utils/reboot.yml
177-
when: adapter_type == "e1000e"
138+
- name: "Set new {{ adapter_type }} network adapter with DHCP IPv4 address"
139+
when: new_nic_ipv4_method == "dhcp"
140+
block:
141+
- name: "Set new {{ adapter_type }} network adapter with static IPv4 address"
142+
ansible.builtin.shell: 'sysrc ifconfig_{{ new_network_adapter }}="DHCP"'
143+
delegate_to: "{{ vm_guest_ip }}"
144+
145+
- name: "Get DHCP IPv4 address for new {{ adapter_type }} network adapter"
146+
ansible.builtin.shell: "dhclient {{ new_network_adapter }}"
147+
delegate_to: "{{ vm_guest_ip }}"
178148

179-
- include_tasks: ../utils/set_network_adapter_status.yml
149+
- name: "Bring up the new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
150+
include_tasks: ../utils/set_network_adapter_status.yml
180151
vars:
181152
network_adapter_name: "{{ new_network_adapter }}"
182153
network_adapter_status: "up"
183-
when:
184-
- guest_os_network_manager != "netplan"
154+
when: guest_os_network_manager != "netplan"
185155

186156
# Get IP address of new interface
187157
- name: "Set fact of searching IPv4 address"
188158
ansible.builtin.set_fact:
189-
search_ip: "{% if adapter_type == 'pvrdma' %}{{ new_nic_ipv4 }}{% else %}192.168{% endif %}"
159+
search_ip: "{% if new_nic_ipv4 is defined and new_nic_ipv4 %}{{ new_nic_ipv4 }}{% else %}192.168{% endif %}"
190160

191-
- name: "Set command to get link status for the new network adapter"
161+
- name: "Set command to get IP addresses of the new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
192162
ansible.builtin.set_fact:
193163
get_link_status_cmd: |-
194164
{%- if guest_os_ansible_distribution == 'FreeBSD' -%}ifconfig {{ new_network_adapter }} | grep inet | grep -v inet6 | awk '{print $2}'
195165
{%- else -%}ip -br addr show {{ new_network_adapter }} | awk '{print $3}'
196166
{%- endif -%}
197167
198-
- name: "Wait for network adapter '{{ new_network_adapter }}' IPv4 address"
168+
- name: "Wait for IPv4 address of the new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
199169
ansible.builtin.shell: "{{ get_link_status_cmd }}"
200170
register: link_status
201171
changed_when: false
@@ -208,28 +178,35 @@
208178
delegate_to: "{{ vm_guest_ip }}"
209179
ignore_errors: true
210180

211-
- name: "Check network adapter '{{ new_network_adapter }}' IPv4 address"
181+
- name: "Print IP addresses of the new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
182+
ansible.builtin.debug: var=link_status
183+
184+
- name: "Check IPv4 address of the new {{ adapter_type }} network adapter '{{ new_network_adapter }}'"
212185
ansible.builtin.assert:
213186
that:
214187
- link_status is defined
215188
- link_status.stdout is defined
216189
- search_ip in link_status.stdout
217190
fail_msg: >-
218-
Network adapter '{{ new_network_adapter }}' on VM {{ vm_name }}
219-
failed to obtain IPv4 address after 100 seconds.
220-
Its current IPv4 address is '{{ link_status.stdout | default("") }}'.
191+
The new {{ adapter_type }} network adapter '{{ new_network_adapter }}'
192+
failed to obtain IPv4 address in 100 seconds. The command '{{ get_link_status_cmd }}'
193+
returned '{{ link_status | default("") }}'.
221194
222-
- name: "Print the new networ adapter IP address"
223-
ansible.builtin.debug: var=link_status
195+
- name: "Get the new {{ adapter_type }} newtwork adapter status after applying network config"
196+
include_tasks: ../utils/get_network_adapters_status.yml
224197

225-
- include_tasks: ../utils/get_network_adapters_status.yml
226-
- name: "Update the new network adapter status"
198+
- name: "Update the new network adapter status after applying network config"
227199
ansible.builtin.set_fact:
228-
new_network_adapter_status: "{{ (guest_network_adapters_status | selectattr('device', 'equalto', new_network_adapter))[0] }}"
200+
new_network_adapter_status: "{{ guest_network_adapters_status | selectattr('device', 'equalto', new_network_adapter) | first }}"
229201

230-
- name: "Print the new network adapter status after applying new network config"
231-
ansible.builtin.debug: var=new_network_adapter_status
232-
233-
- name: "Set the new network adapter ip address after applying new network config"
202+
- name: "Set fact of the new {{ adapter_type }} network adapter's IPv4 address"
234203
ansible.builtin.set_fact:
235-
new_network_adapter_ip: "{{ link_status.stdout }}"
204+
new_network_adapter_ip: >-
205+
{{
206+
(new_network_adapter_status.ipv4 | type_debug == "list") |
207+
ternary(new_network_adapter_status.ipv4[0].address | default('') ,
208+
new_network_adapter_status.ipv4.address | default(''))
209+
}}
210+
when:
211+
- new_network_adapter_status.ipv4 is defined
212+
- new_network_adapter_status.ipv4 | type_debug in ['list', 'dict']
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
{% if guest_os_ansible_distribution == "Ubuntu" and guest_os_network_manager == "netplan" %}
2+
{%- include 'ubuntu_netplan_conf.j2' -%}
3+
{% else %}
14
auto lo
25
iface lo inet loopback
36
{% for dev in network_adapters_after_hotadd %}
47

58
auto {{ dev }}
69
iface {{ dev }} inet dhcp
7-
{% if dev != eth0_name %}
10+
{%- if dev != eth0_name %}
811
metric 200
912
allow-hotplug {{ dev }}
10-
{% else %}
13+
{%- else %}
1114
metric 100
12-
{% endif %}
15+
{%- endif %}
1316
{% endfor %}
17+
{% endif %}

linux/network_device_ops/freebsd_network_conf.j2

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

0 commit comments

Comments
 (0)