Files
Watari-Ansible/playbooks/setup-compose.yaml
2026-03-06 06:57:32 +00:00

52 lines
1.6 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
- name: Pull repo, copy compose and restart service if needed
hosts: localhost # run on the pull‑host itself
gather_facts: true
vars:
repo_url: "git@github.com:tolerryan/Watari-Ansible.git"
git_branch: "main" # or a tag / commit SHA
src_dir_in_repo: "playbooks"
local_clone_path: "/opt/Watari-Ansible"
apps_root: "/apps"
tasks:
- name: Pull the latest repo
ansible.builtin.git:
repo: "{{ repo_url }}"
dest: "{{ local_clone_path }}"
version: "{{ git_branch }}"
update: true # pull instead of clone on subsequent runs
register: git_result
- name: Set path to this host's compose file in the repo
set_fact:
compose_src: "{{ local_clone_path }}/{{ src_dir_in_repo }}/{{ inventory_hostname }}/docker-compose.yaml"
- name: Ensure destination directory exists
ansible.builtin.file:
path: "{{ apps_root }}/{{ inventory_hostname }}"
state: directory
mode: "0755"
- name: Copy compose file (notify if changed)
ansible.builtin.copy:
src: "{{ compose_src }}"
dest: "{{ apps_root }}/{{ inventory_hostname }}/docker-compose.yaml"
owner: root
group: root
mode: "0644"
notify: restart docker‑compose service
register: copy_result
# ------------------------------------------
# Handlers – only run if the copy task reported a change
# ------------------------------------------
handlers:
- name: restart docker‑compose service
ansible.builtin.systemd:
name: "{{ inventory_hostname }}.service"
state: restarted