summaryrefslogtreecommitdiffstats
path: root/ansible/roles/application/tasks/install.yml
blob: 9e27e2de264cda0b683232ecb5370f94f2231fee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
- name: Helm init and upgrade
  command: |
     {{ helm_bin_dir }}/helm init
     --upgrade
     --skip-refresh
  changed_when: true  # init is always changed type of action

# A correct way to implement this would be using --wait option in helm init invocation.
# However, it does not work due to https://github.com/helm/helm/issues/4031 (fixed in newer helm release)
- name: "Wait for helm upgrade to finish"
  command: "{{ helm_bin_dir }}/helm version --tiller-connection-timeout 10"
  register: result
  until: result.rc == 0
  delay: 10
  retries: 12
  changed_when: false  # for idempotency

- name: Get all helm repos
  command: "{{ helm_bin_dir }}/helm repo list"
  register: repos
  changed_when: false  # for idempotency

- name: Remove stable repo
  command: "{{ helm_bin_dir }}/helm repo remove stable"
  changed_when: true  # when executed its a changed type of action
  when: "'stable' in repos.stdout"

- name: Helm Serve
  shell: "{{ helm_bin_dir }}/helm serve &"
  async: 45
  poll: 3  # wait 3sec to get a chance for some stderr
  register: helm_serve
  changed_when: "'address already in use' not in helm_serve.stderr"

- name: List helm repos
  command: "{{ helm_bin_dir }}/helm repo list"
  register: helm_repo_list
  changed_when: false  # for idempotency
  failed_when:
    - helm_repo_list.rc > 0
    - "'Error: no repositories to show' not in helm_repo_list.stderr"

- name: Helm Add Repo
  command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name | mandatory }} {{ helm_repository_url | mandatory }}"
  when: "'local' not in helm_repo_list.stdout"
  changed_when: true  # when executed its a changed type of action

# Make utility is missing in Ubuntu by default and it's necessary for building local helm repository
- name: Install build-essential
  package:
    name: build-essential
    state: present
  when: ansible_os_family == "Debian"

- name: Build local helm repository
  make:
    chdir: "{{ app_helm_charts_infra_directory }}"
    params:
      SKIP_LINT: "TRUE"
    target: "{{ item }}"
  loop: "{{ app_helm_build_targets }}"
  environment:
    PATH: "{{ helm_bin_dir }}:{{ ansible_env.PATH }}"

- name: Generate Helm application override file with custom role
  include_role:
    name: "{{ app_helm_override_role }}"
  when: not app_skip_helm_override

# The generated override file is added to override list unless skipped.
- name: Add application helm override file to list of overrides unless skipped
  set_fact:
    helm_override_files: "{{ (helm_override_files | default([])) + [app_helm_override_file] }}"
  when: not app_skip_helm_override

- name: Print final list of override files
  debug:
    var: helm_override_files

- include_tasks: setup-helm2.yml
  when: helm_version | regex_search("^v2" )
- include_tasks: setup-helm3.yml
  when: helm_version | regex_search("^v3" )

- name: "Helm Install application {{ app_name }}"
  command: >
          {{ helm_bin_dir }}/helm
          {{ 'deploy' if deploy_plugin_presence.stat.exists else 'install --name' }}
          {{ app_helm_release_name }}
          {{ helm_repository_name }}/{{ app_helm_chart_name }}
          --namespace {{ app_kubernetes_namespace }}
          {{ helm_override_files | map('regex_replace', '^', '-f ') | join(' ') }}
          {{ helm_extra_install_options | map(attribute='opt') | join(' ') }}
  changed_when: true  # when executed its a changed type of action
  register: helm_install
  failed_when: helm_install.stderr