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