blob: 6409a10c7d18bdde3d7152b29c4d1ddf2b9690b1 [file] [log] [blame]
# Copyright (c) 2022 VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Create Keycloak realm
no_log: true
become: false
delegate_to: localhost
changed_when: false
community.general.keycloak_realm:
# Keycloak settings
auth_keycloak_url: "{{ grafana_keycloak_server_url }}"
auth_realm: "{{ grafana_keycloak_user_realm_name }}"
auth_client_id: "{{ grafana_keycloak_admin_client_id }}"
auth_username: "{{ grafana_keycloak_admin_user }}"
auth_password: "{{ grafana_keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Realm settings
id: "{{ grafana_keycloak_realm }}"
realm: "{{ grafana_keycloak_realm }}"
display_name: "{{ grafana_keycloak_realm_name }}"
enabled: true
- name: Add client roles in "id_token"
no_log: true
become: false
delegate_to: localhost
changed_when: false
community.general.keycloak_clientscope:
# Keycloak settings
auth_keycloak_url: "{{ grafana_keycloak_server_url }}"
auth_realm: "{{ grafana_keycloak_user_realm_name }}"
auth_client_id: "{{ grafana_keycloak_admin_client_id }}"
auth_username: "{{ grafana_keycloak_admin_user }}"
auth_password: "{{ grafana_keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Client scope settings
name: roles
realm: "{{ grafana_keycloak_realm }}"
protocol_mappers:
- name: client roles
protocol: openid-connect
protocolMapper: oidc-usermodel-client-role-mapper
config:
claim.name: "resource_access.${client_id}.roles"
access.token.claim: true
id.token.claim: true
multivalued: true
- name: Create Keycloak client
no_log: true
become: false
run_once: true
delegate_to: localhost
community.general.keycloak_client:
# Keycloak settings
auth_keycloak_url: "{{ grafana_keycloak_server_url }}"
auth_realm: "{{ grafana_keycloak_user_realm_name }}"
auth_client_id: "{{ grafana_keycloak_admin_client_id }}"
auth_username: "{{ grafana_keycloak_admin_user }}"
auth_password: "{{ grafana_keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Realm settings
realm: "{{ grafana_keycloak_realm }}"
client_id: "{{ grafana_keycloak_client_id }}"
secret: "{{ grafana_keycloak_client_secret }}"
redirect_uris:
- "https://{{ kube_prometheus_stack_grafana_host }}/login/generic_oauth"
- name: Create Keycloak roles
no_log: true
become: false
run_once: true
delegate_to: localhost
community.general.keycloak_role:
# Keycloak settings
auth_keycloak_url: "{{ grafana_keycloak_server_url }}"
auth_realm: "{{ grafana_keycloak_user_realm_name }}"
auth_client_id: "{{ grafana_keycloak_admin_client_id }}"
auth_username: "{{ grafana_keycloak_admin_user }}"
auth_password: "{{ grafana_keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Realm settings
realm: "{{ grafana_keycloak_realm }}"
client_id: "{{ grafana_keycloak_client_id }}"
name: "{{ item }}"
loop: ["admin", "editor", "viewer"]
- name: Retrieve "etcd" CA certificate
ansible.builtin.slurp:
src: /etc/kubernetes/pki/etcd/ca.crt
register: _etcd_ca_crt
- name: Retrieve "etcd" client certificate
ansible.builtin.slurp:
src: /etc/kubernetes/pki/etcd/healthcheck-client.crt
register: _etcd_healthcheck_client_crt
- name: Retrieve "etcd" client key
ansible.builtin.slurp:
src: /etc/kubernetes/pki/etcd/healthcheck-client.key
register: _etcd_healthcheck_client_key
- name: Uninstall the legacy "ethtool-exporter"
kubernetes.core.k8s:
state: absent
api_version: v1
kind: DaemonSet
name: ethtool-exporter
namespace: "{{ kube_prometheus_stack_helm_release_namespace }}"
- name: Uninstall the legacy HelmRelease
run_once: true
block:
- name: Suspend the existing HelmRelease
failed_when: false
kubernetes.core.k8s:
state: patched
api_version: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
name: "{{ kube_prometheus_stack_helm_release_name }}"
namespace: "{{ kube_prometheus_stack_helm_release_namespace }}"
definition:
spec:
suspend: true
- name: Remove the existing HelmRelease
failed_when: false
kubernetes.core.k8s:
state: absent
api_version: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
name: "{{ kube_prometheus_stack_helm_release_name }}"
namespace: "{{ kube_prometheus_stack_helm_release_namespace }}"
- name: Create secrets for monitoring
kubernetes.core.k8s:
state: present
definition:
- apiVersion: v1
kind: Namespace
metadata:
name: "{{ kube_prometheus_stack_helm_release_namespace }}"
- apiVersion: v1
kind: Secret
metadata:
name: grafana-auth-generic-oauth-secret
namespace: "{{ kube_prometheus_stack_helm_release_namespace }}"
stringData:
client_id: "{{ grafana_keycloak_client_id }}"
client_secret: "{{ grafana_keycloak_client_secret }}"
- apiVersion: v1
kind: Secret
metadata:
name: kube-prometheus-stack-etcd-client-cert
namespace: monitoring
data:
ca.crt: "{{ _etcd_ca_crt.content }}"
healthcheck-client.crt: "{{ _etcd_healthcheck_client_crt.content }}"
healthcheck-client.key: "{{ _etcd_healthcheck_client_key.content }}"
- name: Install all CRDs
run_once: true
changed_when: false
kubernetes.core.k8s:
state: present
definition: "{{ lookup('pipe', 'cat ' + role_path + '/../../charts/kube-prometheus-stack/charts/crds/crds/crd-*.yaml') | regex_replace('- =$', '- \"=\"', multiline=True) | from_yaml_all }}" # noqa: yaml[line-length]
apply: true
server_side_apply:
field_manager: atmosphere
force_conflicts: true
tags:
- kube-prometheus-stack-crds
- name: Deploy Helm chart
run_once: true
kubernetes.core.helm:
name: "{{ kube_prometheus_stack_helm_release_name }}"
chart_ref: "{{ kube_prometheus_stack_helm_chart_ref }}"
release_namespace: "{{ kube_prometheus_stack_helm_release_namespace }}"
create_namespace: true
kubeconfig: /etc/kubernetes/admin.conf
values: "{{ _kube_prometheus_stack_helm_values | combine(kube_prometheus_stack_helm_values, recursive=True) }}"