refined deplyoment strategy

This commit is contained in:
Ubuntu
2026-01-09 15:21:30 +00:00
parent d459ce504d
commit 8b8a122a5b
5 changed files with 30 additions and 17 deletions

View File

@@ -78,8 +78,8 @@ Jetzt nutzen wir Ansible im **Push-Modus**, um Vault auf dem Zielserver zu insta
ansible-galaxy install -r requirements.yml ansible-galaxy install -r requirements.yml
``` ```
2. **Vault Deployen**: 2. **Vault Deployen (Initial)**:
Da Vault noch nicht läuft, wird Ansible Warnungen bei Secrets werfen (Permission Denied), aber das Deployment durchführen und den Container starten. Da Vault noch nicht läuft, wird Ansible Warnungen bei Secrets werfen (Permission Denied/Connection Error), aber das Deployment durchführen und den Container starten.
```bash ```bash
# Deploye auf alle Hosts im Inventory # Deploye auf alle Hosts im Inventory
@@ -109,6 +109,19 @@ Jetzt nutzen wir Ansible im **Push-Modus**, um Vault auf dem Zielserver zu insta
* Es fragt, ob `bootstrap.tfvars` gelöscht werden soll (Ja). * Es fragt, ob `bootstrap.tfvars` gelöscht werden soll (Ja).
* Es fragt, ob das **Root-Token** aus der Datei auf dem Server gelöscht werden soll (Ja, empfohlen für Security). * Es fragt, ob das **Root-Token** aus der Datei auf dem Server gelöscht werden soll (Ja, empfohlen für Security).
5. **Deployment abschließen (Apps & Secrets)**:
Jetzt, wo Vault gefüllt ist und wir ein Token haben, lassen wir Ansible die eigentlichen Apps (z.B. Traefik) erneut deployen diesmal mit korrekten Secrets.
```bash
cd infrastructure/ansible
export VAULT_TOKEN='<Dein-Root-Token>'
# Wichtig: Token via Variable übergeben!
ansible-playbook -i inventory.ini deploy.yml -e "vault_token=$VAULT_TOKEN"
```
✅ **Ergebnis:** Alle Apps laufen und haben ihre korrekten `.env` Files.
--- ---
## Phase 3: Production Mode & GitOps ## Phase 3: Production Mode & GitOps

View File

@@ -27,17 +27,9 @@
# 3. Secrets aus Vault (Lokal lookup, Remote copy) # 3. Secrets aus Vault (Lokal lookup, Remote copy)
# Nur ausführen, wenn has_secrets: true # Nur ausführen, wenn has_secrets: true
- name: "Debug Vault Info"
debug:
msg:
- "Token vorhanden: {{ (vault_token | default(lookup('env', 'VAULT_TOKEN'))) | length > 0 }}"
- "Adresse: {{ lookup('env', 'VAULT_ADDR') }}"
delegate_to: localhost
when: app_item.has_secrets | default(false)
- name: "Lade Secrets aus Vault (Lokal lookup)" - name: "Lade Secrets aus Vault (Lokal lookup)"
set_fact: set_fact:
app_secrets: "{{ lookup('community.hashi_vault.vault_kv2_get', 'apps/' + app_item.name, engine_mount_point='secret', url=lookup('env', 'VAULT_ADDR') | default('https://10.100.30.11:8200'), token=(vault_token | default(lookup('env', 'VAULT_TOKEN'))), validate_certs=false) | default({}) }}" app_secrets: "{{ lookup('community.hashi_vault.vault_kv2_get', 'apps/' + app_item.name, engine_mount_point='secret', url=lookup('env', 'VAULT_ADDR') | default('https://10.100.30.11:8200'), token=(vault_token | default(lookup('env', 'VAULT_TOKEN'))), validate_certs=true) | default({}) }}"
delegate_to: localhost delegate_to: localhost
when: app_item.has_secrets | default(false) when: app_item.has_secrets | default(false)
ignore_errors: true # Trotzdem ignorieren, falls Vault down ist oder Secret fehlt ignore_errors: true # Trotzdem ignorieren, falls Vault down ist oder Secret fehlt

View File

@@ -50,11 +50,11 @@
recurse: false recurse: false
register: installed_dirs register: installed_dirs
- name: "Filtere nicht-App Verzeichnisse (z.B. vault)" - name: "Filtere nicht-App Verzeichnisse (z.B. vault, stabify-infra)"
set_fact: set_fact:
# Wir nehmen an, dass alles in /opt eine App ist, außer explizite Ausnahmen # Wir nehmen an, dass alles in /opt eine App ist, außer explizite Ausnahmen
# Hier filtern wir nur Verzeichnisse, die Docker Compose Files haben könnten ignored_dirs: ['vault', 'stabify-infra', 'cni', 'containerd']
installed_apps: "{{ installed_dirs.files | map(attribute='path') | map('basename') | list }}" installed_apps: "{{ installed_dirs.files | map(attribute='path') | map('basename') | difference(['vault', 'stabify-infra', 'cni', 'containerd']) | list }}"
# 4. Bereinigung (Pruning) # 4. Bereinigung (Pruning)
- name: "Ermittle zu löschende Apps" - name: "Ermittle zu löschende Apps"
@@ -68,8 +68,8 @@
loop: "{{ apps_to_remove }}" loop: "{{ apps_to_remove }}"
loop_control: loop_control:
loop_var: app_name_to_remove loop_var: app_name_to_remove
# Sicherheitshalber: Lösche nichts, was 'vault' heißt, falls Config kaputt ist # Sicherheitshalber: Lösche nichts, was auf der Ignore-Liste steht (Redundant aber sicher)
when: app_name_to_remove != 'vault' when: app_name_to_remove not in ['vault', 'stabify-infra']
# 5. Rollen ausführen (Common & Users auch im Pull-Mode aktuell halten) # 5. Rollen ausführen (Common & Users auch im Pull-Mode aktuell halten)
- name: "Führe Rollen aus" - name: "Führe Rollen aus"

View File

@@ -1,3 +1,11 @@
- name: "Initialer Checkout des GitOps Repositories"
git:
repo: "{{ git_repo_url }}"
dest: /opt/stabify-infra
version: main
force: true # Sicherstellen, dass es sauber ist
ignore_errors: true # Fallback, falls Repo noch leer/privat (wird von ansible-pull eh nochmal probiert)
- name: "Deploy GitOps Service Unit" - name: "Deploy GitOps Service Unit"
template: template:
src: gitops-sync.service.j2 src: gitops-sync.service.j2

View File

@@ -12,7 +12,7 @@ User=root
# -d: Checkout Verzeichnis # -d: Checkout Verzeichnis
# -i: Inventory (hier localhost) # -i: Inventory (hier localhost)
# pull_deploy.yml: Das Playbook im Repo # pull_deploy.yml: Das Playbook im Repo
ExecStart=/usr/bin/ansible-pull -U {{ git_repo_url }} -d /opt/stabify-infra -i infrastructure/ansible/inventory_local.ini infrastructure/ansible/pull_deploy.yml ExecStart=/usr/bin/ansible-pull -U {{ git_repo_url }} -d /opt/stabify-infra -i /opt/stabify-infra/infrastructure/ansible/inventory_local.ini infrastructure/ansible/pull_deploy.yml
timeoutStartSec=600 timeoutStartSec=600
[Install] [Install]