Skip to content

Instantly share code, notes, and snippets.

@NL647
Created December 14, 2023 19:49
Show Gist options
  • Save NL647/24287ff5abe9ffa4ae946976d14a5f07 to your computer and use it in GitHub Desktop.
Save NL647/24287ff5abe9ffa4ae946976d14a5f07 to your computer and use it in GitHub Desktop.
Ansible zip & send
---
- name: Zip and transfer files from Windows servers to Linux server
hosts: windows
gather_facts: no
tasks:
- name: Zip contents of folders A and B
win_shell: |
$zipFile = "$env:COMPUTERNAME.zip"
Compress-Archive -Path C:\path\to\folderA, C:\path\to\folderB -DestinationPath C:\path\to\temp\$zipFile
args:
creates: C:\path\to\temp\{{ ansible_hostname }}.zip
- name: Fetch zipped file from Windows server
win_fetch:
src: C:\path\to\temp\{{ ansible_hostname }}.zip
dest: /local/path/to/store/files/
flat: yes
delegate_to: localhost
- name: Transfer files to Linux server
hosts: linux
gather_facts: no
vars:
ansible_user: linuxuser
ansible_ssh_pass: linuxpass
ansible_become: yes
ansible_become_method: sudo
tasks:
- name: Transfer files to Linux server
copy:
src: /local/path/to/store/files/{{ hostvars[item].ansible_hostname }}.zip
dest: /backup/
loop: "{{ groups['windows'] }}"
delegate_to: localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment