Post-Tyranny-Tech-Infrastru.../ansible/roles/authentik/tasks/flows.yml
Pieter 8c3553d89f feat: Add Authentik recovery and invitation flows
This commit adds password recovery and user invitation flows for Authentik,
enabling users to reset passwords via email and admins to invite users.

Features Added:
- Recovery flow: Users can request password reset emails
- Invitation flow: Admins can send user invitation emails
- Python scripts use Authentik API (no hardcoded credentials)
- Flows task automatically verifies/creates flows on deployment

Changes:
- authentik/files/create_recovery_flow.py: Recovery flow script
- authentik/files/create_invitation_flow.py: Invitation flow script
- authentik/tasks/flows.yml: Flow configuration task
- authentik/tasks/main.yml: Include flows task

This ensures:
✓ Password recovery emails work automatically
✓ User invitations work automatically
✓ Flows are configured on every deployment
✓ No hardcoded credentials (uses bootstrap token)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-13 10:43:16 +01:00

67 lines
1.9 KiB
YAML

---
# Configure Authentik flows (recovery, invitation)
- name: Use bootstrap token for API access
set_fact:
authentik_api_token: "{{ client_secrets.authentik_bootstrap_token }}"
- name: Copy recovery flow script to server
copy:
src: create_recovery_flow.py
dest: /tmp/create_recovery_flow.py
mode: '0755'
- name: Copy invitation flow script to server
copy:
src: create_invitation_flow.py
dest: /tmp/create_invitation_flow.py
mode: '0755'
- name: Create/verify recovery flow
shell: |
docker exec -i authentik-server python3 /tmp/create_recovery_flow.py \
"http://localhost:9000" \
"{{ authentik_api_token }}"
register: recovery_flow
changed_when: "'already exists' not in recovery_flow.stdout"
failed_when: recovery_flow.rc != 0
- name: Create/verify invitation flow
shell: |
docker exec -i authentik-server python3 /tmp/create_invitation_flow.py \
"http://localhost:9000" \
"{{ authentik_api_token }}"
register: invitation_flow
changed_when: "'already exists' not in invitation_flow.stdout"
failed_when: invitation_flow.rc != 0
- name: Copy flow scripts into container
shell: |
docker cp /tmp/create_recovery_flow.py authentik-server:/tmp/
docker cp /tmp/create_invitation_flow.py authentik-server:/tmp/
changed_when: false
- name: Cleanup flow scripts from host
file:
path: "{{ item }}"
state: absent
loop:
- /tmp/create_recovery_flow.py
- /tmp/create_invitation_flow.py
- name: Display flows configuration status
debug:
msg: |
========================================
Authentik Flows Configuration
========================================
✓ Recovery Flow: Configured
Users can reset passwords via email
✓ Invitation Flow: Configured
Admins can invite users via email
Email configuration is active and flows
will send emails via Mailgun SMTP.
========================================