Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 1 | --- |
| 2 | - name: Helm init and upgrade |
| 3 | command: | |
| 4 | {{ helm_bin_dir }}/helm init |
| 5 | --upgrade |
| 6 | --skip-refresh |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 7 | changed_when: true # init is always changed type of action |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 8 | |
Michal Ptacek | 11e2af5 | 2018-12-19 19:42:03 +0000 | [diff] [blame] | 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 |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 17 | changed_when: false # for idempotency |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 18 | |
| 19 | - name: Get all helm repos |
| 20 | command: "{{ helm_bin_dir }}/helm repo list" |
| 21 | register: repos |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 22 | changed_when: false # for idempotency |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 23 | |
| 24 | - name: Remove stable repo |
| 25 | command: "{{ helm_bin_dir }}/helm repo remove stable" |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 26 | changed_when: true # when executed its a changed type of action |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 27 | when: "'stable' in repos.stdout" |
| 28 | |
| 29 | - name: Helm Serve |
| 30 | shell: "{{ helm_bin_dir }}/helm serve &" |
| 31 | async: 45 |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 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" |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 43 | |
| 44 | - name: Helm Add Repo |
| 45 | command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name }} {{ helm_repository_url }}" |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 46 | when: "'local' not in helm_repo_list.stdout" |
| 47 | changed_when: true # when executed its a changed type of action |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 48 | |
Michal Ptacek | 271cf3f | 2019-01-17 20:39:46 +0000 | [diff] [blame] | 49 | - name: Build local helm repository |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 50 | make: |
Michal Ptacek | 11e2af5 | 2018-12-19 19:42:03 +0000 | [diff] [blame] | 51 | chdir: "{{ app_helm_charts_infra_directory }}" |
Michal Ptacek | 271cf3f | 2019-01-17 20:39:46 +0000 | [diff] [blame] | 52 | target: "{{ item }}" |
| 53 | with_items: "{{ app_helm_build_targets }}" |
Michal Ptacek | 11e2af5 | 2018-12-19 19:42:03 +0000 | [diff] [blame] | 54 | environment: |
| 55 | PATH: "{{ helm_bin_dir }}:{{ ansible_env.PATH }}" |
Tomas Levora | 5ea00a9 | 2018-12-19 14:36:36 +0100 | [diff] [blame] | 56 | |
Michal Ptacek | 997057f | 2019-02-01 08:37:05 +0000 | [diff] [blame] | 57 | - name: Register root certificate |
| 58 | slurp: |
Samuli Silvius | e9fca5e | 2019-03-03 13:34:16 +0200 | [diff] [blame] | 59 | src: "{{ playbook_dir }}/certs/rootCA.crt" |
Michal Ptacek | 997057f | 2019-02-01 08:37:05 +0000 | [diff] [blame] | 60 | register: root_cert |
| 61 | delegate_to: localhost |
| 62 | |
| 63 | # WA: this is required because deploy plugin dont process params properly |
| 64 | - name: Create override file with global.cacert |
| 65 | copy: |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 66 | dest: "{{ app_data_path }}/override.yaml" |
Michal Ptacek | 997057f | 2019-02-01 08:37:05 +0000 | [diff] [blame] | 67 | content: | |
| 68 | global: |
Michal Ptacek | 04f2ca6 | 2019-02-15 12:58:57 +0000 | [diff] [blame] | 69 | cacert: | |
Michal Ptacek | 997057f | 2019-02-01 08:37:05 +0000 | [diff] [blame] | 70 | {{ root_cert['content'] | b64decode | indent( width=4, indentfirst=False) }} |
| 71 | |
Michal Ptacek | fabcad6 | 2019-02-04 06:38:08 +0000 | [diff] [blame] | 72 | - name: Check for deploy plugin presence |
| 73 | stat: |
Milan Verespej | 5f5aa01 | 2019-02-08 15:30:39 +0100 | [diff] [blame] | 74 | path: '{{ helm_home_dir.stdout }}/plugins/deploy/deploy.sh' |
Michal Ptacek | fabcad6 | 2019-02-04 06:38:08 +0000 | [diff] [blame] | 75 | register: deploy_plugin_presence |
| 76 | |
| 77 | - name: "Helm Install application {{ app_name }}" |
| 78 | command: > |
| 79 | {{ helm_bin_dir }}/helm |
| 80 | {{ 'deploy' if deploy_plugin_presence.stat.exists else 'install --name' }} |
| 81 | {{ app_helm_release_name }} |
| 82 | {{ helm_repository_name }}/{{ app_helm_chart_name }} |
| 83 | --namespace {{ app_kubernetes_namespace }} |
Michal Ptacek | 997057f | 2019-02-01 08:37:05 +0000 | [diff] [blame] | 84 | -f {{ app_data_path }}/override.yaml |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 85 | changed_when: true # when executed its a changed type of action |
Milan Verespej | a2e3a4c | 2019-03-29 12:50:40 +0100 | [diff] [blame] | 86 | register: helm_install |
| 87 | failed_when: helm_install.stderr |