Ansible create a zip file backup on windows host

笑着哭i 提交于 2019-12-11 04:36:53

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/49197468/ansible-create-a-zip-file-backup-on-windows-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!