Skip to content

Commit

Permalink
Fix cloud-init user-data syntax error
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 f914e92 commit b7bc4cc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
10 changes: 5 additions & 5 deletions common/create_temp_file_dir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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"
16 changes: 11 additions & 5 deletions linux/deploy_vm/collect_vm_logs.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
# 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
when:
- 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:
Expand Down
12 changes: 9 additions & 3 deletions linux/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
19 changes: 9 additions & 10 deletions linux/deploy_vm/reconfigure_vm_with_cloudinit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions linux/deploy_vm/templates/amazon-ova-user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions linux/utils/create_seed_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
ansible.builtin.template:
src: "{{ user_data_template }}"
dest: "{{ user_data_path }}"
mode: "0644"
mode: "0666"
vars:
vm_password_hash: "{{ vm_password | password_hash('sha512') }}"

- name: "Create meta-data file for cloud-init local datasource"
ansible.builtin.file:
path: "{{ meta_data_path }}"
state: touch
mode: "0644"
mode: "0666"

- name: "Set hostname in cloud-init meta-data"
ansible.builtin.lineinfile:
Expand Down

0 comments on commit b7bc4cc

Please sign in to comment.