blob: 5ab971e58553ec314b1077e7904a88f95a97efd7 [file] [log] [blame]
Mohammed Naserb7b97d62022-03-12 16:30:00 -05001# Copyright (c) 2022 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
guilhermesteinmuller4980b132023-01-24 18:50:14 +000015- name: Uninstall the legacy HelmRelease
16 run_once: true
17 block:
18 - name: Suspend the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000019 failed_when: false
guilhermesteinmuller4980b132023-01-24 18:50:14 +000020 kubernetes.core.k8s:
21 state: patched
22 api_version: helm.toolkit.fluxcd.io/v2beta1
23 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000024 name: "{{ keystone_helm_release_name }}"
25 namespace: "{{ keystone_helm_release_namespace }}"
guilhermesteinmuller4980b132023-01-24 18:50:14 +000026 definition:
27 spec:
28 suspend: true
29
30 - name: Remove the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000031 failed_when: false
guilhermesteinmuller4980b132023-01-24 18:50:14 +000032 kubernetes.core.k8s:
33 state: absent
34 api_version: helm.toolkit.fluxcd.io/v2beta1
35 kind: HelmRelease
Mohammed Naser2145fc32023-01-29 23:23:03 +000036 name: "{{ keystone_helm_release_name }}"
37 namespace: "{{ keystone_helm_release_namespace }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050038
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020039- name: Create Keycloak realms
Mohammed Naser59853d42023-11-29 20:32:24 -050040 no_log: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020041 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020042 changed_when: false
43 community.general.keycloak_realm:
44 # Keycloak settings
45 auth_keycloak_url: "{{ item.keycloak_server_url }}"
46 auth_realm: "{{ item.keycloak_user_realm_name }}"
47 auth_client_id: "{{ item.keycloak_admin_client_id }}"
48 auth_username: "{{ item.keycloak_admin_user }}"
49 auth_password: "{{ item.keycloak_admin_password }}"
50 validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
51 # Realm settings
52 id: "{{ item.keycloak_realm }}"
53 realm: "{{ item.keycloak_realm }}"
54 display_name: "{{ item.label }}"
55 enabled: true
56 loop: "{{ keystone_domains }}"
57 loop_control:
58 label: "{{ item.name }}"
59
60- name: Create ConfigMap with all OpenID connect configurations
61 run_once: true
62 kubernetes.core.k8s:
63 template: configmap-openid-metadata.yml.j2
64
65- name: Create Keycloak clients
Mohammed Naser8dc7add2024-01-02 16:43:07 -050066 no_log: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020067 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020068 community.general.keycloak_client:
69 # Keycloak settings
70 auth_keycloak_url: "{{ item.keycloak_server_url }}"
71 auth_realm: "{{ item.keycloak_user_realm_name }}"
72 auth_client_id: "{{ item.keycloak_admin_client_id }}"
73 auth_username: "{{ item.keycloak_admin_user }}"
74 auth_password: "{{ item.keycloak_admin_password }}"
75 validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
76 # Realm settings
77 realm: "{{ item.keycloak_realm }}"
78 client_id: "{{ item.keycloak_client_id }}"
79 secret: "{{ item.keycloak_client_secret }}"
80 redirect_uris:
81 - "{{ keystone_oidc_redirect_uri }}"
82 - "https://{{ openstack_helm_endpoints_horizon_api_host }}/auth/logout/"
83 loop: "{{ keystone_domains }}"
84 loop_control:
85 label: "{{ item.name }}"
86
Mohammed Naserb7b97d62022-03-12 16:30:00 -050087- name: Deploy Helm chart
guilhermesteinmuller4980b132023-01-24 18:50:14 +000088 run_once: true
89 kubernetes.core.helm:
Mohammed Naser2145fc32023-01-29 23:23:03 +000090 name: "{{ keystone_helm_release_name }}"
91 chart_ref: "{{ keystone_helm_chart_ref }}"
92 release_namespace: "{{ keystone_helm_release_namespace }}"
guilhermesteinmuller4980b132023-01-24 18:50:14 +000093 create_namespace: true
94 kubeconfig: /etc/kubernetes/admin.conf
Mohammed Naser2145fc32023-01-29 23:23:03 +000095 values: "{{ _keystone_helm_values | combine(keystone_helm_values, recursive=True) }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050096
97- name: Create Ingress
98 ansible.builtin.include_role:
99 name: openstack_helm_ingress
100 vars:
101 openstack_helm_ingress_endpoint: identity
102 openstack_helm_ingress_service_name: keystone-api
103 openstack_helm_ingress_service_port: 5000
Mohammed Naser2145fc32023-01-29 23:23:03 +0000104 openstack_helm_ingress_annotations: "{{ keystone_ingress_annotations }}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200105
Michiel Piscaer9ce6e892023-11-16 09:02:35 +0100106- name: Validate if ingress is reachable
107 ansible.builtin.uri:
108 url: "https://{{ openstack_helm_endpoints_keystone_api_host }}"
109 status_code: [300]
110 register: keystone_ingress_validate
111 until: keystone_ingress_validate.status == 300
Oleksandr K897b78b2023-12-29 10:55:06 +0100112 retries: 120
Michiel Piscaer9ce6e892023-11-16 09:02:35 +0100113 delay: 1
114
Oleksandr Kozachenko7299c982023-11-23 10:48:14 +0100115- name: Wait until identity service ready
116 kubernetes.core.k8s_info:
117 api_version: apps/v1
118 kind: Deployment
119 name: keystone-api
120 namespace: openstack
121 wait_sleep: 10
122 wait_timeout: 600
123 wait: true
124 wait_condition:
125 type: Available
126 status: true
127
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200128- name: Create Keystone domains
129 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200130 vexxhost.atmosphere.identity_domain:
131 name: "{{ item.name }}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200132 loop: "{{ keystone_domains }}"
133 loop_control:
134 label: "{{ item.name }}"
Oleksandr Kozachenko7299c982023-11-23 10:48:14 +0100135 # NOTE: This often fails since it takes time for the keystone api ready.
136 retries: 60
137 delay: 5
138 register: keystone_domains_result
139 until: keystone_domains_result is not failed
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200140
141- name: Create Keystone identity providers
142 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200143 vexxhost.atmosphere.federation_idp:
144 name: "{{ item.domain.name }}"
145 domain_id: "{{ item.domain.id }}"
146 remote_ids:
147 - "{{ item.item | vexxhost.atmosphere.issuer_from_domain }}"
148 loop: "{{ keystone_domains_result.results }}"
149 loop_control:
150 label: "{{ item.domain.name }}"
151
152- name: Create Keystone federation mappings
153 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200154 vexxhost.atmosphere.federation_mapping:
155 name: "{{ item.name }}-openid"
156 rules:
157 - local:
158 - user:
159 type: local
160 id: "{0}"
Ed Timmons Jr4ba25cf2023-11-29 23:22:43 -0500161 name: "{1}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200162 domain:
163 name: "{{ item.name }}"
164 remote:
165 - type: OIDC-sub
Ed Timmons Jr4ba25cf2023-11-29 23:22:43 -0500166 - type: OIDC-preferred_username
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200167 loop: "{{ keystone_domains }}"
168 loop_control:
169 label: "{{ item.name }}"
170
171- name: Create Keystone federation protocols
172 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200173 vexxhost.atmosphere.keystone_federation_protocol:
174 name: openid
175 idp_id: "{{ item.name }}"
176 mapping_id: "{{ item.name }}-openid"
177 loop: "{{ keystone_domains }}"
178 loop_control:
179 label: "{{ item.name }}"