Created
July 29, 2024 14:00
-
-
Save mohag/aecfd06c4b85d3071285679ef79bef60 to your computer and use it in GitHub Desktop.
GCS bucket region detection from Ansible (from a GCP host)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Since we don't have a region for GCP, get the token from the metadata service | |
ansible.builtin.uri: | |
url: "http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token" | |
headers: | |
Metadata-Flavor: Google | |
Accept: "application/json" | |
return_content: yes | |
register: gcp_token | |
- name: Fetch the region for the bucket from the GCS API | |
ansible.builtin.uri: | |
url: "https://storage.googleapis.com/storage/v1/b/{{ backup_gcs_bucket }}?alt=json&fields=metageneration%2ClocationType%2CstorageClass%2Clocation&projection=full" | |
headers: | |
Authorization: "Bearer {{ gcp_token.json.access_token }}" | |
Accept: "application/json" | |
return_content: yes | |
register: gcs_bucket_info | |
- name: Get the region from the GCS bucket info | |
ansible.builtin.set_fact: | |
backup_s3_region: "{{ gcs_bucket_info.json.location }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment