Skip to content

Commit

Permalink
[Ubuntu 23.10] Fix package installation failure at deploy_vm (#505)
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <qiz@vmware.com>
  • Loading branch information
keirazhang authored Sep 27, 2023
1 parent 2887517 commit d037ba4
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
23 changes: 17 additions & 6 deletions autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
autoinstall:
version: 1
early-commands:
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
- echo 'The network interface name is' $(ip -br link show | grep -v lo | awk '{print $1}') >/dev/ttyS0
- echo '{{ autoinstall_start_msg }}' $(ip -br -4 addr show | grep -v lo | awk '{print $3}') >/dev/ttyS0
locale: en_US.UTF-8
keyboard:
layout: us
Expand All @@ -17,6 +18,20 @@ autoinstall:
realname: ubuntu
username: {{ vm_username }}
password: {{ vm_password_hash }}
ssh:
install-server: yes
allow-pw: yes
authorized-keys:
- {{ ssh_public_key }}
packages:
- open-vm-tools
- open-vm-tools-desktop
- build-essential
- sg3-utils
- ndctl
- rdma-core
- rdmacm-utils
- ibverbs-utils
user-data:
users:
- name: root
Expand All @@ -36,12 +51,8 @@ autoinstall:
preserve_sources_list: false
geoip: true
late-commands:
- echo "# apt-get update" >> /dev/ttyS0
- curtin in-target --target=/target -- apt-get update -y >> /dev/ttyS0
- 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
- 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
- rm -f /etc/cloud/cloud.cfg.d/*-installer.cfg 2>/dev/null
- sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /target/etc/ssh/sshd_config
- sed -i 's/^#PasswordAuthentication .*/PasswordAuthentication yes/' /target/etc/ssh/sshd_config
- echo "{{ autoinstall_complete_msg }}" >> /dev/ttyS0
- echo "{{ autoinstall_complete_msg }}" > /dev/ttyS0
shutdown: 'poweroff'
3 changes: 2 additions & 1 deletion autoinstall/Ubuntu/Server/user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
autoinstall:
version: 1
early-commands:
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
- echo 'The network interface name is' $(ip -br link show | grep -v lo | awk '{print $1}') >/dev/ttyS0
- echo '{{ autoinstall_start_msg }}' $(ip -br -4 addr show | grep -v lo | awk '{print $3}') >/dev/ttyS0
refresh-installer:
update: false
locale: en_US.UTF-8
Expand Down
2 changes: 1 addition & 1 deletion common/vm_wait_log_msg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
- (get_vm_log_content.content | regex_findall(vm_wait_log_msg) | length) >= (vm_wait_log_msg_times | default(1))
delay: "{{ vm_wait_log_delay | default(5) }}"
retries: "{{ vm_wait_log_retries | default(60) }}"
ignore_errors: "{{ vm_wait_log_ignore_errors | default(false) }}"
ignore_errors: true

- name: "Set fact of the logs list found for specified log message"
ansible.builtin.set_fact:
Expand Down
2 changes: 1 addition & 1 deletion linux/deploy_vm/create_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
- block:
- name: "Set fact for autoinstall start message to be printed to VM serial port"
ansible.builtin.set_fact:
autoinstall_start_msg: "Ubuntu autoinstall is started at {{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}"
autoinstall_start_msg: "Ubuntu autoinstall is started with IPv4 address:"

# Create the Ubuntu seed ISO to modify login information
- include_tasks: ../utils/create_seed_iso.yml
Expand Down
38 changes: 32 additions & 6 deletions linux/deploy_vm/ubuntu/ubuntu_install_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,36 @@
when: ubuntu_install_method is defined and ubuntu_install_method == "simulation"

# Wait for autoinstall start message in serial port output file
- include_tasks: ../../../common/vm_wait_log_msg.yml
vars:
vm_wait_log_name: "{{ vm_serial_port_output_file | basename }}"
vm_wait_log_msg: "{{ autoinstall_start_msg }}"
vm_wait_log_retries: 150
vm_wait_log_delay: 5
- name: "Wait for Ubuntu autoinstall is started successfully"
when: ubuntu_install_method is defined and ubuntu_install_method == "cloud-init"
block:
- name: "Wait for autoinstall start message"
include_tasks: ../../../common/vm_wait_log_msg.yml
vars:
vm_wait_log_name: "{{ vm_serial_port_output_file | basename }}"
vm_wait_log_msg: "{{ autoinstall_start_msg }}[^\\r\\n]*"
vm_wait_log_retries: 150
vm_wait_log_delay: 5

# Ubuntu autoinstall with cloud configs requires network connection.
# When autoinstall start message is detected, its must be followed with an IPv4
# address get at early-commands in the unattend install config file.
# Otherwise, we can stop autoinstall immediately.
- name: "Get the IPv4 address when Ubuntu autoinstall started"
ansible.builtin.set_fact:
ubuntu_autoinstall_start_ipv4: >-
{{
vm_wait_log_msg_list |
map('replace', autoinstall_start_msg, '') |
map('trim') |
ansible.utils.ipaddr('address')
}}
- name: "Check VM obtains IPv4 address"
ansible.builtin.assert:
that:
- ubuntu_autoinstall_start_ipv4
- ubuntu_autoinstall_start_ipv4 | length > 0
- ubuntu_autoinstall_start_ipv4[0] is ansible.utils.ipv4
fail_msg: "Ubuntu autoinstall failed to start due to no IPv4 address obtained."
success_msg: "Ubuntu autoinstall is started with IPv4 address {{ ubuntu_autoinstall_start_ipv4 }}"
6 changes: 3 additions & 3 deletions linux/utils/add_official_online_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@
include_tasks: replace_or_add_line_in_file.yml
vars:
file: "{{ apt_source_list }}"
reg_exp: "{{ apt_source }}"
line_content: "{{ apt_source }}"
reg_exp: "{{ apt_source_item }}"
line_content: "{{ apt_source_item }}"
with_list: "{{ apt_sources }}"
loop_control:
loop_var: "apt_source"
loop_var: "apt_source_item"

# Remove repositories from universe and multiverse
- name: "Remove repositories from universe and multiverse"
Expand Down
4 changes: 3 additions & 1 deletion linux/utils/get_network_config_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
- name: "Get network config file from NetworkManager"
block:
- name: "Get network connections"
ansible.builtin.shell: "nmcli -t -f NAME,ACTIVE,FILENAME connection show --active | grep '^{{ network_adapter_name }}:'"
ansible.builtin.shell: |
conn_name=$(nmcli -t -f GENERAL.CONNECTION device show {{ network_adapter_name }} | cut -d ':' -f 2);
nmcli -t -f NAME,ACTIVE,FILENAME connection show --active | grep "$conn_name:"
delegate_to: "{{ vm_guest_ip }}"
register: "network_conn_result"
ignore_errors: true
Expand Down
6 changes: 6 additions & 0 deletions linux/utils/set_network_adapter_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
- name: "Connect network interface '{{ network_adapter_name }}'"
ansible.builtin.shell: "nmcli device connect {{ network_adapter_name }}"
delegate_to: "{{ vm_guest_ip }}"
register: nmcli_connect_result
retries: 5
delay: 5
until:
- nmcli_connect_result.rc is defined
- nmcli_connect_result.rc == 0

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

0 comments on commit d037ba4

Please sign in to comment.