Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 1 | --- |
| 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 Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 19 | |
| 20 | - name: Detect if archive is compressed |
| 21 | shell: > |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 22 | file "{{ resources_dir }}/{{ resource_source_filename }}" |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 23 | | grep "compressed" |
| 24 | register: compressed |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 25 | failed_when: compressed.rc > 1 |
| 26 | delegate_to: "{{ resources_source_host }}" |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 27 | |
| 28 | - name: Set tar extract options |
| 29 | set_fact: |
| 30 | tar_extract_options: "{{ '-xzf' if compressed.rc == 0 else '-xf' }}" |
| 31 | |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame^] | 32 | - name: "Unarchive resource {{ resources_dir }}/{{ resource_source_filename }} \ |
| 33 | to {{ resource_destination_directory }} dir on infrastructure servers over ssh" |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 34 | 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 Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 42 | always: |
| 43 | - name: Remove the ssh private key |
| 44 | file: |
| 45 | path: /root/.ssh/infra_to_resource.privkey |
| 46 | state: absent |