added jnss-web
This commit is contained in:
133
playbooks/deploy-jnss-web.yml
Normal file
133
playbooks/deploy-jnss-web.yml
Normal file
@@ -0,0 +1,133 @@
|
||||
---
|
||||
# ================================================================
|
||||
# jnss-web Static Site Deployment Playbook
|
||||
# ================================================================
|
||||
# Deploys the jnss-web SvelteKit static site to jnss.me
|
||||
#
|
||||
# Usage:
|
||||
# ansible-playbook -i inventory/hosts.yml playbooks/deploy-jnss-web.yml
|
||||
#
|
||||
# This playbook:
|
||||
# - Clones the jnss-web repository (deploy branch) to a temp directory
|
||||
# - Syncs build artifacts to /var/www/jnss-web
|
||||
# - Deploys Caddy configuration for jnss.me with www redirect
|
||||
# - Reloads Caddy to serve the new site
|
||||
# ================================================================
|
||||
|
||||
- name: Deploy jnss-web static site
|
||||
hosts: homelab
|
||||
become: true
|
||||
|
||||
vars:
|
||||
# Git repository configuration
|
||||
jnss_web_repo_url: "https://git.jnss.me/joakim/jnss-web.git"
|
||||
jnss_web_branch: "deploy"
|
||||
|
||||
# Server paths
|
||||
jnss_web_root: "/var/www/jnss-web"
|
||||
|
||||
# Domain configuration
|
||||
jnss_web_domain: "jnss.me"
|
||||
|
||||
# Caddy configuration
|
||||
caddy_user: "caddy"
|
||||
caddy_sites_enabled_dir: "/etc/caddy/sites-enabled"
|
||||
|
||||
tasks:
|
||||
# ============================================================
|
||||
# Git Repository Management
|
||||
# ============================================================
|
||||
|
||||
- name: Create temporary directory for git clone
|
||||
tempfile:
|
||||
state: directory
|
||||
suffix: -jnss-web
|
||||
register: temp_clone_dir
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Clone jnss-web repository to temp directory
|
||||
git:
|
||||
repo: "{{ jnss_web_repo_url }}"
|
||||
dest: "{{ temp_clone_dir.path }}"
|
||||
version: "{{ jnss_web_branch }}"
|
||||
depth: 1
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Verify build directory exists in repository
|
||||
stat:
|
||||
path: "{{ temp_clone_dir.path }}/index.html"
|
||||
register: build_dir
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Fail if index.html not found
|
||||
fail:
|
||||
msg: "Build index.html not found in repository root. Ensure the deploy branch contains the built artifacts."
|
||||
when: not build_dir.stat.exists
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
# ============================================================
|
||||
# Web Root Deployment
|
||||
# ============================================================
|
||||
|
||||
- name: Remove old web root
|
||||
file:
|
||||
path: "{{ jnss_web_root }}"
|
||||
state: absent
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Create fresh web root directory
|
||||
file:
|
||||
path: "{{ jnss_web_root }}"
|
||||
state: directory
|
||||
owner: "{{ caddy_user }}"
|
||||
group: "{{ caddy_user }}"
|
||||
mode: '0755'
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Copy build files to web root
|
||||
copy:
|
||||
src: "{{ temp_clone_dir.path }}/"
|
||||
dest: "{{ jnss_web_root }}/"
|
||||
owner: "{{ caddy_user }}"
|
||||
group: "{{ caddy_user }}"
|
||||
mode: '0755'
|
||||
remote_src: true
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
- name: Clean up temporary clone directory
|
||||
file:
|
||||
path: "{{ temp_clone_dir.path }}"
|
||||
state: absent
|
||||
tags: [jnss-web, deploy]
|
||||
|
||||
# ============================================================
|
||||
# Caddy Configuration
|
||||
# ============================================================
|
||||
|
||||
- name: Deploy Caddy configuration for jnss-web
|
||||
template:
|
||||
src: templates/jnss-web.caddy.j2
|
||||
dest: "{{ caddy_sites_enabled_dir }}/jnss-web.caddy"
|
||||
owner: root
|
||||
group: "{{ caddy_user }}"
|
||||
mode: '0644'
|
||||
notify: reload caddy
|
||||
tags: [jnss-web, caddy]
|
||||
|
||||
- name: Validate Caddy configuration
|
||||
command: caddy validate --config /etc/caddy/Caddyfile
|
||||
register: caddy_validate
|
||||
changed_when: false
|
||||
tags: [jnss-web, caddy]
|
||||
|
||||
- name: Display Caddy validation result
|
||||
debug:
|
||||
msg: "Caddy configuration is valid"
|
||||
when: caddy_validate.rc == 0
|
||||
tags: [jnss-web, caddy]
|
||||
|
||||
handlers:
|
||||
- name: reload caddy
|
||||
systemd:
|
||||
name: caddy
|
||||
state: reloaded
|
||||
Reference in New Issue
Block a user