make sure to use bash shell
Build and Publish Docker Image / Build and Push Docker Image (push) Successful in 2m18s Details

This commit is contained in:
Isaac Johnson 2026-10-06 09:05:43 -05:00
parent 75b4f62463
commit 4fc932ebae
1 changed files with 62 additions and 45 deletions

View File

@ -23,11 +23,13 @@
# 1. Local Prerequisites
# -------------------------------------------------------------
- name: Ensure uptime-kuma-api Python library is installed locally
ansible.builtin.shell: |
apt update
apt install python3-pip -y
python3 -m pip install --user uptime-kuma-api --break-system-packages
python3 -m pip install uptime-kuma-api --break-system-packages
ansible.builtin.shell:
executable: /bin/bash
cmd: |
apt update
apt install python3-pip -y
python3 -m pip install --user uptime-kuma-api --break-system-packages
python3 -m pip install uptime-kuma-api --break-system-packages
register: pip_install
changed_when: "'Successfully installed' in pip_install.stdout"
@ -35,77 +37,91 @@
# 2. Allocate Static Public IP (Idempotent)
# -------------------------------------------------------------
- name: Check if static IP exists
ansible.builtin.command: >
gcloud compute addresses describe {{ static_ip_name }}
--region={{ gcp_region }}
--project={{ gcp_project }}
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute addresses describe {{ static_ip_name }}
--region={{ gcp_region }}
--project={{ gcp_project }}
register: ip_check
failed_when: false
changed_when: false
- name: Allocate static external IP in GCP
ansible.builtin.command: >
gcloud compute addresses create {{ static_ip_name }}
--region={{ gcp_region }}
--project={{ gcp_project }}
--description="Static IP for Uptime Kuma"
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute addresses create {{ static_ip_name }}
--region={{ gcp_region }}
--project={{ gcp_project }}
--description="Static IP for Uptime Kuma"
when: ip_check.rc != 0
# -------------------------------------------------------------
# 3. Create Firewall Rule (Port 3001)
# -------------------------------------------------------------
- name: Check if firewall rule exists
ansible.builtin.command: >
gcloud compute firewall-rules describe {{ firewall_rule_name }}
--project={{ gcp_project }}
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute firewall-rules describe {{ firewall_rule_name }}
--project={{ gcp_project }}
register: fw_check
failed_when: false
changed_when: false
- name: Allow TCP traffic to port 3001
ansible.builtin.command: >
gcloud compute firewall-rules create {{ firewall_rule_name }}
--project={{ gcp_project }}
--allow=tcp:3001
--target-tags=uptime-kuma
--source-ranges=0.0.0.0/0
--description="Allow traffic to Uptime Kuma UI & API"
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute firewall-rules create {{ firewall_rule_name }}
--project={{ gcp_project }}
--allow=tcp:3001
--target-tags=uptime-kuma
--source-ranges=0.0.0.0/0
--description="Allow traffic to Uptime Kuma UI & API"
when: fw_check.rc != 0
# -------------------------------------------------------------
# 4. Provision VM with Container-Optimized OS
# -------------------------------------------------------------
- name: Check if instance already exists
ansible.builtin.command: >
gcloud compute instances describe {{ instance_name }}
--zone={{ gcp_zone }}
--project={{ gcp_project }}
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute instances describe {{ instance_name }}
--zone={{ gcp_zone }}
--project={{ gcp_project }}
register: instance_check
failed_when: false
changed_when: false
- name: Launch Compute Engine VM with Uptime Kuma container
ansible.builtin.command: >
gcloud compute instances create-with-container {{ instance_name }}
--project={{ gcp_project }}
--zone={{ gcp_zone }}
--machine-type={{ machine_type }}
--tags=uptime-kuma
--address={{ static_ip_name }}
--boot-disk-size=20GB
--container-image=louislam/uptime-kuma:1
--container-mount-host-path=host-path=/var/uptime-kuma,mount-path=/app/data,mode=rw
ansible.builtin.shell:
executable: /bin/bash
cmd: |
gcloud compute instances create-with-container {{ instance_name }}
--project={{ gcp_project }}
--zone={{ gcp_zone }}
--machine-type={{ machine_type }}
--tags=uptime-kuma
--address={{ static_ip_name }}
--boot-disk-size=20GB
--container-image=louislam/uptime-kuma:1
--container-mount-host-path=host-path=/var/uptime-kuma,mount-path=/app/data,mode=rw
when: instance_check.rc != 0
# -------------------------------------------------------------
# 5. Fetch Public IP and Wait for Service Readiness
# -------------------------------------------------------------
- name: Fetch instance public IP address
ansible.builtin.command: >
gcloud compute instances describe {{ instance_name }}
--zone={{ gcp_zone }}
--project={{ gcp_project }}
--format="value(networkInterfaces[0].accessConfigs[0].natIP)"
ansible.builtin.shell:
cmd: |
gcloud compute instances describe {{ instance_name }}
--zone={{ gcp_zone }}
--project={{ gcp_project }}
--format="value(networkInterfaces[0].accessConfigs[0].natIP)"
executable: /bin/bash
register: vm_ip
changed_when: false
@ -126,8 +142,8 @@
# 6. Non-Interactive Configuration via API
# -------------------------------------------------------------
- name: Perform headless setup and add monitor
ansible.builtin.command:
cmd: >
ansible.builtin.shell:
cmd: |
python3 -c "
import sys
from uptime_kuma_api import UptimeKumaApi, MonitorType
@ -158,6 +174,7 @@
api.disconnect()
"
executable: /bin/bash
register: setup_output
changed_when: "'MONITOR_ADDED' in setup_output.stdout"