4

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

Tj Kellie
  • 6,336
  • 2
  • 31
  • 40
sfgroups
  • 18,151
  • 28
  • 132
  • 204

1 Answers1

6

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
Tj Kellie
  • 6,336
  • 2
  • 31
  • 40
  • 1
    Thanks for the code, it worked. why we need dest and creates arguments? – sfgroups Mar 12 '18 at 19:35
  • 1
    creates arg is optional, dest is the name of the archive to create, and src is of course the files to be zipped so those are required. I followed the same spec as the win_unzip module. – Tj Kellie Mar 12 '18 at 21:20
  • Thanks for this module, hope this will be included part of the core modules soon. – sfgroups Mar 13 '18 at 12:52