Michal Ptacek | f590720 | 2018-12-19 11:54:34 +0000 | [diff] [blame] | 1 | --- |
| 2 | - name: Upload resources to infrastructure servers over nfs |
| 3 | block: |
| 4 | - name: Mount resources |
| 5 | mount: |
| 6 | path: /tmp/resource_data |
| 7 | src: "{{ hostvars[groups.resources.0].ansible_host }}:{{ hostvars[groups.resources.0].resources_dir }}" |
| 8 | fstype: nfs |
| 9 | state: mounted |
| 10 | |
| 11 | - name: Unarchive resources |
| 12 | unarchive: |
| 13 | src: "/tmp/resource_data/{{ hostvars[groups.resources.0].resources_filename }}" |
| 14 | remote_src: yes |
| 15 | dest: "{{ app_data_path }}" |
| 16 | when: not resources_data_check.stat.exists |
| 17 | |
| 18 | - name: Unarchive auxiliary resources |
| 19 | unarchive: |
| 20 | src: "/tmp/resource_data/{{ hostvars[groups.resources.0].aux_resources_filename }}" |
| 21 | remote_src: yes |
| 22 | dest: "{{ aux_data_path }}" |
| 23 | when: > |
| 24 | hostvars[groups.resources.0].aux_resources_filename is defined |
| 25 | and aux_data_path is defined and aux_data_path is not none |
| 26 | and hostvars[groups.resources.0].aux_file_presence.stat.exists |
| 27 | and not aux_resources_data_check.stat.exists |
| 28 | |
| 29 | rescue: |
| 30 | - name: Removing the resources data due to an error - so the next run can try again |
| 31 | command: /bin/false |
| 32 | register: upload_failed |
| 33 | |
| 34 | always: |
| 35 | - name: unmount resource dir |
| 36 | mount: |
| 37 | path: /tmp/resource_data |
| 38 | src: "{{ hostvars[groups.resources.0].ansible_host }}:{{hostvars[groups.resources.0].resources_dir }}" |
| 39 | fstype: nfs |
| 40 | state: absent |
| 41 | |
| 42 | - name: Remove the resource data on error |
| 43 | file: |
| 44 | path: "{{ app_data_path }}" |
| 45 | state: absent |
| 46 | when: upload_failed is defined |
| 47 | |
| 48 | - name: Remove the auxilliary resource data on error |
| 49 | file: |
| 50 | path: "{{ aux_data_path }}" |
| 51 | state: absent |
| 52 | when: upload_failed is defined |