90 lines
3.7 KiB
YAML
90 lines
3.7 KiB
YAML
|
|
---
|
||
|
|
- name: Remove Uptime Kuma GCP Resources
|
||
|
|
hosts: all
|
||
|
|
|
||
|
|
vars:
|
||
|
|
# GCP Configuration
|
||
|
|
gcp_project: "your-gcp-project-id"
|
||
|
|
gcp_region: "us-central1"
|
||
|
|
service_name: "uptime-kuma"
|
||
|
|
ar_repo_name: "dockerhub"
|
||
|
|
data_bucket_name: "{{ gcp_project }}-uptime-kuma-data"
|
||
|
|
|
||
|
|
tasks:
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
# 1. Delete Cloud Run Service
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
- name: Delete Uptime Kuma Cloud Run service
|
||
|
|
ansible.builtin.shell:
|
||
|
|
executable: /bin/bash
|
||
|
|
cmd: |
|
||
|
|
if [ -f '/home/builder/google-cloud-sdk/path.bash.inc' ]; then . '/home/builder/google-cloud-sdk/path.bash.inc'; fi
|
||
|
|
set -e
|
||
|
|
if gcloud run services describe {{ service_name }} \
|
||
|
|
--region={{ gcp_region }} \
|
||
|
|
--project={{ gcp_project }} >/dev/null 2>&1; then
|
||
|
|
gcloud run services delete {{ service_name }} \
|
||
|
|
--region={{ gcp_region }} \
|
||
|
|
--project={{ gcp_project }} \
|
||
|
|
--quiet
|
||
|
|
echo SERVICE_DELETED
|
||
|
|
else
|
||
|
|
echo SERVICE_NOT_FOUND
|
||
|
|
fi
|
||
|
|
register: service_delete_output
|
||
|
|
changed_when: "'SERVICE_DELETED' in service_delete_output.stdout"
|
||
|
|
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
# 2. Delete Cloud Storage Data Bucket and Contents
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
- name: Delete Uptime Kuma Cloud Storage data bucket
|
||
|
|
ansible.builtin.shell:
|
||
|
|
executable: /bin/bash
|
||
|
|
cmd: |
|
||
|
|
if [ -f '/home/builder/google-cloud-sdk/path.bash.inc' ]; then . '/home/builder/google-cloud-sdk/path.bash.inc'; fi
|
||
|
|
set -e
|
||
|
|
if gcloud storage buckets describe gs://{{ data_bucket_name }} \
|
||
|
|
--project={{ gcp_project }} >/dev/null 2>&1; then
|
||
|
|
gcloud storage rm --recursive gs://{{ data_bucket_name }} \
|
||
|
|
--project={{ gcp_project }} \
|
||
|
|
--quiet
|
||
|
|
echo BUCKET_DELETED
|
||
|
|
else
|
||
|
|
echo BUCKET_NOT_FOUND
|
||
|
|
fi
|
||
|
|
register: bucket_delete_output
|
||
|
|
changed_when: "'BUCKET_DELETED' in bucket_delete_output.stdout"
|
||
|
|
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
# 3. Delete Artifact Registry Remote Repository
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
- name: Delete Artifact Registry Docker Hub remote repository
|
||
|
|
ansible.builtin.shell:
|
||
|
|
executable: /bin/bash
|
||
|
|
cmd: |
|
||
|
|
if [ -f '/home/builder/google-cloud-sdk/path.bash.inc' ]; then . '/home/builder/google-cloud-sdk/path.bash.inc'; fi
|
||
|
|
set -e
|
||
|
|
if gcloud artifacts repositories describe {{ ar_repo_name }} \
|
||
|
|
--location={{ gcp_region }} \
|
||
|
|
--project={{ gcp_project }} >/dev/null 2>&1; then
|
||
|
|
gcloud artifacts repositories delete {{ ar_repo_name }} \
|
||
|
|
--location={{ gcp_region }} \
|
||
|
|
--project={{ gcp_project }} \
|
||
|
|
--quiet
|
||
|
|
echo REPO_DELETED
|
||
|
|
else
|
||
|
|
echo REPO_NOT_FOUND
|
||
|
|
fi
|
||
|
|
register: repo_delete_output
|
||
|
|
changed_when: "'REPO_DELETED' in repo_delete_output.stdout"
|
||
|
|
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
# 4. Removal Summary
|
||
|
|
# -------------------------------------------------------------
|
||
|
|
- name: Show removal summary
|
||
|
|
ansible.builtin.debug:
|
||
|
|
msg:
|
||
|
|
- "Cloud Run Service ({{ service_name }}): {{ service_delete_output.stdout_lines | last }}"
|
||
|
|
- "Cloud Storage Bucket (gs://{{ data_bucket_name }}): {{ bucket_delete_output.stdout_lines | last }}"
|
||
|
|
- "Artifact Registry Repo ({{ ar_repo_name }}): {{ repo_delete_output.stdout_lines | last }}"
|