tasks.yml DRY + Molecule verify fix
Test & Deploy Hugo Docker CMS / test-and-deploy (push) Successful in 4m8s
Test & Deploy Hugo Docker CMS / test-and-deploy (push) Successful in 4m8s
This commit is contained in:
+4
-136
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Playbook: Hugo-Docker-CMS aufzielen
|
# Playbook: Hugo-Docker-CMS ausrollen
|
||||||
# Aufruf: ansible-playbook -i "<host>," deploy.yml
|
# Aufruf: ansible-playbook -i "<host>," deploy.yml
|
||||||
# oder mit Variablen:
|
# oder mit Variablen:
|
||||||
# ansible-playbook -i "<host>," deploy.yml -e "target_hostname=ras-dan-01 target_port=5443"
|
# ansible-playbook -i "<host>," deploy.yml -e "target_hostname=ras-dan-01 target_port=5443"
|
||||||
@@ -15,139 +15,7 @@
|
|||||||
site_author: "JonnyBravo"
|
site_author: "JonnyBravo"
|
||||||
deploy_path: "{{ '~' | expanduser }}/.docker/hugo"
|
deploy_path: "{{ '~' | expanduser }}/.docker/hugo"
|
||||||
project_root: "{{ playbook_dir }}/.."
|
project_root: "{{ playbook_dir }}/.."
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
# ── Verzeichnisse anlegen ──
|
- name: Deploy-Tasks ausführen
|
||||||
- name: Zielverzeichnisse erstellen
|
ansible.builtin.include_tasks:
|
||||||
ansible.builtin.file:
|
file: tasks.yml
|
||||||
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"
|
|
||||||
changed_when: molecule_test is not defined
|
|
||||||
|
|
||||||
- name: Existierende crt-Dateien finden
|
|
||||||
ansible.builtin.stat:
|
|
||||||
path: "{{ deploy_path }}/crt/{{ item }}"
|
|
||||||
loop:
|
|
||||||
- "ca.crt"
|
|
||||||
- "{{ target_hostname }}.crt"
|
|
||||||
- "{{ target_hostname }}-chain.crt"
|
|
||||||
- "localhost.crt"
|
|
||||||
- "localhost-chain.crt"
|
|
||||||
register: crt_stat
|
|
||||||
|
|
||||||
- name: Zertifikate lesbar machen
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ deploy_path }}/crt/{{ item.item }}"
|
|
||||||
mode: "0644"
|
|
||||||
loop: "{{ crt_stat.results | selectattr('stat.exists') | list }}"
|
|
||||||
changed_when: molecule_test is not defined
|
|
||||||
loop_control:
|
|
||||||
label: "{{ item.item }}"
|
|
||||||
|
|
||||||
# ── 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"
|
|
||||||
@@ -1,3 +1,17 @@
|
|||||||
---
|
---
|
||||||
- name: Converge
|
- name: Converge
|
||||||
ansible.builtin.import_playbook: ../../deploy.yml
|
hosts: all
|
||||||
|
gather_facts: true
|
||||||
|
vars:
|
||||||
|
target_hostname: "test-node"
|
||||||
|
target_port: 5443
|
||||||
|
site_title: "Hugo Docker CMS"
|
||||||
|
site_description: "Testlauf"
|
||||||
|
site_author: "Molecule"
|
||||||
|
deploy_path: "/tmp/.docker/hugo"
|
||||||
|
project_root: "/home/jonnybravo/Projekte/hugo_docker"
|
||||||
|
molecule_test: true
|
||||||
|
tasks:
|
||||||
|
- name: Deploy-Tasks ausführen
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: ../../tasks.yml
|
||||||
@@ -12,14 +12,6 @@ platforms:
|
|||||||
|
|
||||||
provisioner:
|
provisioner:
|
||||||
name: ansible
|
name: ansible
|
||||||
inventory:
|
|
||||||
host_vars:
|
|
||||||
ubuntu:
|
|
||||||
target_hostname: "test-node"
|
|
||||||
target_port: 5443
|
|
||||||
deploy_path: "/tmp/.docker/hugo"
|
|
||||||
project_root: "/home/jonnybravo/Projekte/hugo_docker"
|
|
||||||
molecule_test: true
|
|
||||||
config_options:
|
config_options:
|
||||||
defaults:
|
defaults:
|
||||||
host_key_checking: false
|
host_key_checking: false
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
|
|
||||||
- name: Entrypoint muss ausführbar sein
|
- name: Entrypoint muss ausführbar sein
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: entrypoint_stat.stat.executable
|
that: entrypoint_stat.stat.mode == '0755'
|
||||||
fail_msg: "entrypoint.sh ist nicht ausführbar!"
|
fail_msg: "entrypoint.sh hat nicht mode 0755!"
|
||||||
success_msg: "entrypoint.sh ist ausführbar."
|
success_msg: "entrypoint.sh hat korrekt mode 0755."
|
||||||
|
|
||||||
- name: Prüfe Template-Inhalte
|
- name: Prüfe Template-Inhalte
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
---
|
||||||
|
# Shared tasks: Hugo Docker CMS bereitstellen
|
||||||
|
# Wird von deploy.yml (Playbook) und molecule converge.yml includiert.
|
||||||
|
|
||||||
|
# ── 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"
|
||||||
|
changed_when: molecule_test is not defined
|
||||||
|
|
||||||
|
- name: Existierende crt-Dateien finden
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ deploy_path }}/crt/{{ item }}"
|
||||||
|
loop:
|
||||||
|
- "ca.crt"
|
||||||
|
- "{{ target_hostname }}.crt"
|
||||||
|
- "{{ target_hostname }}-chain.crt"
|
||||||
|
- "localhost.crt"
|
||||||
|
- "localhost-chain.crt"
|
||||||
|
register: crt_stat
|
||||||
|
|
||||||
|
- name: Zertifikate lesbar machen
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ deploy_path }}/crt/{{ item.item }}"
|
||||||
|
mode: "0644"
|
||||||
|
loop: "{{ crt_stat.results | selectattr('stat.exists') | list }}"
|
||||||
|
changed_when: molecule_test is not defined
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.item }}"
|
||||||
|
|
||||||
|
# ── 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 {{ project_root }}/crt/ca.crt /etc/ca-certificates/trust-source/anchors/hugo-docker-ca.crt"
|
||||||
|
- " sudo update-ca-trust"
|
||||||
Reference in New Issue
Block a user