recordding firstrun.sh and setup-compse.yaml

This commit is contained in:
Ryan Toler
2026-03-06 06:57:32 +00:00
parent 44b8d22e2e
commit 82ddaf2fa8
3 changed files with 59 additions and 119 deletions

View File

@@ -0,0 +1,51 @@
---
- 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