--- # ============LICENSE_START======================================================= # Copyright (C) 2019 The Nordix Foundation. All rights reserved. # ================================================================================ # 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. # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= - name: Load execution mode variables include_vars: "{{ execution_mode }}.yaml" - block: - name: Create directories for helm repositories file: path: "{{ item.path }}" state: "{{ item.state }}" loop: - {path: "{{ engine_workspace }}/offline/charts/stable", state: absent} - {path: "{{ engine_workspace }}/offline/charts/stable", state: directory} - {path: "{{ engine_workspace }}/offline/charts/local", state: absent} - {path: "{{ engine_workspace }}/offline/charts/local", state: directory} - name: Place index.yaml to webserver stable charts repository template: src: "index.yaml.j2" dest: "{{ engine_workspace }}/offline/charts/stable/index.yaml" force: true when: execution_mode == "offline-deployment" - name: Initialize Helm command: helm init --client-only --local-repo-url {{ local_repo_url }} --stable-repo-url {{ stable_repo_url }} register: helm_init_result changed_when: true when: helm_version is version('v3', '<') - name: Check if stable helm repo exists (helm v3+) command: "helm repo list" changed_when: true failed_when: false register: helm_repo_list_result - name: Add stable helm repo (helm v3+) command: "helm repo add stable {{ stable_repo_url }}" register: helm_repo_add_stable_result changed_when: true when: > helm_version is version('v3.0.0', '>=') and execution_mode == "online-deployment" and helm_repo_list_result is not search(stable_repo_url) - name: Clone Helm Charts repository git: repo: "{{ helm_charts_git_url }}" dest: "{{ config_path }}/repos/charts" version: "{{ charts_version }}" force: true recursive: true environment: http_proxy: "{{ lookup('env','http_proxy') }}" https_proxy: "{{ lookup('env','https_proxy') }}" no_proxy: "{{ lookup('env','no_proxy') }}" - name: Generate values.yaml template: src: "values.yaml.j2" dest: "{{ config_path }}/repos/charts/stable/prometheus/values.yaml" force: true - name: Remove previous installations of Prometheus command: > helm delete --purge "{{ prometheus_service }}" changed_when: true ignore_errors: true tags: reset - name: Remove Prometheus namespace command: > kubectl delete ns "{{ prometheus_namespace }}" changed_when: true ignore_errors: true tags: reset - name: Create Prometheus namespace k8s: state: present definition: apiVersion: v1 kind: Namespace metadata: name: "{{ prometheus_namespace }}" - name: Install Prometheus using helm command: > helm install {% if helm_version is version('v3.0.0', '<') %} --name {% endif %}"{{ prometheus_service }}" --namespace "{{ prometheus_namespace }}" --timeout "900{% if helm_version is version('v3.0.0', '>=') %}s{% endif %}" {{ config_path }}/repos/charts/stable/prometheus register: prometheus_helm_log changed_when: true - name: Log Prometheus helm output to console debug: msg: "{{ prometheus_helm_log.stdout_lines }}" - name: Wait until Prometheus pods are available k8s_facts: kind: Pod namespace: "{{ prometheus_namespace }}" label_selectors: - "app = {{ prometheus_service }}" field_selectors: - status.phase=Running register: prometheus_pod_status until: - prometheus_pod_status.resources is defined - prometheus_pod_status.resources retries: 30 delay: 10 - name: Install Prometheus LoadBalancer service k8s: state: present definition: "{{ lookup('template', 'prometheus_service.yaml.j2') }}" register: prometheus_service_status - name: Log Prometheus service information to console debug: msg: - "------------------------------" - "Prometheus Service information" - "------------------------------" - "clusterIP: {{ prometheus_service_status.result.spec.clusterIP }}" - "targetPort: {{ prometheus_service_status.result.spec.ports[0].targetPort }}" - "nodePort: {{ prometheus_service_status.result.spec.ports[0].nodePort }}" - "------------------------------" # vim: set ts=2 sw=2 expandtab: