blob: 8e04d5c0fb68bf14360f0c182b3ad93a00ddc09b [file] [log] [blame]
Michal Ptacekf5907202018-12-19 11:54:34 +00001---
2- name: Upload resources to infrastructure servers over ssh
3 block:
4 - name: Upload ssh private key
5 copy:
6 src: "{{ ansible_ssh_private_key_file }}"
7 dest: /root/.ssh/infra_to_resource.privkey
8 mode: 0600
9 owner: root
10 group: root
11 remote_src: no
12
13 - name: Unarchive resources
14 shell: >
15 ssh -o StrictHostKeyChecking=no -o BatchMode=yes
16 -i /root/.ssh/infra_to_resource.privkey
17 {{ hostvars[groups.resources.0].ansible_host }}
18 'cat "{{ hostvars[groups.resources.0].resources_dir }}/{{ hostvars[groups.resources.0].resources_filename }}"'
19 | tar -C "{{ app_data_path }}" -xf -
20 args:
21 warn: False
22 when: not resources_data_check.stat.exists
23
24 - name: Unarchive auxiliary resources
25 shell: >
26 ssh -i /root/.ssh/infra_to_resource.privkey
27 {{ hostvars[groups.resources.0].ansible_host }}
28 'cat "{{ hostvars[groups.resources.0].resources_dir }}/{{ hostvars[groups.resources.0].aux_resources_filename }}"'
29 | tar -C "{{ aux_data_path }}" -xf -
30 when: >
31 hostvars[groups.resources.0].aux_resources_filename is defined
32 and aux_data_path is defined and aux_data_path is not none
33 and hostvars[groups.resources.0].aux_file_presence.stat.exists
34 and not aux_resources_data_check.stat.exists
35 args:
36 warn: False
37
38 rescue:
39 - name: Removing the resources data due to an error - so the next run can try again
40 command: /bin/false
41 register: upload_failed
42
43 always:
44 - name: Remove the ssh private key
45 file:
46 path: /root/.ssh/infra_to_resource.privkey
47 state: absent
48
49 - name: Remove the resource data on error
50 file:
51 path: "{{ app_data_path }}"
52 state: absent
53 when: upload_failed is defined
54
55 - name: Remove the auxilliary resource data on error
56 file:
57 path: "{{ aux_data_path }}"
58 state: absent
59 when: upload_failed is defined