Move pre, postinstall, scenario, and apps to stack
[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   when: execution_mode == "offline-deployment"
40
41 - name: Initialize Helm
42   command: helm init --client-only --local-repo-url {{ local_repo_url }} --stable-repo-url {{ stable_repo_url }}
43   register: helm_init_result
44   changed_when: true
45
46 - name: Clone Helm Charts repository
47   git:
48     repo: "{{ helm_charts_git_url }}"
49     dest: "{{ engine_cache }}/repos/charts"
50     version: "{{ charts_version }}"
51     force: true
52     recursive: true
53   environment:
54     http_proxy: "{{ lookup('env','http_proxy') }}"
55     https_proxy: "{{ lookup('env','https_proxy') }}"
56     no_proxy: "{{ lookup('env','no_proxy') }}"
57
58 - name: Generate values.yaml
59   template:
60     src: "values.yaml.j2"
61     dest: "{{ engine_cache }}/repos/charts/stable/spinnaker/values.yaml"
62     force: true
63
64 - name: Remove previous installations of Spinnaker
65   command: >
66     helm delete --purge "{{ spinnaker_service }}"
67   changed_when: true
68   ignore_errors: true
69   tags: reset
70
71 - name: Remove Spinnaker namespace
72   command: >
73     kubectl delete ns "{{ spinnaker_namespace }}"
74   changed_when: true
75   ignore_errors: true
76   tags: reset
77
78 - name: Create Spinnaker namespace
79   k8s:
80     state: present
81     definition:
82       apiVersion: v1
83       kind: Namespace
84       metadata:
85         name: "{{ spinnaker_namespace }}"
86
87 - name: Verify Spinnaker Helm charts are available to be deployed
88   command: helm search spinnaker -l
89   register: helm_search
90   changed_when: false
91
92 - name: Log Helm chart list to console
93   debug:
94     msg: "{{ helm_search.stdout_lines }}"
95
96 - name: Inform user about Spinnaker deployment
97   debug:
98     msg: >
99       Spinnaker deployment is about to start!
100       This takes a while and nothing will be logged to console until the process is completed.
101
102 - name: Fetch all helm dependencies for Spinnaker
103   command: >
104     helm dependency update
105       {{ engine_cache }}/repos/charts/stable/spinnaker
106   changed_when: true
107
108 - name: Install Spinnaker using helm
109   command: >
110     helm install
111       --name "{{ spinnaker_service }}"
112       --namespace "{{ spinnaker_namespace }}"
113       --timeout 900
114       {{ engine_cache }}/repos/charts/stable/spinnaker
115   register: spinnaker_helm_log
116   changed_when: true
117
118 - name: Log Spinnaker helm output to console
119   debug:
120     msg: "{{ spinnaker_helm_log.stdout_lines }}"
121
122 # wait 10 minutes for all containers to be started
123 - name: Wait for all containers to be started
124   shell: |
125     set -o pipefail
126     kubectl get po -n spinnaker | grep ContainerCreating | wc -l
127   register: kube
128   changed_when:
129     kube.stdout  == '0'
130   until:
131     kube.stdout  == '0'
132   retries: 60
133   delay: 10
134
135 # wait 20 minutes for all containers to be initialized
136 - block:
137     - name: Wait for all containers to be initialized
138       shell: |
139         set -o pipefail
140         kubectl get po -n spinnaker | grep Init | grep -v Error | wc -l
141       register: kube
142       changed_when:
143         kube.stdout  == '0'
144       until:
145         kube.stdout  == '0'
146       retries: 120
147       delay: 10
148   always:
149     - name: Get POD status
150       command: kubectl get po -n spinnaker
151       changed_when: false
152       register: kube
153
154     - name: Log POD status to console
155       debug:
156         msg: "{{ kube.stdout_lines }}"
157
158     - name: Get summary of Spinnaker deployment
159       script: log-spinnaker-status.sh
160       register: spinnaker_status
161
162     - name: Log Spinnaker status to console
163       debug:
164         msg: "{{ spinnaker_status.stdout_lines }}"
165
166 # vim: set ts=2 sw=2 expandtab: