blob: c4400faf73f84d815dd35697e278652aa1853ff6 [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
Mohammed Naser8dc7add2024-01-02 16:43:07 -050041 become: false
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020042 run_once: true
43 delegate_to: localhost
44 changed_when: false
45 community.general.keycloak_realm:
46 # Keycloak settings
47 auth_keycloak_url: "{{ item.keycloak_server_url }}"
48 auth_realm: "{{ item.keycloak_user_realm_name }}"
49 auth_client_id: "{{ item.keycloak_admin_client_id }}"
50 auth_username: "{{ item.keycloak_admin_user }}"
51 auth_password: "{{ item.keycloak_admin_password }}"
52 validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
53 # Realm settings
54 id: "{{ item.keycloak_realm }}"
55 realm: "{{ item.keycloak_realm }}"
56 display_name: "{{ item.label }}"
57 enabled: true
58 loop: "{{ keystone_domains }}"
59 loop_control:
60 label: "{{ item.name }}"
61
62- name: Create ConfigMap with all OpenID connect configurations
63 run_once: true
64 kubernetes.core.k8s:
65 template: configmap-openid-metadata.yml.j2
66
67- name: Create Keycloak clients
Mohammed Naser8dc7add2024-01-02 16:43:07 -050068 no_log: true
69 become: false
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020070 run_once: true
71 delegate_to: localhost
72 community.general.keycloak_client:
73 # Keycloak settings
74 auth_keycloak_url: "{{ item.keycloak_server_url }}"
75 auth_realm: "{{ item.keycloak_user_realm_name }}"
76 auth_client_id: "{{ item.keycloak_admin_client_id }}"
77 auth_username: "{{ item.keycloak_admin_user }}"
78 auth_password: "{{ item.keycloak_admin_password }}"
79 validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
80 # Realm settings
81 realm: "{{ item.keycloak_realm }}"
82 client_id: "{{ item.keycloak_client_id }}"
83 secret: "{{ item.keycloak_client_secret }}"
84 redirect_uris:
85 - "{{ keystone_oidc_redirect_uri }}"
86 - "https://{{ openstack_helm_endpoints_horizon_api_host }}/auth/logout/"
87 loop: "{{ keystone_domains }}"
88 loop_control:
89 label: "{{ item.name }}"
90
Mohammed Naserb7b97d62022-03-12 16:30:00 -050091- name: Deploy Helm chart
guilhermesteinmuller4980b132023-01-24 18:50:14 +000092 run_once: true
93 kubernetes.core.helm:
Mohammed Naser2145fc32023-01-29 23:23:03 +000094 name: "{{ keystone_helm_release_name }}"
95 chart_ref: "{{ keystone_helm_chart_ref }}"
96 release_namespace: "{{ keystone_helm_release_namespace }}"
guilhermesteinmuller4980b132023-01-24 18:50:14 +000097 create_namespace: true
98 kubeconfig: /etc/kubernetes/admin.conf
Mohammed Naser2145fc32023-01-29 23:23:03 +000099 values: "{{ _keystone_helm_values | combine(keystone_helm_values, recursive=True) }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -0500100
101- name: Create Ingress
102 ansible.builtin.include_role:
103 name: openstack_helm_ingress
104 vars:
105 openstack_helm_ingress_endpoint: identity
106 openstack_helm_ingress_service_name: keystone-api
107 openstack_helm_ingress_service_port: 5000
Mohammed Naser2145fc32023-01-29 23:23:03 +0000108 openstack_helm_ingress_annotations: "{{ keystone_ingress_annotations }}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200109
Michiel Piscaer9ce6e892023-11-16 09:02:35 +0100110- name: Validate if ingress is reachable
111 ansible.builtin.uri:
112 url: "https://{{ openstack_helm_endpoints_keystone_api_host }}"
113 status_code: [300]
114 register: keystone_ingress_validate
115 until: keystone_ingress_validate.status == 300
Oleksandr K897b78b2023-12-29 10:55:06 +0100116 retries: 120
Michiel Piscaer9ce6e892023-11-16 09:02:35 +0100117 delay: 1
118
Oleksandr Kozachenko7299c982023-11-23 10:48:14 +0100119- name: Wait until identity service ready
120 kubernetes.core.k8s_info:
121 api_version: apps/v1
122 kind: Deployment
123 name: keystone-api
124 namespace: openstack
125 wait_sleep: 10
126 wait_timeout: 600
127 wait: true
128 wait_condition:
129 type: Available
130 status: true
131
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200132- name: Create Keystone domains
133 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200134 vexxhost.atmosphere.identity_domain:
135 name: "{{ item.name }}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200136 loop: "{{ keystone_domains }}"
137 loop_control:
138 label: "{{ item.name }}"
Oleksandr Kozachenko7299c982023-11-23 10:48:14 +0100139 # NOTE: This often fails since it takes time for the keystone api ready.
140 retries: 60
141 delay: 5
142 register: keystone_domains_result
143 until: keystone_domains_result is not failed
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200144
145- name: Create Keystone identity providers
146 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200147 vexxhost.atmosphere.federation_idp:
148 name: "{{ item.domain.name }}"
149 domain_id: "{{ item.domain.id }}"
150 remote_ids:
151 - "{{ item.item | vexxhost.atmosphere.issuer_from_domain }}"
152 loop: "{{ keystone_domains_result.results }}"
153 loop_control:
154 label: "{{ item.domain.name }}"
155
156- name: Create Keystone federation mappings
157 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200158 vexxhost.atmosphere.federation_mapping:
159 name: "{{ item.name }}-openid"
160 rules:
161 - local:
162 - user:
163 type: local
164 id: "{0}"
Ed Timmons Jr4ba25cf2023-11-29 23:22:43 -0500165 name: "{1}"
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200166 domain:
167 name: "{{ item.name }}"
168 remote:
169 - type: OIDC-sub
Ed Timmons Jr4ba25cf2023-11-29 23:22:43 -0500170 - type: OIDC-preferred_username
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200171 loop: "{{ keystone_domains }}"
172 loop_control:
173 label: "{{ item.name }}"
174
175- name: Create Keystone federation protocols
176 run_once: true
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +0200177 vexxhost.atmosphere.keystone_federation_protocol:
178 name: openid
179 idp_id: "{{ item.name }}"
180 mapping_id: "{{ item.name }}-openid"
181 loop: "{{ keystone_domains }}"
182 loop_control:
183 label: "{{ item.name }}"