blob: bd578ae33c2ba9609d9897d871ae960c2d599b83 [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
Michal Ptacek200ae722019-03-21 12:32:20 +000032 - name: "Unarchive resource {{ resources_dir }}/{{ resource_source_filename }} \
33 to {{ resource_destination_directory }} dir on infrastructure servers over ssh"
Samuli Silvius29886f02019-02-19 16:00:37 +020034 shell: >
35 ssh -o StrictHostKeyChecking=no -o BatchMode=yes
36 -i /root/.ssh/infra_to_resource.privkey
37 {{ resources_source_host }}
38 'cat "{{ resources_dir }}/{{ resource_source_filename }}"'
39 | tar -C "{{ resource_destination_directory }}" "{{ tar_extract_options }}" -
40 args:
41 warn: false
Samuli Silvius29886f02019-02-19 16:00:37 +020042 always:
43 - name: Remove the ssh private key
44 file:
45 path: /root/.ssh/infra_to_resource.privkey
46 state: absent