package v2 ubuntu image
[infra/stack/kubernetes.git] / apps / spinnaker / kubespray / playbooks / roles / install / tasks / main.yml
1 ---
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19 #
20 - name: Load execution mode variables
21   include_vars: "{{ execution_mode }}.yaml"
22
23 - block:
24   - name: Create directories for helm repositories
25     file:
26       path: "{{ item.path }}"
27       state: "{{ item.state }}"
28     loop:
29       - {path: "{{ engine_workspace }}/offline/charts/stable", state: absent}
30       - {path: "{{ engine_workspace }}/offline/charts/stable", state: directory}
31       - {path: "{{ engine_workspace }}/offline/charts/local", state: absent}
32       - {path: "{{ engine_workspace }}/offline/charts/local", state: directory}
33
34   - name: Place index.yaml to webserver stable charts repository
35     template:
36       src: "index.yaml.j2"
37       dest: "{{ engine_workspace }}/offline/charts/stable/index.yaml"
38       force: true
39
40   - name: Create local repo index (empty initially)
41     command: "helm repo index {{ engine_workspace }}/offline/charts/local/"
42     creates: "{{ engine_workspace }}/offline/charts/local/index.yaml"
43   when: execution_mode == "offline-deployment"
44
45 - name: Initialize Helm
46   command: helm init --client-only --local-repo-url {{ local_repo_url }} --stable-repo-url {{ stable_repo_url }}
47   register: helm_init_result
48   changed_when: true
49   when: helm_version is version('v3', '<')
50
51 - name: Check if stable helm repo exists (helm v3+)
52   command: "helm repo list"
53   changed_when: true
54   failed_when: false
55   register: helm_repo_list_result
56
57 - name: Add stable helm repo (helm v3+)
58   command: "helm repo add stable {{ stable_repo_url }}"
59   register: helm_repo_add_stable_result
60   changed_when: true
61   when: >
62     helm_version is version('v3.0.0', '>=')
63     and execution_mode == "online-deployment"
64     and helm_repo_list_result is not search(stable_repo_url)
65
66 - name: Add local helm repo (helm v3+)
67   command: "helm repo add local {{ local_repo_url }}"
68   register: helm_repo_add_local_result
69   changed_when: true
70   when: >
71     helm_version is version('v3.0.0', '>=')
72     and execution_mode == "offline-deployment"
73     and helm_repo_list_result is not search(local_repo_url)
74
75 - name: Clone Helm Charts repository
76   git:
77     repo: "{{ helm_charts_git_url }}"
78     dest: "{{ engine_cache }}/repos/charts"
79     version: "{{ charts_version }}"
80     force: true
81     recursive: true
82   environment:
83     http_proxy: "{{ lookup('env','http_proxy') }}"
84     https_proxy: "{{ lookup('env','https_proxy') }}"
85     no_proxy: "{{ lookup('env','no_proxy') }}"
86
87 - name: Generate values.yaml
88   template:
89     src: "values.yaml.j2"
90     dest: "{{ engine_cache }}/repos/charts/stable/spinnaker/values.yaml"
91     force: true
92
93 - name: Remove previous installations of Spinnaker
94   command: >
95     helm delete --purge "{{ spinnaker_service }}"
96   changed_when: true
97   ignore_errors: true
98   tags: reset
99
100 - name: Remove Spinnaker namespace
101   command: >
102     kubectl delete ns "{{ spinnaker_namespace }}"
103   changed_when: true
104   ignore_errors: true
105   tags: reset
106
107 - name: Create Spinnaker namespace
108   k8s:
109     state: present
110     definition:
111       apiVersion: v1
112       kind: Namespace
113       metadata:
114         name: "{{ spinnaker_namespace }}"
115
116 - name: Verify Spinnaker Helm charts are available to be deployed
117   command: helm search spinnaker -l
118   register: helm_search
119   changed_when: false
120
121 - name: Log Helm chart list to console
122   debug:
123     msg: "{{ helm_search.stdout_lines }}"
124
125 - name: Inform user about Spinnaker deployment
126   debug:
127     msg: >
128       Spinnaker deployment is about to start!
129       This takes a while and nothing will be logged to console until the process is completed.
130
131 - name: Fetch all helm dependencies for Spinnaker
132   command: >
133     helm dependency update
134       {{ engine_cache }}/repos/charts/stable/spinnaker
135   changed_when: true
136
137 - name: Install Spinnaker using helm
138   command: >
139     helm install
140       {% if helm_version is version('v3.0.0', '<')%} --name {% endif %}"{{ spinnaker_service }}"
141       --namespace "{{ spinnaker_namespace }}"
142       --timeout "900{% if helm_version is version('v3.0.0', '>=') %}s{% endif %}"
143       {{ engine_cache }}/repos/charts/stable/spinnaker
144   register: spinnaker_helm_log
145   changed_when: true
146
147 - name: Log Spinnaker helm output to console
148   debug:
149     msg: "{{ spinnaker_helm_log.stdout_lines }}"
150
151 # wait 10 minutes for all containers to be started
152 - name: Wait for all containers to be started
153   shell: |
154     set -o pipefail
155     kubectl get po -n spinnaker | grep ContainerCreating | wc -l
156   register: kube
157   changed_when:
158     kube.stdout  == '0'
159   until:
160     kube.stdout  == '0'
161   retries: 60
162   delay: 10
163
164 # wait 20 minutes for all containers to be initialized
165 - block:
166     - name: Wait for all containers to be initialized
167       shell: |
168         set -o pipefail
169         kubectl get po -n spinnaker | grep Init | grep -v Error | wc -l
170       register: kube
171       changed_when:
172         kube.stdout  == '0'
173       until:
174         kube.stdout  == '0'
175       retries: 120
176       delay: 10
177   always:
178     - name: Get POD status
179       command: kubectl get po -n spinnaker
180       changed_when: false
181       register: kube
182
183     - name: Log POD status to console
184       debug:
185         msg: "{{ kube.stdout_lines }}"
186
187     - name: Get summary of Spinnaker deployment
188       script: log-spinnaker-status.sh
189       register: spinnaker_status
190
191     - name: Log Spinnaker status to console
192       debug:
193         msg: "{{ spinnaker_status.stdout_lines }}"
194
195 # vim: set ts=2 sw=2 expandtab: