Skip to content

Commit

Permalink
Add debug messages for OVA deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <qiz@vmware.com>
  • Loading branch information
keirazhang committed Aug 7, 2023
1 parent 117293c commit f914e92
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
delegate_to: "{{ vm_guest_ip }}"
when: guest_os_ansible_distribution not in ['Flatcar', 'RHCOS']

# Ensure /var/vss.log is absent
- name: "Remove {{ vss_log_path }} if it exists"
ansible.builtin.file:
path: "{{ vss_log_path }}"
Expand All @@ -77,11 +76,6 @@
is_quiesce: "yes"
dump_memory: "no"

# After snapshot is taken, check log file /var/vss.log in guest, which should have below contents:
# /usr/sbin/pre-freeze-script freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
# /usr/sbin/post-thaw-script thaw
- name: "Check {{ vss_log_path }} existence"
include_tasks: ../utils/get_file_stat_info.yml
vars:
Expand All @@ -105,6 +99,11 @@
register: vss_content

# Guest OS is not Flatcar or RHCOS
# After quiesce snapshot is taken, guest log file /vss.log should have below contents:
# /usr/sbin/pre-freeze-script freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
# /usr/sbin/post-thaw-script thaw
- name: "Check file content in {{ vss_log_path }}"
ansible.builtin.assert:
that:
Expand All @@ -118,6 +117,9 @@
when: guest_os_ansible_distribution not in ['Flatcar', 'RHCOS']

# Guest OS is Flatcar or RHCOS
# After quiesce snapshot is taken, guest log file /var/vss.log should have below contents:
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
- name: "Check file content in {{ vss_log_path }}"
ansible.builtin.assert:
that:
Expand Down
65 changes: 30 additions & 35 deletions linux/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# OVA file on NFS server
- name: "Get OVA path and file name after mounting NFS storage at local"
when: ova_nfs_server_path is defined and ova_nfs_server_path
block:
- name: "Mount NFS storage at local"
include_tasks: ../../common/mount_nfs_storage_local.yml
Expand All @@ -27,7 +28,6 @@
ansible.builtin.set_fact:
vm_ova_path: "{{ nfs_mount_dir }}/{{ ova_path }}"
vm_ova_name: "{{ ova_path | basename }}"
when: ova_nfs_server_path is defined and ova_nfs_server_path
# Check OVA file exists
- name: "Check for {{ vm_ova_path }} existence"
ansible.builtin.stat:
Expand Down Expand Up @@ -88,11 +88,9 @@
- (hardware_version == "latest" or
(vm_hardware_version_num | int < hardware_version | int))

# Add serial port for Ubuntu OVA in case of hang at boot time
# Add serial port for Flatcar and RHCOS for collecting console output
# Add serial port for collecting messages
- name: "Add a serial port for VM"
include_tasks: ../../common/vm_add_serial_port.yml
when: ova_guest_os_type in ['ubuntu', 'flatcar', 'rhcos']

- name: "Reconfigure VM with cloud-init"
include_tasks: reconfigure_vm_with_cloudinit.yml
Expand All @@ -109,39 +107,36 @@
reconfiguration. Please add it if needed or the following tests might fail.
when: ova_guest_os_type == 'unknown'

- name: "Remove serial port"
when: ova_guest_os_type in ['ubuntu', 'flatcar', 'rhcos']
block:
- name: "Shutdown guest OS"
include_tasks: ../utils/shutdown.yml
- name: "Shutdown guest OS"
include_tasks: ../utils/shutdown.yml

- name: "Collect serial port log before removing serial port"
include_tasks: collect_serial_port_log.yml
- name: "Collect serial port log before removing serial port"
include_tasks: collect_serial_port_log.yml

- name: "Remove serial port from VM"
include_tasks: ../../common/vm_remove_serial_port.yml
- name: "Remove serial port from VM"
include_tasks: ../../common/vm_remove_serial_port.yml

# The workaround "Remove CDROM" for issue: https://bugs.launchpad.net/cloud-init/+bug/1992509
- name: "Remove existing CDROMs"
include_tasks: ../../common/vm_configure_cdrom.yml
vars:
cdrom_type: client
cdrom_controller_type: "{{ vm_cdrom.controller_label.split()[0] | lower }}"
cdrom_controller_num: "{{ vm_cdrom.bus_num }}"
cdrom_unit_num: "{{ vm_cdrom.unit_num }}"
cdrom_state: absent
with_items: "{{ vm_existing_cdrom_list }}"
loop_control:
loop_var: vm_cdrom
when:
- ova_guest_os_type == 'ubuntu'
- vm_existing_cdrom_list is defined
- vm_existing_cdrom_list | length > 0

- name: "Power on VM"
include_tasks: ../../common/vm_set_power_state.yml
vars:
vm_power_state_set: 'powered-on'
# The workaround "Remove CDROM" for issue: https://bugs.launchpad.net/cloud-init/+bug/1992509
- name: "Remove existing CDROMs"
include_tasks: ../../common/vm_configure_cdrom.yml
vars:
cdrom_type: client
cdrom_controller_type: "{{ vm_cdrom.controller_label.split()[0] | lower }}"
cdrom_controller_num: "{{ vm_cdrom.bus_num }}"
cdrom_unit_num: "{{ vm_cdrom.unit_num }}"
cdrom_state: absent
with_items: "{{ vm_existing_cdrom_list }}"
loop_control:
loop_var: vm_cdrom
when:
- guest_os_ansible_distribution == "Ubuntu"
- vm_existing_cdrom_list is defined
- vm_existing_cdrom_list | length > 0

- name: "Power on VM"
include_tasks: ../../common/vm_set_power_state.yml
vars:
vm_power_state_set: 'powered-on'
rescue:
- name: "Collect serial port log at test failure"
include_tasks: collect_serial_port_log.yml
Expand All @@ -152,6 +147,7 @@
exit_testing_when_fail: true
always:
- name: "Unmount NFS share folder and remove mount folder"
when: nfs_mount_dir is defined and nfs_mount_dir
block:
- name: "Umount NFS share points"
include_tasks: ../../common/local_unmount.yml
Expand All @@ -165,7 +161,6 @@
vars:
local_path: "{{ nfs_mount_dir }}"
del_local_file_ignore_errors: true
when: nfs_mount_dir is defined and nfs_mount_dir

- name: "Collect VM deployment logs"
include_tasks: collect_vm_logs.yml
8 changes: 4 additions & 4 deletions linux/deploy_vm/flatcar/generate_ignition_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
ignition_sshd_config: "{{ 'PermitRootLogin yes\nPasswordAuthentication yes\n' | b64encode }}"

# Put SSH public key into ignition config file
- name: "Generation ignition config file {{ ignition_config_file }}"
- name: "Generation Ignition config file {{ ignition_config_file }}"
ansible.builtin.template:
src: ignition_config.j2
dest: "{{ ignition_config_file }}"
mode: "0644"
register: generate_ignition

- name: "Assert {{ ignition_config_file }} is generated"
- name: "Assert Ignition config file is generated"
ansible.builtin.assert:
that:
- generate_ignition.changed
fail_msg: "Failed to generate {{ ignition_config_file }}"
success_msg: "Successfully generated {{ ignition_config_file }}"

- name: "Generate base64 encoded string for {{ ignition_config_file }}"
- name: "Generate base64 encoded data for {{ ignition_config_file }}"
ansible.builtin.set_fact:
ignition_config_data: "{{ lookup('file', ignition_config_file) | b64encode }}"

- name: "Display base64 encoded data"
- name: "Display base64 encoded data of Ignition config file {{ ignition_config_file }}"
ansible.builtin.debug: var=ignition_config_data
22 changes: 22 additions & 0 deletions linux/deploy_vm/reconfigure_vm_with_cloudinit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
- name: "Set fact of cloud-init final message"
ansible.builtin.set_fact:
cloudinit_final_msg: "The system is finally up, after $UPTIME seconds"
cloudinit_runcmd:
- "echo 'Get OS release info' >/dev/ttyS0"
- "cat /etc/os-release >/dev/ttyS0"
- "echo 'Update sshd settings in cloud-init config' >/dev/ttyS0"
- "sed -i 's/^disable_root:.*/disable_root: false/' /etc/cloud/cloud.cfg"
- "sed -i 's/^ssh_pwauth:.*/ssh_pwauth: true/' /etc/cloud/cloud.cfg"
- "echo 'Update sshd config to permit root login and password authentication' >/dev/ttyS0"
- "sed -i 's/^#*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config"
- "sed -i 's/^#*PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config"

- name: "Update cloud-init runcmd for {{ ova_guest_os_type | capitalize }}"
ansible.builtin.set_fact:
cloudinit_runcmd: >-
{{
cloudinit_runcmd |
union(["echo 'Restart sshd service' >/dev/ttyS0",
"systemctl restart sshd",
"echo 'Get sshd service status' >/dev/ttyS0",
"systemctl status sshd >/dev/ttyS0"
])
}}
when: ova_guest_os_type in ['amazon', 'ubuntu']

- name: "Create cloud-init seed ISO to configure guest OS"
include_tasks: ../utils/create_seed_iso.yml
Expand Down
2 changes: 1 addition & 1 deletion linux/deploy_vm/reconfigure_vm_with_ignition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: "Generate Ignition config file"
include_tasks: flatcar/generate_ignition_config.yml

- name: "Defining the Ignition configs in Guestinfo"
- name: "Define Ignition configs in VM guestinfo"
include_tasks: ../../common/vm_set_extra_config.yml
vars:
vm_advanced_settings:
Expand Down
9 changes: 5 additions & 4 deletions linux/deploy_vm/templates/amazon-ova-user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ users:
{% endif %}

runcmd:
- [ sed, -i, "s/^#PermitRootLogin .*/PermitRootLogin yes/", "/etc/ssh/sshd_config"]
- [ sed, -i, "s/^disable_root:.*/disable_root: false/", "/etc/cloud/cloud.cfg"]
- [ sed, -i, "s/^ssh_pwauth:.*/ssh_pwauth: true/", "/etc/cloud/cloud.cfg"]
- [ sed, -i, "s/^repo_upgrade:.*/repo_upgrade: none/", "/etc/cloud/cloud.cfg"]
{% for cmd in cloudinit_runcmd %}
- {{ cmd }}
{% endfor %}
- echo "Disable repo upgrade in cloud-init config" >/dev/ttyS0
- sed -i "s/^repo_upgrade:.*/repo_upgrade: none/" /etc/cloud/cloud.cfg

write_files:
- content: |
Expand Down
11 changes: 7 additions & 4 deletions linux/deploy_vm/templates/photon-ova-user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ users:

# Workaround for root password setting when shadow version is 4.6-5 and earlier
bootcmd:
- shadow_version=$(rpm -q shadow | grep -E -o "[0-9]+(\.[0-9]+)+-[0-9]+"); [ $(printf "$shadow_version\n4.6-6\n" | sort | head -n 1) != "4.6-6" ] && /bin/sed -E -i 's/^root:([^:]+):.*$/root:\1:17532:0:99999:0:::/' /etc/shadow
- echo "Running cloud-init bootcmd" >/dev/ttyS0
- shadow_version=$(rpm -q shadow | grep -E -o "[0-9]+(\.[0-9]+)+-[0-9]+"); echo "Shadow version is $shadow_version" >/dev/ttyS0; [ $(printf "$shadow_version\n4.6-6\n" | sort | head -n 1) != "4.6-6" ] && /bin/sed -E -i 's/^root:([^:]+):.*$/root:\1:17532:0:99999:0:::/' /etc/shadow

runcmd:
{% for cmd in cloudinit_runcmd %}
- {{ cmd }}
{% endfor %}
- echo "Stop and disable iptables" >/dev/ttyS0
- [systemctl, stop, iptables]
- [systemctl, disable, iptables]
- [systemctl, disable, chronyd]
- [systemctl, disable, chrony-wait]
- os_version=$(grep VERSION= /etc/os-release | grep -E -o "[0-9]+\.[0-9]+"); [ $(printf "$os_version\n4.0\n" | sort | head -n 1 | cut -d '.' -f 1) -ge 4 ] && systemctl start sshd.socket
- os_major_ver=$(grep VERSION= /etc/os-release | grep -Eo "[0-9]+\.[0-9]+" | cut -d '.' -f 1); [ $os_major_ver -ge 4 ] && (echo "Starting sshd.socket ..." >/dev/ttyS0; systemctl start sshd.socket; systemctl status sshd.socket >/dev/ttyS0)

final_message: "{{ cloudinit_final_msg }}"
7 changes: 5 additions & 2 deletions linux/deploy_vm/templates/ubuntu-ova-user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ packages:
- net-tools
- sg3-utils
- ndctl

runcmd:
{% for cmd in cloudinit_runcmd %}
- {{ cmd }}
{% endfor %}
- echo 'Force apt-get to use IPv4 address' >/dev/ttyS0
- echo 'Acquire::ForceIPv4 "true";' >>/etc/apt/apt.conf.d/99force-ipv4
- sed -i 's/^#*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
- systemctl restart sshd

final_message: "{{ cloudinit_final_msg }}"

0 comments on commit f914e92

Please sign in to comment.