blob: 1385ba55392eca9356e85f0fb2b99785ec626b95 [file] [log] [blame]
Samuli Silvius29886f02019-02-19 16:00:37 +02001---
2#
3# Expected variables
4# resources_source_host
5# resources_dir
6# resource_source_filename
7# resource_destination_directory
8# Output is upload_failed true/false
9#
10- name: "Upload resource {{ resources_dir }}/{{ resource_source_filename }} to infrastructure servers over ssh"
11 block:
12 - name: Upload ssh private key
13 copy:
14 src: "{{ ansible_ssh_private_key_file }}"
15 dest: /root/.ssh/infra_to_resource.privkey
16 mode: 0600
17 owner: root
18 group: root
Samuli Silvius29886f02019-02-19 16:00:37 +020019
20 - name: Detect if archive is compressed
21 shell: >
Milan Verespejad41e6d2019-03-01 14:49:25 +010022 file "{{ resources_dir }}/{{ resource_source_filename }}"
Samuli Silvius29886f02019-02-19 16:00:37 +020023 | grep "compressed"
24 register: compressed
Milan Verespejad41e6d2019-03-01 14:49:25 +010025 failed_when: compressed.rc > 1
26 delegate_to: "{{ resources_source_host }}"
Samuli Silvius29886f02019-02-19 16:00:37 +020027
28 - name: Set tar extract options
29 set_fact:
30 tar_extract_options: "{{ '-xzf' if compressed.rc == 0 else '-xf' }}"
31
32 - name: "Unarchive resource {{ resources_dir }}/{{ resource_source_filename }} to {{ resource_destination_directory }} dir on infrastructure servers over ssh"
33 shell: >
34 ssh -o StrictHostKeyChecking=no -o BatchMode=yes
35 -i /root/.ssh/infra_to_resource.privkey
36 {{ resources_source_host }}
37 'cat "{{ resources_dir }}/{{ resource_source_filename }}"'
38 | tar -C "{{ resource_destination_directory }}" "{{ tar_extract_options }}" -
39 args:
40 warn: false
Samuli Silvius29886f02019-02-19 16:00:37 +020041 always:
42 - name: Remove the ssh private key
43 file:
44 path: /root/.ssh/infra_to_resource.privkey
45 state: absent