# Copyright 2022 The Kubernetes Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- name: Install cloud-init packages
  yum:
    name: "{{ packages }}"
    state: present
  vars:
    packages:
    - cloud-init
    - cloud-utils-growpart
    - python2-pip

# 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
    state: forcereinstall
  when: ansible_distribution_major_version == '7'

# Directly installing Guestinfo datasource is needed so long as
# cloud-init is < 21.3
- name: Download cloud-init datasource for VMware Guestinfo
  get_url:
    url:  '{{ guestinfo_datasource_script }}'
    dest: /tmp/cloud-init-vmware.sh
    mode: 0700

- name: Execute cloud-init-vmware.sh
  shell: bash -o errexit -o pipefail /tmp/cloud-init-vmware.sh
  environment:
    REPO_SLUG: '{{ guestinfo_datasource_slug }}'
    GIT_REF:   '{{ guestinfo_datasource_ref }}'

- name: Remove cloud-init-vmware.sh
  file:
    path:  /tmp/cloud-init-vmware.sh
    state: absent