Add Helm v3 plugin deployment playbook
[oom/offline-installer.git] / ansible / roles / application / tasks / install.yml
1 ---
2 - name: Helm init and upgrade
3   command: |
4      {{ helm_bin_dir }}/helm init
5      --upgrade
6      --skip-refresh
7   changed_when: true  # init is always changed type of action
8
9 # A correct way to implement this would be using --wait option in helm init invocation.
10 # However, it does not work due to https://github.com/helm/helm/issues/4031 (fixed in newer helm release)
11 - name: "Wait for helm upgrade to finish"
12   command: "{{ helm_bin_dir }}/helm version --tiller-connection-timeout 10"
13   register: result
14   until: result.rc == 0
15   delay: 10
16   retries: 12
17   changed_when: false  # for idempotency
18
19 - name: Get all helm repos
20   command: "{{ helm_bin_dir }}/helm repo list"
21   register: repos
22   changed_when: false  # for idempotency
23
24 - name: Remove stable repo
25   command: "{{ helm_bin_dir }}/helm repo remove stable"
26   changed_when: true  # when executed its a changed type of action
27   when: "'stable' in repos.stdout"
28
29 - name: Helm Serve
30   shell: "{{ helm_bin_dir }}/helm serve &"
31   async: 45
32   poll: 3  # wait 3sec to get a chance for some stderr
33   register: helm_serve
34   changed_when: "'address already in use' not in helm_serve.stderr"
35
36 - name: List helm repos
37   command: "{{ helm_bin_dir }}/helm repo list"
38   register: helm_repo_list
39   changed_when: false  # for idempotency
40   failed_when:
41     - helm_repo_list.rc > 0
42     - "'Error: no repositories to show' not in helm_repo_list.stderr"
43
44 - name: Helm Add Repo
45   command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name | mandatory }} {{ helm_repository_url | mandatory }}"
46   when: "'local' not in helm_repo_list.stdout"
47   changed_when: true  # when executed its a changed type of action
48
49 # Make utility is missing in Ubuntu by default and it's necessary for building local helm repository
50 - name: Install build-essential
51   package:
52     name: build-essential
53     state: present
54   when: ansible_os_family == "Debian"
55
56 - name: Build local helm repository
57   make:
58     chdir: "{{ app_helm_charts_infra_directory }}"
59     params:
60       SKIP_LINT: "TRUE"
61     target: "{{ item }}"
62   loop: "{{ app_helm_build_targets }}"
63   environment:
64     PATH: "{{ helm_bin_dir }}:{{ ansible_env.PATH }}"
65
66 - name: Generate Helm application override file with custom role
67   include_role:
68     name: "{{ app_helm_override_role }}"
69   when: not app_skip_helm_override
70
71 # The generated override file is added to override list unless skipped.
72 - name: Add application helm override file to list of overrides unless skipped
73   set_fact:
74     helm_override_files: "{{ (helm_override_files | default([])) + [app_helm_override_file] }}"
75   when: not app_skip_helm_override
76
77 - name: Print final list of override files
78   debug:
79     var: helm_override_files
80
81 - include_tasks: setup-helm2.yml
82   when: helm_version | regex_search("^v2" )
83 - include_tasks: setup-helm3.yml
84   when: helm_version | regex_search("^v3" )
85
86 - name: "Helm Install application {{ app_name }}"
87   command: >
88           {{ helm_bin_dir }}/helm
89           {{ 'deploy' if deploy_plugin_presence.stat.exists else 'install --name' }}
90           {{ app_helm_release_name }}
91           {{ helm_repository_name }}/{{ app_helm_chart_name }}
92           --namespace {{ app_kubernetes_namespace }}
93           {{ helm_override_files | map('regex_replace', '^', '-f ') | join(' ') }}
94           {{ helm_extra_install_options | map(attribute='opt') | join(' ') }}
95   changed_when: true  # when executed its a changed type of action
96   register: helm_install
97   failed_when: helm_install.stderr