From e6c1765a4abeccbd572e5ca08b5742ce3856cac3 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Thu, 25 Nov 2021 11:51:26 +0100 Subject: [ANSIBLE] Drop Helm v2 specific code from application role Change-Id: I270594786b2ec3b63b5c6cd313278bb271db44b1 Issue-ID: OOM-2883 Signed-off-by: Bartek Grzybowski --- ansible/roles/application/defaults/main.yml | 2 +- .../application/tasks/install-helm-plugins.yml | 33 ++++++++++++++ .../application/tasks/install-helm2-plugins.yml | 25 ----------- .../application/tasks/install-helm3-plugins.yml | 33 -------------- ansible/roles/application/tasks/install.yml | 5 +-- ansible/roles/application/tasks/setup-helm.yml | 18 ++++++++ ansible/roles/application/tasks/setup-helm2.yml | 52 ---------------------- ansible/roles/application/tasks/setup-helm3.yml | 18 -------- .../application/tasks/transfer-helm-charts.yml | 5 +-- 9 files changed, 54 insertions(+), 137 deletions(-) create mode 100644 ansible/roles/application/tasks/install-helm-plugins.yml delete mode 100644 ansible/roles/application/tasks/install-helm2-plugins.yml delete mode 100644 ansible/roles/application/tasks/install-helm3-plugins.yml create mode 100644 ansible/roles/application/tasks/setup-helm.yml delete mode 100644 ansible/roles/application/tasks/setup-helm2.yml delete mode 100644 ansible/roles/application/tasks/setup-helm3.yml (limited to 'ansible') diff --git a/ansible/roles/application/defaults/main.yml b/ansible/roles/application/defaults/main.yml index 8e630f73..1c4437ed 100644 --- a/ansible/roles/application/defaults/main.yml +++ b/ansible/roles/application/defaults/main.yml @@ -2,7 +2,7 @@ helm_repository_name: local helm_repository_url: http://127.0.0.1:8879 helm_extra_install_options: - - { opt: "{% if helm_version | regex_search('^v3' ) %}{{ '--timeout 1800s' }}{% else %}{{ '--timeout 1800' }}{% endif %}"} + - { opt: '--timeout 1800s'} # Override file generation for Helm application can be customized by any role # given by user and found by ansible from roles_path. # By default override file is generated by 'application-override' role that diff --git a/ansible/roles/application/tasks/install-helm-plugins.yml b/ansible/roles/application/tasks/install-helm-plugins.yml new file mode 100644 index 00000000..5d933ed2 --- /dev/null +++ b/ansible/roles/application/tasks/install-helm-plugins.yml @@ -0,0 +1,33 @@ +--- +- name: Install helm plugins if needed + block: + - name: Get helm environment information + command: "{{ helm_bin_dir }}/helm env" + register: helm_env + - name: Set helm data dir + set_fact: + helm_data_dir: + "{% if 'HELM_DATA_HOME' in helm_env.stdout -%} + {{ (helm_env.stdout | replace('\"', '') | regex_search('HELM_DATA_HOME.*')).split('=')[1] }} + {%- else -%} + {{ '~/.local/share/helm' }} + {%- endif %}" + - name: Ensure that dir for helm plugins exists + file: + path: "{{ helm_data_dir }}/plugins" + state: directory + mode: 0755 + - name: Register all plugins to be inserted by dir names + find: + paths: "{{ app_helm_plugins_directory }}" + file_type: "directory" + register: list_of_plugins + delegate_to: localhost + - name: Install all helm plugins from {{ app_helm_plugins_directory }} dir + copy: + src: "{{ item.path }}" + dest: "{{ helm_data_dir }}/plugins" + directory_mode: true + mode: 0755 + loop: "{{ list_of_plugins.files }}" + when: app_helm_plugins_directory is defined and app_helm_plugins_directory is not none diff --git a/ansible/roles/application/tasks/install-helm2-plugins.yml b/ansible/roles/application/tasks/install-helm2-plugins.yml deleted file mode 100644 index f1f900e3..00000000 --- a/ansible/roles/application/tasks/install-helm2-plugins.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- name: Install helm plugins if needed - block: - - name: Get helm dir - command: "{{ helm_bin_dir }}/helm home" - register: helm_home_dir - - name: Ensure that dir for helm plugins exists - file: - path: "{{ helm_home_dir.stdout }}/plugins" - state: directory - mode: 0755 - - name: Register all plugins to be inserted by dir names - find: - paths: "{{ app_helm_plugins_directory }}" - file_type: "directory" - register: list_of_plugins - delegate_to: localhost - - name: Install all helm plugins from {{ app_helm_plugins_directory }} dir - copy: - src: "{{ item.path }}" - dest: "{{ helm_home_dir.stdout }}/plugins" - directory_mode: true - mode: 0755 - loop: "{{ list_of_plugins.files }}" - when: app_helm_plugins_directory is defined and app_helm_plugins_directory is not none diff --git a/ansible/roles/application/tasks/install-helm3-plugins.yml b/ansible/roles/application/tasks/install-helm3-plugins.yml deleted file mode 100644 index 5d933ed2..00000000 --- a/ansible/roles/application/tasks/install-helm3-plugins.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -- name: Install helm plugins if needed - block: - - name: Get helm environment information - command: "{{ helm_bin_dir }}/helm env" - register: helm_env - - name: Set helm data dir - set_fact: - helm_data_dir: - "{% if 'HELM_DATA_HOME' in helm_env.stdout -%} - {{ (helm_env.stdout | replace('\"', '') | regex_search('HELM_DATA_HOME.*')).split('=')[1] }} - {%- else -%} - {{ '~/.local/share/helm' }} - {%- endif %}" - - name: Ensure that dir for helm plugins exists - file: - path: "{{ helm_data_dir }}/plugins" - state: directory - mode: 0755 - - name: Register all plugins to be inserted by dir names - find: - paths: "{{ app_helm_plugins_directory }}" - file_type: "directory" - register: list_of_plugins - delegate_to: localhost - - name: Install all helm plugins from {{ app_helm_plugins_directory }} dir - copy: - src: "{{ item.path }}" - dest: "{{ helm_data_dir }}/plugins" - directory_mode: true - mode: 0755 - loop: "{{ list_of_plugins.files }}" - when: app_helm_plugins_directory is defined and app_helm_plugins_directory is not none diff --git a/ansible/roles/application/tasks/install.yml b/ansible/roles/application/tasks/install.yml index 2db88631..6cd22d05 100644 --- a/ansible/roles/application/tasks/install.yml +++ b/ansible/roles/application/tasks/install.yml @@ -6,10 +6,7 @@ state: present when: ansible_os_family == "Debian" -- include_tasks: setup-helm2.yml - when: helm_version | regex_search("^v2" ) -- include_tasks: setup-helm3.yml - when: helm_version | regex_search("^v3" ) +- include_tasks: setup-helm.yml - name: Build local helm repository make: diff --git a/ansible/roles/application/tasks/setup-helm.yml b/ansible/roles/application/tasks/setup-helm.yml new file mode 100644 index 00000000..4b50ec1c --- /dev/null +++ b/ansible/roles/application/tasks/setup-helm.yml @@ -0,0 +1,18 @@ +--- +- 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 + +- name: Check for deploy plugin presence + stat: + path: '{{ helm_data_dir }}/plugins/deploy/deploy.sh' + register: deploy_plugin_presence diff --git a/ansible/roles/application/tasks/setup-helm2.yml b/ansible/roles/application/tasks/setup-helm2.yml deleted file mode 100644 index 8479e1a1..00000000 --- a/ansible/roles/application/tasks/setup-helm2.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- 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 - -- name: Check for deploy plugin presence - stat: - path: '{{ helm_home_dir.stdout }}/plugins/deploy/deploy.sh' - register: deploy_plugin_presence diff --git a/ansible/roles/application/tasks/setup-helm3.yml b/ansible/roles/application/tasks/setup-helm3.yml deleted file mode 100644 index 4b50ec1c..00000000 --- a/ansible/roles/application/tasks/setup-helm3.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- 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 - -- name: Check for deploy plugin presence - stat: - path: '{{ helm_data_dir }}/plugins/deploy/deploy.sh' - register: deploy_plugin_presence diff --git a/ansible/roles/application/tasks/transfer-helm-charts.yml b/ansible/roles/application/tasks/transfer-helm-charts.yml index 2101a5ab..9b36cffe 100644 --- a/ansible/roles/application/tasks/transfer-helm-charts.yml +++ b/ansible/roles/application/tasks/transfer-helm-charts.yml @@ -20,7 +20,4 @@ src: "{{ app_helm_charts_install_directory }}.tgz" dest: "{{ app_helm_charts_infra_directory }}" -- include_tasks: install-helm2-plugins.yml - when: helm_version | regex_search("^v2" ) -- include_tasks: install-helm3-plugins.yml - when: helm_version | regex_search("^v3" ) +- include_tasks: install-helm-plugins.yml -- cgit 1.2.3-korg