144 lines
4.7 KiB
YAML
144 lines
4.7 KiB
YAML
---
|
|
# Playbook: Hugo-Docker-CMS aufzielen
|
|
# Aufruf: ansible-playbook -i "<host>," deploy.yml
|
|
# oder mit Variablen:
|
|
# ansible-playbook -i "<host>," deploy.yml -e "target_hostname=ras-dan-01 target_port=5443"
|
|
|
|
- name: Hugo Docker CMS bereitstellen
|
|
hosts: all
|
|
gather_facts: true
|
|
vars:
|
|
target_hostname: "{{ inventory_hostname }}"
|
|
target_port: 5443
|
|
site_title: "Hugo Docker CMS"
|
|
site_description: "Markdown-Dateien einfach in content/ ablegen."
|
|
site_author: "JonnyBravo"
|
|
deploy_path: "{{ '~' | expanduser }}/.docker/hugo"
|
|
project_root: "{{ playbook_dir }}/.."
|
|
|
|
tasks:
|
|
# ── Verzeichnisse anlegen ──
|
|
- name: Zielverzeichnisse erstellen
|
|
ansible.builtin.file:
|
|
path: "{{ deploy_path }}/{{ item }}"
|
|
state: directory
|
|
mode: "0755"
|
|
loop:
|
|
- content
|
|
- crt
|
|
- site/assets/css
|
|
- site/layouts/_default
|
|
- site/layouts/partials
|
|
- site/static
|
|
|
|
# ── docker-compose.yml kopieren ──
|
|
- name: docker-compose.yml kopieren
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/docker-compose.yml"
|
|
dest: "{{ deploy_path }}/docker-compose.yml"
|
|
mode: "0644"
|
|
|
|
# ── Statische Site-Dateien kopieren ──
|
|
- name: Hugo-Layouts kopieren
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/site/layouts/"
|
|
dest: "{{ deploy_path }}/site/layouts/"
|
|
mode: "0644"
|
|
|
|
- name: main.css kopieren
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/site/assets/css/main.css"
|
|
dest: "{{ deploy_path }}/site/assets/css/main.css"
|
|
mode: "0644"
|
|
|
|
- name: Entrypoint kopieren und ausführbar machen
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/site/entrypoint.sh"
|
|
dest: "{{ deploy_path }}/site/entrypoint.sh"
|
|
mode: "0755"
|
|
|
|
# ── Zertifikate kopieren ──
|
|
- name: Zertifikate für Ziel-Host kopieren
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/crt/"
|
|
dest: "{{ deploy_path }}/crt/"
|
|
mode: "0600"
|
|
|
|
- name: Zertifikate lesbar machen (crt-Dateien)
|
|
ansible.builtin.file:
|
|
path: "{{ deploy_path }}/crt/{{ item }}"
|
|
mode: "0644"
|
|
loop:
|
|
- "ca.crt"
|
|
- "{{ target_hostname }}.crt"
|
|
- "{{ target_hostname }}-chain.crt"
|
|
- "localhost.crt"
|
|
- "localhost-chain.crt"
|
|
ignore_errors: true
|
|
|
|
# ── Content (optional, nur wenn lokal vorhanden) ──
|
|
- name: Beispiel-Content kopieren (falls vorhanden)
|
|
ansible.builtin.copy:
|
|
src: "{{ project_root }}/content/"
|
|
dest: "{{ deploy_path }}/content/"
|
|
mode: "0644"
|
|
ignore_errors: true
|
|
|
|
# ── Templates rendern ──
|
|
- name: Caddyfile aus Template generieren
|
|
ansible.builtin.template:
|
|
src: "templates/Caddyfile.j2"
|
|
dest: "{{ deploy_path }}/Caddyfile"
|
|
mode: "0644"
|
|
|
|
- name: hugo.toml aus Template generieren
|
|
ansible.builtin.template:
|
|
src: "templates/hugo.toml.j2"
|
|
dest: "{{ deploy_path }}/site/hugo.toml"
|
|
mode: "0644"
|
|
|
|
# ── Docker Compose starten ──
|
|
- name: Docker Compose Pull (neueste Images)
|
|
ansible.builtin.command:
|
|
cmd: docker compose pull
|
|
chdir: "{{ deploy_path }}"
|
|
register: pull_result
|
|
changed_when: "'Pulled' in pull_result.stdout or 'newer' in pull_result.stdout"
|
|
when: molecule_test is not defined
|
|
|
|
- name: Docker Compose starten
|
|
ansible.builtin.command:
|
|
cmd: docker compose up -d
|
|
chdir: "{{ deploy_path }}"
|
|
register: compose_result
|
|
changed_when: "'Starting' in compose_result.stdout or 'Creating' in compose_result.stdout"
|
|
when: molecule_test is not defined
|
|
|
|
- name: Warten bis Caddy lauscht
|
|
ansible.builtin.wait_for:
|
|
port: "{{ target_port }}"
|
|
host: "127.0.0.1"
|
|
timeout: 30
|
|
when: molecule_test is not defined
|
|
|
|
- name: HTTPS-Smoke-Test
|
|
ansible.builtin.uri:
|
|
url: "https://localhost:{{ target_port }}/"
|
|
validate_certs: false
|
|
return_content: false
|
|
register: smoketest
|
|
failed_when: smoketest.status != 200
|
|
when: molecule_test is not defined
|
|
|
|
- name: Erfolgsmeldung
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "✅ Hugo Docker CMS läuft!"
|
|
- " https://{{ target_hostname }}:{{ target_port }}/"
|
|
- " https://localhost:{{ target_port }}/"
|
|
- " Pfad: {{ deploy_path }}"
|
|
- " .md-Dateien: {{ deploy_path }}/content/"
|
|
- ""
|
|
- "🔒 CA-Zertifikat muss noch vertraut werden (auf deinem Client):"
|
|
- " sudo cp {{ playbook_dir }}/../crt/ca.crt /etc/ca-certificates/trust-source/anchors/hugo-docker-ca.crt"
|
|
- " sudo update-ca-trust" |