Created
December 14, 2023 19:49
-
-
Save NL647/24287ff5abe9ffa4ae946976d14a5f07 to your computer and use it in GitHub Desktop.
Ansible zip & send
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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