139 lines
4.4 KiB
YAML
139 lines
4.4 KiB
YAML
# update_glance.yml
|
|
|
|
- name: Update Glance
|
|
hosts: pve2_vm
|
|
gather_facts: false
|
|
|
|
vars:
|
|
# Compose sync (controller -> target)
|
|
compose_local_dir: "{{ playbook_dir }}/docker-compose"
|
|
compose_remote_base: "/home/{{ ansible_user }}/.ansible-compose"
|
|
|
|
# Glance settings
|
|
glance_project: glance
|
|
glance_port: 9445
|
|
glance_compose_filename: "docker-compose-glance.yml"
|
|
glance_service: glance
|
|
|
|
# Own project directory, so .env does not collide with other stacks
|
|
glance_remote_dir: "{{ compose_remote_base }}/glance"
|
|
glance_config_remote_dir: "{{ compose_remote_base }}/glance/config"
|
|
|
|
# Config delivery (git -> controller -> target)
|
|
glance_config_local: "{{ playbook_dir }}/files/glance/glance.yml"
|
|
|
|
# Persistent env file on the VM (NOT in git)
|
|
glance_env_persistent: "{{ compose_remote_base }}/env/glance.env"
|
|
|
|
tasks:
|
|
- name: Ensure remote base directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ compose_remote_base }}"
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Ensure remote env directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ compose_remote_base }}/env"
|
|
state: directory
|
|
|
|
- name: Check for persistent Glance env file
|
|
ansible.builtin.stat:
|
|
path: "{{ glance_env_persistent }}"
|
|
register: glance_env_stat
|
|
|
|
- name: Abort when Glance env is missing
|
|
ansible.builtin.fail:
|
|
msg: >-
|
|
Missing persistent env file: {{ glance_env_persistent }}.
|
|
Create it on the VM with a GITHUB_TOKEN variable.
|
|
when: not glance_env_stat.stat.exists
|
|
|
|
- name: Ensure Glance project directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ glance_remote_dir }}"
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Ensure Glance config directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ glance_config_remote_dir }}"
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Upload Glance compose file to remote host
|
|
ansible.builtin.copy:
|
|
src: "{{ compose_local_dir }}/{{ glance_compose_filename }}"
|
|
dest: "{{ glance_remote_dir }}/{{ glance_compose_filename }}"
|
|
mode: "0644"
|
|
|
|
- name: Upload Glance configuration
|
|
ansible.builtin.copy:
|
|
src: "{{ glance_config_local }}"
|
|
dest: "{{ glance_config_remote_dir }}/glance.yml"
|
|
mode: "0644"
|
|
|
|
- name: Deploy Glance .env into compose directory
|
|
ansible.builtin.copy:
|
|
src: "{{ glance_env_persistent }}"
|
|
dest: "{{ glance_remote_dir }}/.env"
|
|
remote_src: true
|
|
mode: "0600"
|
|
|
|
- name: Pull latest Glance image
|
|
community.docker.docker_compose_v2:
|
|
project_name: "{{ glance_project }}"
|
|
project_src: "{{ glance_remote_dir }}"
|
|
files:
|
|
- "{{ glance_compose_filename }}"
|
|
pull: always
|
|
|
|
- name: Recreate Glance service
|
|
community.docker.docker_compose_v2:
|
|
project_name: "{{ glance_project }}"
|
|
project_src: "{{ glance_remote_dir }}"
|
|
files:
|
|
- "{{ glance_compose_filename }}"
|
|
services:
|
|
- "{{ glance_service }}"
|
|
state: present
|
|
recreate: always
|
|
|
|
- name: Verify Glance is serving
|
|
block:
|
|
- name: Wait for Glance port
|
|
ansible.builtin.wait_for:
|
|
host: 127.0.0.1
|
|
port: "{{ glance_port }}"
|
|
timeout: 60
|
|
|
|
- name: Check Glance HTTP endpoint (retry until ready)
|
|
ansible.builtin.uri:
|
|
url: "http://127.0.0.1:{{ glance_port }}/"
|
|
status_code: 200
|
|
register: glance_http
|
|
retries: 30
|
|
delay: 3
|
|
until: glance_http.status == 200
|
|
changed_when: false
|
|
|
|
rescue:
|
|
- name: Collect Glance container logs
|
|
ansible.builtin.command:
|
|
cmd: "docker logs --tail 50 glance"
|
|
register: glance_logs
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Show Glance container logs
|
|
ansible.builtin.debug:
|
|
msg: "{{ glance_logs.stderr_lines | default([]) + glance_logs.stdout_lines | default([]) }}"
|
|
|
|
- name: Fail after showing logs
|
|
ansible.builtin.fail:
|
|
msg: "Glance did not become healthy on port {{ glance_port }}. See container logs above."
|
|
|
|
- name: Clean up legacy compose file from shared base directory
|
|
ansible.builtin.file:
|
|
path: "{{ compose_remote_base }}/{{ glance_compose_filename }}"
|
|
state: absent |