diff --git a/roles/product_install/defaults/main.yml b/roles/product_install/defaults/main.yml index 211e76e..0741a94 100644 --- a/roles/product_install/defaults/main.yml +++ b/roles/product_install/defaults/main.yml @@ -22,6 +22,10 @@ atl_product_download_filename: "{{ atl_download_edition | default(atl_product_ed atl_product_download: "{{ atl_installer_temp }}/{{ atl_product_download_filename }}" atl_product_varfile: "{{ atl_installer_temp }}/{{ atl_product_family }}.varfile" +atl_product_home_shared_download_dir: "{{ atl_product_home_shared }}/downloads" +atl_product_home_shared_download: "{{ atl_product_home_shared_download_dir }}/{{ atl_product_download_filename }}" +atl_product_home_shared_download_lockdir: "{{ atl_product_home_shared_download }}_downloaded" + atl_marketplace_base: "https://marketplace.atlassian.com" atl_servicedesk_latest_url: "https://marketplace.atlassian.com/rest/2/products/key/jira-servicedesk/versions/latest" atl_servicedesk_versioned_url: "https://marketplace.atlassian.com/rest/2/products/key/jira-servicedesk/versions/name/{{ atl_product_version }}" diff --git a/roles/product_install/tasks/main.yml b/roles/product_install/tasks/main.yml index 77371fa..94cd6ba 100644 --- a/roles/product_install/tasks/main.yml +++ b/roles/product_install/tasks/main.yml @@ -116,6 +116,7 @@ - "{{ atl_product_home }}" - "{{ atl_product_installation_versioned }}" - "{{ atl_product_version_cache_dir }}" + - "{{ atl_product_home_shared_download_dir }}" changed_when: false # For Molecule idempotence check # At this point atl_product_version should be set, cache if necessary. @@ -125,17 +126,75 @@ dest: "{{ atl_product_version_cache }}" force: true +# For the first run a temp binary should be downloaded but moved to shared home to ensure all subsequent nodes have access +# to the same specific version binary. +# To prevent a race condition with multiple downloads at the same time a directory is used as a lockfile (atomic operation). -# Note: We don't the cache binary in the shared drive to the complexity -# around download race-conditions if multiple nodes are starting at -# the same time. When downloading from product-downloads.atlassian.com -# (which is a CDN) takes seconds anyway. -- name: Fetch product installer - get_url: - url: "{{ atl_product_download_url }}" - dest: "{{ atl_product_download }}" - mode: 0755 - force: false +- name: Assume temp binary should be downloaded + set_fact: + download_binary: yes + +# Check for product installer in home_shared and lockdir to determine if it needs to be downloaded again. +- name: Check download lock directory exists + stat: + path: "{{ atl_product_home_shared_download_lockdir }}" + register: download_lockdir + +- name: Check for presence of product installer in home_shared + stat: + path: "{{ atl_product_home_shared_download }}" + register: home_shared_downloaded + +# If binary exists and lockdir exists use this binary instead +- name: Check Lock Directory and binary exists on shared_home + set_fact: + download_binary: no + when: + - home_shared_downloaded.stat.exists + - download_lockdir.stat.isdir is defined + - download_lockdir.stat.isdir + +# If the binary was never installed, download it +- name: "Download product installer and move to shared directory" + block: + + - name: Fetch product installer + get_url: + url: "{{ atl_product_download_url }}" + dest: "{{ atl_product_download }}" + mode: 0755 + force: false + register: atl_product_downloaded + + - name: Remove lockdir to prevent nodes relying on binary when copying + file: + path: "{{ atl_product_home_shared_download_lockdir }}" + state: absent + when: atl_product_downloaded is succeeded + register: lockdir_removed + + - name: Copy temp installer to home_shared + copy: + src: "{{ atl_product_download }}" + dest: "{{ atl_product_home_shared_download }}" + remote_src: yes + when: lockdir_removed is succeeded + register: copied + + - name: Delete old temp installer + file: + path: "{{ atl_product_download }}" + state: absent + when: copied is succeeded + register: temp_deleted + + - name: Create lockdir once product installer downloaded and moved + file: + path: "{{ atl_product_home_shared_download_lockdir }}" + state: directory + when: temp_deleted is succeeded + + when: download_binary - name: Unpack the downloaded application depending on format include_tasks: "unpack_{{ atl_download_format }}.yml" diff --git a/roles/product_install/tasks/unpack_installer.yml b/roles/product_install/tasks/unpack_installer.yml index 925dca0..11d37e3 100644 --- a/roles/product_install/tasks/unpack_installer.yml +++ b/roles/product_install/tasks/unpack_installer.yml @@ -11,7 +11,7 @@ # will create 'jira1'; this potentially creates idempotency/upgrade # issues down the line. - name: Run the installer - command: /bin/sh "{{ atl_product_download }}" -q -varfile "{{ atl_product_varfile }}" + command: /bin/sh "{{ atl_product_home_shared_download }}" -q -varfile "{{ atl_product_varfile }}" args: creates: "{{ atl_product_installation_versioned }}/.install4j/" become: true