blob: bc7df37fccb4827ad22f33836b359b41312e57d3 [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
Michal Ptacek173ad8e2019-02-14 07:47:59 +000032 and hostvars[groups.resources.0].aux_resources_filename is not none
Michal Ptacekf5907202018-12-19 11:54:34 +000033 and aux_data_path is defined and aux_data_path is not none
34 and hostvars[groups.resources.0].aux_file_presence.stat.exists
35 and not aux_resources_data_check.stat.exists
36 args:
37 warn: False
38
39 rescue:
40 - name: Removing the resources data due to an error - so the next run can try again
41 command: /bin/false
42 register: upload_failed
43
44 always:
45 - name: Remove the ssh private key
46 file:
47 path: /root/.ssh/infra_to_resource.privkey
48 state: absent
49
50 - name: Remove the resource data on error
51 file:
52 path: "{{ app_data_path }}"
53 state: absent
54 when: upload_failed is defined
55
56 - name: Remove the auxilliary resource data on error
57 file:
58 path: "{{ aux_data_path }}"
59 state: absent
60 when: upload_failed is defined