Skip to content

Commit d037ba4

Browse files
authored
[Ubuntu 23.10] Fix package installation failure at deploy_vm (#505)
Signed-off-by: Qi Zhang <[email protected]>
1 parent 2887517 commit d037ba4

File tree

8 files changed

+65
-19
lines changed

8 files changed

+65
-19
lines changed

autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
autoinstall:
33
version: 1
44
early-commands:
5-
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
5+
- echo 'The network interface name is' $(ip -br link show | grep -v lo | awk '{print $1}') >/dev/ttyS0
6+
- echo '{{ autoinstall_start_msg }}' $(ip -br -4 addr show | grep -v lo | awk '{print $3}') >/dev/ttyS0
67
locale: en_US.UTF-8
78
keyboard:
89
layout: us
@@ -17,6 +18,20 @@ autoinstall:
1718
realname: ubuntu
1819
username: {{ vm_username }}
1920
password: {{ vm_password_hash }}
21+
ssh:
22+
install-server: yes
23+
allow-pw: yes
24+
authorized-keys:
25+
- {{ ssh_public_key }}
26+
packages:
27+
- open-vm-tools
28+
- open-vm-tools-desktop
29+
- build-essential
30+
- sg3-utils
31+
- ndctl
32+
- rdma-core
33+
- rdmacm-utils
34+
- ibverbs-utils
2035
user-data:
2136
users:
2237
- name: root
@@ -36,12 +51,8 @@ autoinstall:
3651
preserve_sources_list: false
3752
geoip: true
3853
late-commands:
39-
- echo "# apt-get update" >> /dev/ttyS0
40-
- curtin in-target --target=/target -- apt-get update -y >> /dev/ttyS0
41-
- echo "# apt-get install build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils" >> /dev/ttyS0
42-
- curtin in-target --target=/target -- apt-get install -y --force-yes build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils >> /dev/ttyS0
4354
- rm -f /etc/cloud/cloud.cfg.d/*-installer.cfg 2>/dev/null
4455
- sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /target/etc/ssh/sshd_config
4556
- sed -i 's/^#PasswordAuthentication .*/PasswordAuthentication yes/' /target/etc/ssh/sshd_config
46-
- echo "{{ autoinstall_complete_msg }}" >> /dev/ttyS0
57+
- echo "{{ autoinstall_complete_msg }}" > /dev/ttyS0
4758
shutdown: 'poweroff'

autoinstall/Ubuntu/Server/user-data.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
autoinstall:
33
version: 1
44
early-commands:
5-
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
5+
- echo 'The network interface name is' $(ip -br link show | grep -v lo | awk '{print $1}') >/dev/ttyS0
6+
- echo '{{ autoinstall_start_msg }}' $(ip -br -4 addr show | grep -v lo | awk '{print $3}') >/dev/ttyS0
67
refresh-installer:
78
update: false
89
locale: en_US.UTF-8

common/vm_wait_log_msg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
- (get_vm_log_content.content | regex_findall(vm_wait_log_msg) | length) >= (vm_wait_log_msg_times | default(1))
5454
delay: "{{ vm_wait_log_delay | default(5) }}"
5555
retries: "{{ vm_wait_log_retries | default(60) }}"
56-
ignore_errors: "{{ vm_wait_log_ignore_errors | default(false) }}"
56+
ignore_errors: true
5757

5858
- name: "Set fact of the logs list found for specified log message"
5959
ansible.builtin.set_fact:

linux/deploy_vm/create_unattend_install_iso.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
- block:
8686
- name: "Set fact for autoinstall start message to be printed to VM serial port"
8787
ansible.builtin.set_fact:
88-
autoinstall_start_msg: "Ubuntu autoinstall is started at {{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}"
88+
autoinstall_start_msg: "Ubuntu autoinstall is started with IPv4 address:"
8989

9090
# Create the Ubuntu seed ISO to modify login information
9191
- include_tasks: ../utils/create_seed_iso.yml

linux/deploy_vm/ubuntu/ubuntu_install_os.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,36 @@
66
when: ubuntu_install_method is defined and ubuntu_install_method == "simulation"
77

88
# Wait for autoinstall start message in serial port output file
9-
- include_tasks: ../../../common/vm_wait_log_msg.yml
10-
vars:
11-
vm_wait_log_name: "{{ vm_serial_port_output_file | basename }}"
12-
vm_wait_log_msg: "{{ autoinstall_start_msg }}"
13-
vm_wait_log_retries: 150
14-
vm_wait_log_delay: 5
9+
- name: "Wait for Ubuntu autoinstall is started successfully"
1510
when: ubuntu_install_method is defined and ubuntu_install_method == "cloud-init"
11+
block:
12+
- name: "Wait for autoinstall start message"
13+
include_tasks: ../../../common/vm_wait_log_msg.yml
14+
vars:
15+
vm_wait_log_name: "{{ vm_serial_port_output_file | basename }}"
16+
vm_wait_log_msg: "{{ autoinstall_start_msg }}[^\\r\\n]*"
17+
vm_wait_log_retries: 150
18+
vm_wait_log_delay: 5
19+
20+
# Ubuntu autoinstall with cloud configs requires network connection.
21+
# When autoinstall start message is detected, its must be followed with an IPv4
22+
# address get at early-commands in the unattend install config file.
23+
# Otherwise, we can stop autoinstall immediately.
24+
- name: "Get the IPv4 address when Ubuntu autoinstall started"
25+
ansible.builtin.set_fact:
26+
ubuntu_autoinstall_start_ipv4: >-
27+
{{
28+
vm_wait_log_msg_list |
29+
map('replace', autoinstall_start_msg, '') |
30+
map('trim') |
31+
ansible.utils.ipaddr('address')
32+
}}
33+
34+
- name: "Check VM obtains IPv4 address"
35+
ansible.builtin.assert:
36+
that:
37+
- ubuntu_autoinstall_start_ipv4
38+
- ubuntu_autoinstall_start_ipv4 | length > 0
39+
- ubuntu_autoinstall_start_ipv4[0] is ansible.utils.ipv4
40+
fail_msg: "Ubuntu autoinstall failed to start due to no IPv4 address obtained."
41+
success_msg: "Ubuntu autoinstall is started with IPv4 address {{ ubuntu_autoinstall_start_ipv4 }}"

linux/utils/add_official_online_repo.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@
163163
include_tasks: replace_or_add_line_in_file.yml
164164
vars:
165165
file: "{{ apt_source_list }}"
166-
reg_exp: "{{ apt_source }}"
167-
line_content: "{{ apt_source }}"
166+
reg_exp: "{{ apt_source_item }}"
167+
line_content: "{{ apt_source_item }}"
168168
with_list: "{{ apt_sources }}"
169169
loop_control:
170-
loop_var: "apt_source"
170+
loop_var: "apt_source_item"
171171

172172
# Remove repositories from universe and multiverse
173173
- name: "Remove repositories from universe and multiverse"

linux/utils/get_network_config_file.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
- name: "Get network config file from NetworkManager"
1919
block:
2020
- name: "Get network connections"
21-
ansible.builtin.shell: "nmcli -t -f NAME,ACTIVE,FILENAME connection show --active | grep '^{{ network_adapter_name }}:'"
21+
ansible.builtin.shell: |
22+
conn_name=$(nmcli -t -f GENERAL.CONNECTION device show {{ network_adapter_name }} | cut -d ':' -f 2);
23+
nmcli -t -f NAME,ACTIVE,FILENAME connection show --active | grep "$conn_name:"
2224
delegate_to: "{{ vm_guest_ip }}"
2325
register: "network_conn_result"
2426
ignore_errors: true

linux/utils/set_network_adapter_status.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
- name: "Connect network interface '{{ network_adapter_name }}'"
2020
ansible.builtin.shell: "nmcli device connect {{ network_adapter_name }}"
2121
delegate_to: "{{ vm_guest_ip }}"
22+
register: nmcli_connect_result
23+
retries: 5
24+
delay: 5
25+
until:
26+
- nmcli_connect_result.rc is defined
27+
- nmcli_connect_result.rc == 0
2228

2329
- name: "Set expected network interface status to 'connected'"
2430
ansible.builtin.set_fact:

0 commit comments

Comments
 (0)