sfgroups
sfgroups

Reputation: 19109

Ansible create a zip file backup on windows host

I want to zip the windows directory into zip file. archive function is not working.

for windows I see win_unzip module, but I didn't find win_zip module.

How do we take the backup of existing folder in windows?

  - name: Backup existing install folder to zip 
    archive:
      path:
        - "{{ installdir }}"
      dest: "{{ stragedir }}\\{{ appname }}.zip"
      format: zip 

error:

 [WARNING]: FATAL ERROR DURING FILE TRANSFER: Traceback (most recent call last):   File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 276, in _winrm_exec
self._winrm_send_input(self.protocol, self.shell_id, command_id, data, eof=is_last)   File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 256, in
_winrm_send_input     protocol.send_message(xmltodict.unparse(rq))   File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 256, in send_message     raise
WinRMOperationTimeoutError() WinRMOperationTimeoutError

thanks SR

Upvotes: 4

Views: 6119

Answers (1)

Tj Kellie
Tj Kellie

Reputation: 6476

There is no module from ansible currently to do zip archiving on Windows. I've created a simple module that acts like win-unzip that I use, as long as powershell 4 is installed on the host this should work for you. The code is here: https://github.com/tjkellie/PublicRepo/blob/master/ansible feel free to use until an official module is created.

Add the files to your library:

library/                  # Put the custom modules files here
filter_plugins/           
roles/
       library/           # or here

And use the module from a playbook like this:

- name: zip a directory
  win_zip:
    src: C:\Users\Someuser\Logs
    dest: C:\Users\Someuser\OldLogs.zip
    creates: C:\Users\Someuser\OldLogs.zip

Upvotes: 6

Related Questions