personal_infra/ansible/services/personal-blog/deploy_personal_blog_playbook.yml
counterweight 532974634e
playbooks: stop re-runs overwriting live config
Three seeding tasks used copy without force: false, so every run replaced the
real file with the starter one:

- personal-blog: the placeholder index.html over the deployed site.
- lnbits: .env.example over .env - a new AUTH_SECRET_KEY, logging every
  user out, and it would have clobbered a restored .env.
- forgejo: a two-line app.ini stub over the real config, losing
  INTERNAL_TOKEN, the JWT secrets, the DB path and ROOT_URL.

All three now seed a fresh install only. Found while restoring each from
backup on 2026-10-17.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 22:10:23 +02:00

58 lines
1.8 KiB
YAML

- name: Deploy personal blog static site with Caddy file server
hosts: edge
become: yes
vars_files:
- ./personal_blog_vars.yml
vars:
personal_blog_subdomain: "{{ subdomains.personal_blog }}"
personal_blog_domain: "{{ personal_blog_subdomain }}.{{ root_domain }}"
tasks:
- name: Ensure user is in www-data group
user:
name: "{{ ansible_user }}"
groups: www-data
append: yes
- name: Create web root directory for personal blog
file:
path: "{{ personal_blog_web_root }}"
state: directory
owner: "{{ ansible_user }}"
group: www-data
mode: '2775'
- name: Fix ownership and permissions on web root directory
shell: |
chown -R {{ ansible_user }}:www-data {{ personal_blog_web_root }}
find {{ personal_blog_web_root }} -type d -exec chmod 2775 {} \;
find {{ personal_blog_web_root }} -type f -exec chmod 664 {} \;
- name: Create placeholder index.html
copy:
dest: "{{ personal_blog_web_root }}/index.html"
content: |
<!DOCTYPE html>
<html>
<head>
<title>Personal Blog</title>
</head>
<body>
<h1>Personal Blog</h1>
<p>Site is ready. Deploy your static files here.</p>
</body>
</html>
owner: "{{ ansible_user }}"
group: www-data
mode: '0664'
# Only on a fresh web root. Without this, every re-run (and site.yml)
# overwrote the real deployed index.html with the placeholder.
force: false
- name: Publish the blog through Caddy
ansible.builtin.include_role:
name: caddy_site
vars:
caddy_site_name: personal-blog
caddy_site_domain: "{{ personal_blog_domain }}"
caddy_site_root: "{{ personal_blog_web_root }}"