2026-01-13 10:43:16 +01:00
---
2026-01-17 09:57:07 +01:00
# Configure Authentik flows (invitation, 2FA) via Blueprints
2026-01-13 10:43:16 +01:00
- name : Use bootstrap token for API access
set_fact :
authentik_api_token : "{{ client_secrets.authentik_bootstrap_token }}"
2026-01-14 08:54:47 +01:00
- name : Wait for Authentik API to be ready
shell : |
2026-01-14 09:03:13 +01:00
i=1
while [ $i -le 30 ]; do
2026-01-14 13:47:17 +01:00
if docker exec authentik-server curl -sf -H "Authorization: Bearer {{ authentik_api_token }}" http://localhost:9000/api/v3/flows/instances/ > /dev/null 2>&1; then
2026-01-14 08:54:47 +01:00
echo "Authentik API is ready"
exit 0
fi
echo "Waiting for Authentik API... attempt $i/30"
sleep 5
2026-01-14 09:03:13 +01:00
i=$((i+1))
2026-01-14 08:54:47 +01:00
done
exit 1
register : api_wait
changed_when : false
2026-01-14 14:15:58 +01:00
- name : Create blueprints directory on server
file :
path : "{{ authentik_config_dir }}/blueprints"
state : directory
2026-01-13 10:43:16 +01:00
mode : '0755'
2026-01-15 13:48:40 +01:00
- name : Copy flow blueprints to server
2026-01-14 08:39:43 +01:00
copy :
2026-01-15 13:48:40 +01:00
src : "{{ item }}"
dest : "{{ authentik_config_dir }}/blueprints/{{ item }}"
2026-01-14 14:15:58 +01:00
mode : '0644'
2026-01-15 13:48:40 +01:00
loop :
- custom-flows.yaml
- enrollment-flow.yaml
register : blueprints_copied
2026-01-14 08:39:43 +01:00
2026-01-15 13:48:40 +01:00
- name : Copy blueprints into authentik-worker container
2026-01-13 10:55:14 +01:00
shell : |
2026-01-15 13:48:40 +01:00
docker cp "{{ authentik_config_dir }}/blueprints/{{ item }}" authentik-worker:/blueprints/{{ item }}
loop :
- custom-flows.yaml
- enrollment-flow.yaml
when : blueprints_copied.changed
- name : Copy blueprints into authentik-server container
2026-01-14 08:39:43 +01:00
shell : |
2026-01-15 13:48:40 +01:00
docker cp "{{ authentik_config_dir }}/blueprints/{{ item }}" authentik-server:/blueprints/{{ item }}
loop :
- custom-flows.yaml
- enrollment-flow.yaml
when : blueprints_copied.changed
2026-01-14 08:39:43 +01:00
2026-01-14 14:15:58 +01:00
- name : Wait for blueprint to be discovered and applied
2026-01-13 10:43:16 +01:00
shell : |
2026-01-14 14:15:58 +01:00
echo "Waiting for blueprint to be discovered and applied..."
sleep 10
# Check if blueprint instance was created
i=1
while [ $i -le 24 ]; do
result=$(docker exec authentik-server curl -sf -H 'Authorization : Bearer {{ authentik_api_token }}' \
'http://localhost:9000/api/v3/managed/blueprints/' 2 >/dev/null || echo '')
if echo "$result" | grep -q 'custom-flow-configuration'; then
echo "Blueprint instance found"
# Check if it has been applied successfully
if echo "$result" | grep -A 10 'custom-flow-configuration' | grep -q 'successful'; then
echo "Blueprint applied successfully"
exit 0
else
echo "Blueprint found but not yet applied, waiting..."
fi
else
echo "Waiting for blueprint discovery... attempt $i/24"
fi
2026-01-13 10:43:16 +01:00
2026-01-14 14:15:58 +01:00
sleep 5
i=$((i+1))
done
echo "Blueprint may still be applying, continuing..."
exit 0
register : blueprint_wait
changed_when : false
- name : Verify invitation stage was created
2026-01-13 10:43:16 +01:00
shell : |
2026-01-14 14:15:58 +01:00
docker exec authentik-server curl -sf -H "Authorization: Bearer {{ authentik_api_token }}" \
"http://localhost:9000/api/v3/stages/all/" | \
python3 -c "import sys, json; data = json.load(sys.stdin); stages = [s for s in data['results'] if 'invitation' in s.get('name', '').lower()]; print(json.dumps({'found': len(stages) > 0, 'count': len(stages)}))"
register : invitation_check
changed_when : false
failed_when : false
2026-01-13 10:43:16 +01:00
- name : Display flows configuration status
debug :
msg : |
========================================
Authentik Flows Configuration
========================================
2026-01-14 14:15:58 +01:00
Configuration Method : YAML Blueprints
2026-01-15 13:48:40 +01:00
Blueprints Deployed :
- /blueprints/custom-flows.yaml (2FA enforcement)
- /blueprints/enrollment-flow.yaml (invitation-only registration)
2026-01-14 14:15:58 +01:00
2026-01-15 13:48:40 +01:00
✓ Blueprints Deployed : {{ blueprints_copied.changed }}
✓ Blueprints Applied : {{ 'Yes' if 'successfully' in blueprint_wait.stdout else 'In Progress' }}
2026-01-14 14:15:58 +01:00
Verification :
{{ invitation_check.stdout | default('Invitation stage : Checking...') }}
2026-01-14 08:39:43 +01:00
2026-01-14 14:15:58 +01:00
Note : Authentik applies blueprints asynchronously.
Changes should be visible within 1-2 minutes.
2026-01-17 09:57:07 +01:00
Recovery flows must be configured manually in Authentik admin UI.
2026-01-13 10:43:16 +01:00
2026-01-15 13:48:40 +01:00
Flow URLs :
- Enrollment : https://{{ authentik_domain }}/if/flow/default-enrollment-flow/
2026-01-13 10:43:16 +01:00
2026-01-15 13:48:40 +01:00
Email configuration is active - emails sent via Mailgun SMTP.
2026-01-13 10:43:16 +01:00
========================================