From 574db76afb575872b7fcae7158b01a46e41fa88e Mon Sep 17 00:00:00 2001 From: Shalin Patel Date: Wed, 21 Aug 2024 11:24:01 -0700 Subject: [PATCH] fix: remove cloud-init dropin for custom vmware guest datasource --- ansible/roles/providers/tasks/main.yml | 5 ++ .../roles/providers/tasks/vmware-redhat.yaml | 52 +++++++++++++++++++ ansible/roles/providers/tasks/vmware.yml | 28 ---------- 3 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 ansible/roles/providers/tasks/vmware-redhat.yaml diff --git a/ansible/roles/providers/tasks/main.yml b/ansible/roles/providers/tasks/main.yml index 8be5634c3..16617966e 100644 --- a/ansible/roles/providers/tasks/main.yml +++ b/ansible/roles/providers/tasks/main.yml @@ -22,6 +22,11 @@ when: packer_builder_type is search('vmware') or packer_builder_type is search('vsphere') +- include_tasks: vmware-redhat.yaml + when: + - packer_builder_type is search('vmware') or packer_builder_type is search('vsphere') + - ansible_os_family == "RedHat" + - include_tasks: googlecompute.yml when: packer_builder_type.startswith('googlecompute') diff --git a/ansible/roles/providers/tasks/vmware-redhat.yaml b/ansible/roles/providers/tasks/vmware-redhat.yaml new file mode 100644 index 000000000..428d43abf --- /dev/null +++ b/ansible/roles/providers/tasks/vmware-redhat.yaml @@ -0,0 +1,52 @@ +- name: Get package facts + ansible.builtin.package_facts: + manager: "auto" + +- name: Set cloud-init version + ansible.builtin.set_fact: + cloud_init_version: "{{ ansible_facts.packages['cloud-init'][0].version }}" + +# this program used by ds-identify to determine whether or not the +# VMwareGuestInfo datasource is useable. +- name: Directly install GuestInfo + when: cloud_init_version is version('21.3', '<') + block: + + - name: Copy vmware guestinfo datasource + copy: + src: "{{ item }}" + dest: /tmp/ + owner: root + group: root + mode: 0755 + with_items: + - cloud-init-vmware.sh + - DataSourceVMwareGuestInfo.py + + - name: Create ds-check program to verify VMwareGuestInfo datasource + copy: + src: files/dscheck_VMwareGuestInfo.sh + dest: /usr/bin/dscheck_VMwareGuestInfo + owner: root + group: root + mode: 0755 + + - name: Execute cloud-init-vmware.sh + shell: bash -o errexit -o pipefail /tmp/cloud-init-vmware.sh + environment: + VMWARE_DS_PATH: '/tmp/DataSourceVMwareGuestInfo.py' + + - name: Remove cloud-init-vmware.sh + file: + path: /tmp/cloud-init-vmware.sh + state: absent + + # sets the datasource_list to VMwareGuestInfo for all OS + # ensure that VMwareGuestInfo overrides existing datasource drop-ins if it exists. + - name: Copy cloud-init config file for vmware + copy: + src: files/etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg + dest: /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg + owner: root + group: root + mode: 0644 diff --git a/ansible/roles/providers/tasks/vmware.yml b/ansible/roles/providers/tasks/vmware.yml index fe325302d..d3ba315d3 100644 --- a/ansible/roles/providers/tasks/vmware.yml +++ b/ansible/roles/providers/tasks/vmware.yml @@ -58,34 +58,6 @@ packages: "cloud-init cloud-utils python3-netifaces" when: ansible_os_family == "VMware Photon OS" -# pip on CentOS needs to be upgraded, but since it's still -# Python 2.7, need < 21.0 -- name: Upgrade pip - pip: - name: pip<21.0 - extra_args: "{{ '--no-index --find-links=' + pip_packages_remote_filesystem_repo_path if offline_mode_enabled }}" - state: forcereinstall - when: ansible_os_family == "RedHat" and ansible_distribution_major_version == '7' - -- name: Copy vmware guestinfo datasource - copy: - src: "{{ item }}" - dest: /tmp/ - owner: root - group: root - mode: 0755 - with_items: - - cloud-init-vmware.sh - - DataSourceVMwareGuestInfo.py - -- name: Copy cloud-init config file for vmware - copy: - src: files/etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg - dest: /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg - owner: root - group: root - mode: 0644 - - name: Remove subiquity-disable-cloudinit-networking.cfg file: path: /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg