diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 5a97210445..fc8ebd3cc6 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -28,8 +28,7 @@ virtual_machines: rhel: project: rhel-cloud families: - - rhel-8 - - rhel-9 + "{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a X86_64 -p rhel-cloud') }}" container_engine: podman rhel-arm64: @@ -37,7 +36,7 @@ virtual_machines: arch: arm64 machine_type: t2a-standard-2 families: - - rhel-9-arm64 + "{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a ARM64 -p rhel-cloud') }}" container_engine: podman rhel-s390x: @@ -59,12 +58,8 @@ virtual_machines: rhel-sap: project: rhel-sap-cloud families: - - rhel-8-4-sap-ha - - rhel-8-6-sap-ha - # RHEL SAP 8.4 seems to have an older version of podman that - # fails with our integration tests, so we stick with docker - # for now. - container_engine: docker + "{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a X86_64 -p rhel-sap-cloud') }}" + container_engine: podman rhcos: project: rhcos-cloud @@ -140,16 +135,14 @@ virtual_machines: ubuntu-os: project: ubuntu-os-cloud families: - - ubuntu-2204-lts - - ubuntu-2404-lts-amd64 + "{{ lookup('ansible.builtin.pipe', \"scripts/fetch_gcp_families.sh -f '^ubuntu-\\d+-lts(-amd64)?$'\") }}" ubuntu-arm: project: ubuntu-os-cloud arch: arm64 machine_type: t2a-standard-2 families: - - ubuntu-2204-lts-arm64 - - ubuntu-2404-lts-arm64 + "{{ lookup('ansible.builtin.pipe', \"scripts/fetch_gcp_families.sh -f '^ubuntu-\\d+-lts-arm64$'\") }}" ubuntu-os-pro: project: ubuntu-os-pro-cloud diff --git a/ansible/scripts/fetch_gcp_families.sh b/ansible/scripts/fetch_gcp_families.sh new file mode 100755 index 0000000000..9848a24d5f --- /dev/null +++ b/ansible/scripts/fetch_gcp_families.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +set -euo pipefail + +function usage() { + echo "$0 [OPTIONS]" + echo "" + echo "[OPTIONS]" + echo " -a, --arch" + echo " Architecture wanted for the listed images" + echo " -p, --project" + echo " Project the image is hosted in" + echo " -f, --family" + echo " Regular expression for the image family to be listed" +} + +TEMP=$(getopt -o 'ha:p:f:' -l 'help,arch,project,family' -n "$0" -- "$@") + +# shellcheck disable=SC2181 +if [ $? -ne 0 ]; then + exit 1 +fi + +eval set -- "$TEMP" +unset TEMP + +arch="" +family="" +project="" +filter="" +using_regex=0 +using_aip=0 + +while true; do + case "${1:-}" in + '-h' | '--help') + usage + exit 0 + ;; + + '-a' | '--arch') + arch="architecture=$2" + using_aip=1 + shift 2 + ;; + + '-p' | '--project') + project="selfLink=/$2/" + using_aip=1 + shift 2 + ;; + + '-f' | '--family') + family="family ~ \"$2\"" + using_regex=1 + shift 2 + ;; + + '--') + shift + break + ;; + esac +done + +if ((using_regex != 0 && using_aip != 0)); then + echo >&2 "Mixing regex and AIP-160 is not supported in gcloud filters" + echo >&2 "see: https://cloud.google.com/compute/docs/reference/rest/v1/images/list" + exit 1 +elif ((using_regex != 0)); then + filter="$family" +elif ((using_aip != 0)); then + if [[ -n "$project" ]]; then + filter="$project" + if [[ -n "$arch" ]]; then + filter="$filter AND $arch" + fi + elif [[ -n "$arch" ]]; then + filter="$arch" + fi +fi + +gcloud compute images list \ + --format='json(family)' \ + --filter="$filter" \ + --limit 10 | jq -cM '[ .[].family ]'