Ingress Nginx Integration
[infra/stack/kubernetes.git] / apps / istio / 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: Make sure "{{ istio_work_dir }}" exists
21   file:
22     path: "{{ istio_work_dir }}"
23     state: directory
24
25 # TODO: validate download checksum
26 - name: Download the installation files
27   unarchive:
28     src: "{{ istio_download_url }}"
29     dest: "{{ istio_work_dir }}"
30     remote_src: true
31   environment:
32     http_proxy: "{{ lookup('env','http_proxy') }}"
33     https_proxy: "{{ lookup('env','https_proxy') }}"
34     no_proxy: "{{ lookup('env','no_proxy') }}"
35
36 - name: List existing installation of Istio
37   shell: helm list | awk '{print $1}' | grep istio
38   register: installed_istio_charts
39   ignore_errors: true
40   changed_when: false
41   tags: reset
42
43 - name: Delete existing installation of Istio
44   command: helm delete --purge "{{ item }}"
45   loop: "{{ installed_istio_charts.stdout_lines }}"
46   ignore_errors: true
47   changed_when: true
48   tags: reset
49
50 # This solves this bug: https://github.com/ansible/ansible/issues/47081 with the k8s module which is caused
51 # due to the presence of --- at the end of the yaml file.
52 - name: Fix upstream Istio CRDs
53   lineinfile:
54     path: "{{ item }}"
55     regex: '^-{3}\n+$'
56     line: ""
57     state: present
58     firstmatch: true
59   with_fileglob:
60     - "{{ istio_work_dir }}/istio-{{ istio_version }}/install/kubernetes/helm/istio-init/files/*"
61   ignore_errors: true
62   tags: reset
63
64 - name: Delete existing Istio CRDs
65   k8s:
66     api_version: apiextensions.k8s.io/v1beta1
67     kind: CustomResourceDefinition
68     state: absent
69     src: "{{ item }}"
70   with_fileglob:
71     - "{{ istio_work_dir }}/istio-{{ istio_version }}/install/kubernetes/helm/istio-init/files/*"
72   ignore_errors: true
73   tags: reset
74
75 - name: Delete Istio init namespace
76   k8s:
77     name: "{{ istio_init_namespace }}"
78     api_version: v1
79     kind: Namespace
80     state: absent
81   ignore_errors: true
82   tags: reset
83
84 # This can be avoided when we update Ansible to 2.8 version as is included in k8s module
85 - name: Verify Istio init namespace deletion
86   k8s_facts:
87     kind: Namespace
88     name: "{{ istio_init_namespace }}"
89   register: namespace_status
90   until: not namespace_status.resources
91   retries: 5
92   delay: 10
93   ignore_errors: true
94   tags: reset
95
96 - name: Delete Istio namespace
97   k8s:
98     name: "{{ istio_namespace }}"
99     api_version: v1
100     kind: Namespace
101     state: absent
102   ignore_errors: true
103   tags: reset
104
105 # This can be avoided when we update Ansible to 2.8 version as is included in k8s module
106 - name: Verify Istio init namespace deletion
107   k8s_facts:
108     kind: Namespace
109     name: "{{ istio_namespace }}"
110   register: namespace_status
111   until: not namespace_status.resources
112   retries: 5
113   delay: 10
114   ignore_errors: true
115   tags: reset
116
117 - name: Install and bootstrap Istio CRDs
118   command: >
119     helm install "{{ istio_work_dir }}"/istio-"{{ istio_version }}"/install/kubernetes/helm/istio-init
120       --name "{{ istio_init_release_name }}"
121       --namespace "{{ istio_init_namespace }}"
122   changed_when: true
123
124 - name: Verify the commitment of all Istio CRDs
125   k8s_facts:
126     kind: CustomResourceDefinition
127     api: apiextensions.k8s.io/v1beta1
128     label_selectors:
129       - release=istio
130   register: crd_status
131   until: crd_status.resources|length >= 23
132   retries: 5
133   delay: 10
134
135 - name: Install Istio configuration profile
136   command: >
137     helm install "{{ istio_work_dir }}"/istio-"{{ istio_version }}"/install/kubernetes/helm/istio
138       --name "{{ istio_release_name }}"
139       --namespace "{{ istio_namespace }}"
140   changed_when: true
141
142 - name: Verify Istio service existence
143   k8s_facts:
144     kind: Service
145     namespace: "{{ istio_namespace }}"
146     label_selectors:
147       - release=istio
148   register: istio_service_status
149   until: istio_service_status.resources is defined
150   retries: 5
151   delay: 10
152
153 - name: Wait until Istio pods are ready
154   k8s_facts:
155     kind: Pod
156     namespace: "{{ istio_namespace }}"
157     label_selectors:
158       - release=istio
159     field_selectors:
160       - status.phase=Running
161   register: istio_pod_status
162   until:
163     - istio_pod_status.resources is defined
164     - istio_pod_status.resources
165   retries: 5
166   delay: 10
167
168 - name: Add istioctl CLI bin to path
169   become: true
170   copy:
171     src: '{{ istio_work_dir }}/istio-{{ istio_version }}/bin/istioctl'
172     dest: '/usr/local/bin/istioctl'
173     remote_src: true
174     mode: '0755'
175
176 # vim: set ts=2 sw=2 expandtab: