From b7bc4cca51d9b975375e3a521e82adcde2655ca6 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Mon, 7 Aug 2023 16:29:59 +0800 Subject: [PATCH] Fix cloud-init user-data syntax error Signed-off-by: Qi Zhang --- common/create_temp_file_dir.yml | 10 +++++----- linux/deploy_vm/collect_vm_logs.yml | 16 +++++++++++----- linux/deploy_vm/deploy_vm_from_ova.yml | 12 +++++++++--- .../reconfigure_vm_with_cloudinit.yml | 19 +++++++++---------- .../templates/amazon-ova-user-data.j2 | 4 ++-- linux/utils/create_seed_iso.yml | 4 ++-- 6 files changed, 38 insertions(+), 27 deletions(-) diff --git a/common/create_temp_file_dir.yml b/common/create_temp_file_dir.yml index 95b28a6a6..7a698716a 100644 --- a/common/create_temp_file_dir.yml +++ b/common/create_temp_file_dir.yml @@ -3,10 +3,10 @@ --- # Create a temporary file or directory # Parameters: +# tmp_state: file or directory. By default, temporary file will be created. # tmp_dir: (Optional) the location where temporary file or diretotry will be created. -# tmp_state: file or directory. By default, temporary file will be created -# tmp_prefix: the prefix of temporary file or directory -# tmp_suffix: the suffix of temporar file or directory +# tmp_prefix: (Optional) the prefix of temporary file or directory. +# tmp_suffix: (Optional) the suffix of temporar file or directory. # Return: # tmp_path: the path to temporary file or directory # @@ -31,11 +31,11 @@ - name: "Modify the mode of temporary file" ansible.builtin.file: path: "{{ tmp_path }}" - mode: "0644" + mode: "0666" when: tmp_state == "file" - name: "Modify the mode of temporary directory" ansible.builtin.file: path: "{{ tmp_path }}" - mode: "0755" + mode: "0777" when: tmp_state == "directory" diff --git a/linux/deploy_vm/collect_vm_logs.yml b/linux/deploy_vm/collect_vm_logs.yml index 74fd9865a..85be13fa2 100644 --- a/linux/deploy_vm/collect_vm_logs.yml +++ b/linux/deploy_vm/collect_vm_logs.yml @@ -1,21 +1,26 @@ # Copyright 2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Collect cloud-init logs for deploying Ubuntu live-server, -# cloud image or Photon OVA. +# Collect VM guest info and cloud-init logs for deploying Ubuntu live-server, +# cloud image, VMware Photon OS OVA or Amazon Linux OVA. # -- name: "Collect VM logs" +- name: "Collect VM deployement logs" block: - name: "Get VM's power state" include_tasks: ../../common/vm_get_power_state.yml - - name: "Collect cloud-init logs" + - name: "Collect VM's guest info and cloud-init logs" block: + - name: "Get VMware Tools status" + include_tasks: ../../common/vm_get_vmtools_status.yml + + # VM's guest info will be collected by log plugin - name: "Get VM's guest info" include_tasks: ../../common/vm_get_guest_info.yml when: - unattend_install_conf is defined - unattend_install_conf | lower is not match('.*bclinux-for-euler.*') + - vmtools_is_running - name: "Collect cloud-init logs" include_tasks: ../utils/collect_cloudinit_logs.yml @@ -23,7 +28,8 @@ - guestinfo_guest_id is defined - ((guestinfo_guest_id is match('ubuntu.*') and unattend_install_conf is defined and - (unattend_install_conf is match('Ubuntu/Server/') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity'))) or + (unattend_install_conf is match('Ubuntu/Server/') or + unattend_install_conf is match('Ubuntu/Desktop/Subiquity'))) or (ova_guest_os_type is defined and ova_guest_os_type in ['photon', 'ubuntu', 'amazon'])) when: diff --git a/linux/deploy_vm/deploy_vm_from_ova.yml b/linux/deploy_vm/deploy_vm_from_ova.yml index f1845b537..35bf3a9b7 100644 --- a/linux/deploy_vm/deploy_vm_from_ova.yml +++ b/linux/deploy_vm/deploy_vm_from_ova.yml @@ -107,6 +107,9 @@ reconfiguration. Please add it if needed or the following tests might fail. when: ova_guest_os_type == 'unknown' + - name: "Collect VM deployment logs" + include_tasks: collect_vm_logs.yml + - name: "Shutdown guest OS" include_tasks: ../utils/shutdown.yml @@ -138,6 +141,12 @@ vars: vm_power_state_set: 'powered-on' rescue: + # If test case failed before collecting VM cloud-init logs, + # the logs need to be collected at rescue + - name: "Collect VM deployment logs" + include_tasks: collect_vm_logs.yml + when: cloudinit_logs_local_path is undefined + - name: "Collect serial port log at test failure" include_tasks: collect_serial_port_log.yml @@ -161,6 +170,3 @@ vars: local_path: "{{ nfs_mount_dir }}" del_local_file_ignore_errors: true - - - name: "Collect VM deployment logs" - include_tasks: collect_vm_logs.yml diff --git a/linux/deploy_vm/reconfigure_vm_with_cloudinit.yml b/linux/deploy_vm/reconfigure_vm_with_cloudinit.yml index bd15cfd95..354e08211 100644 --- a/linux/deploy_vm/reconfigure_vm_with_cloudinit.yml +++ b/linux/deploy_vm/reconfigure_vm_with_cloudinit.yml @@ -3,16 +3,16 @@ --- - name: "Set fact of cloud-init final message" ansible.builtin.set_fact: - cloudinit_final_msg: "The system is finally up, after $UPTIME seconds" + cloudinit_final_msg: "OVA deployment with cloud-init config is completed" 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" + - 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: @@ -32,7 +32,6 @@ vars: user_data_template: "{{ ova_guest_os_type }}-ova-user-data.j2" local_hostname: "{{ ova_guest_os_type }}-ova-{{ hostname_timestamp }}" - mode: '0644' - name: "Upload cloud-init seed ISO to ESXi server datastore" include_tasks: ../../common/esxi_upload_datastore_file.yml diff --git a/linux/deploy_vm/templates/amazon-ova-user-data.j2 b/linux/deploy_vm/templates/amazon-ova-user-data.j2 index b39b91f0a..339f928f7 100644 --- a/linux/deploy_vm/templates/amazon-ova-user-data.j2 +++ b/linux/deploy_vm/templates/amazon-ova-user-data.j2 @@ -22,8 +22,8 @@ runcmd: {% 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 + - 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: | diff --git a/linux/utils/create_seed_iso.yml b/linux/utils/create_seed_iso.yml index 2fb88d1eb..bb265c85a 100644 --- a/linux/utils/create_seed_iso.yml +++ b/linux/utils/create_seed_iso.yml @@ -30,7 +30,7 @@ ansible.builtin.template: src: "{{ user_data_template }}" dest: "{{ user_data_path }}" - mode: "0644" + mode: "0666" vars: vm_password_hash: "{{ vm_password | password_hash('sha512') }}" @@ -38,7 +38,7 @@ ansible.builtin.file: path: "{{ meta_data_path }}" state: touch - mode: "0644" + mode: "0666" - name: "Set hostname in cloud-init meta-data" ansible.builtin.lineinfile: