# Ansible sunchronize module.

**URL:** <https://forum.ansible.com/t/ansible-sunchronize-module/22252>\
**Category:** Ansible Project\
**Tags:** fedora\
**Created:** [August 9, 2016, 9:48pm UTC](https://forum.ansible.com/t/ansible-sunchronize-module/22252 "2016-08-09T21:48:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amrit\_Bhandari](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Amrit\_Bhandari](https://forum.ansible.com/u/Amrit_Bhandari)\
**Post date:** [August 9, 2016, 9:48pm UTC](https://forum.ansible.com/t/ansible-sunchronize-module/22252/1 "2016-08-09T21:48:28Z")

</div>

Hello everyone,  
I am using Ansible 2.1.0.0 in a FEDORA environment.I have a playbook which is supposed to run a Python script.The Python script generates directories and subdirectories in /tmp/data/ of the remote machines.What need to do now is : 1)tar the directory in the remote machines and 2) move them to the controlling machines. I have come across the synchronize module and it says compress is ‘yes’ by default.However even when I try compress=yes, I don’t get a zip or a tar file.Getting a tar file would be ideal for me.So, now I have been trying the following way.Here;s my playbook:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 10, 2016, 12:49pm UTC](https://forum.ansible.com/t/ansible-sunchronize-module/22252/2 "2016-08-10T12:49:32Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I am using Ansible 2.1.0.0 in a FEDORA environment.I have a  
> playbook which is supposed to run a Python script.The Python script  
> generates directories and subdirectories in /tmp/data/ of the remote  
> machines.What need to do now is : 1)tar the directory in the remote  
> machines and 2) move them to the controlling machines. I have come across  
> the synchronize module and it says compress is 'yes' by default.However  
> even when I try compress=yes, I don't get a zip or a tar file.Getting a tar  
> file would be ideal for me.So, now I have been trying the following

Synchronize is a wrapper around Rsync, Rsync doesn't make zip or tar files. Compress just indicate the data is compressed before transmitted so potential less data has to go over the wire, the data is automatically uncompress before saved to the file system.

> way.Here;s my playbook:
> 
> ---  
> - hosts: all
> 
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: Execute the script  
> &nbsp;&nbsp;&nbsp;&nbsp;script: /usr10/bhandara/Desktop/RunPy.sh  
> &nbsp;&nbsp;&nbsp;&nbsp;register: result  
> &nbsp;&nbsp;&nbsp;&nbsp;until: result.stdout.find("Exiting simulations exploration.")!=-1  
> &nbsp;&nbsp;&nbsp;&nbsp;retries: 3  
> &nbsp;&nbsp;&nbsp;&nbsp;delay: 10
> 
> &nbsp;&nbsp;- name: Compress files in the data directory  
> &nbsp;&nbsp;&nbsp;&nbsp;shell: tar -cvzf data\_directory\*.tgz -P /tmp/data/

This is not valid tar usage, you need to sort this out, "man tar" maybe.

> &nbsp;&nbsp;- name: fetch the tar file  
> &nbsp;&nbsp;&nbsp;&nbsp;fetch:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /tmp/data/data\_directory\*.tgz  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: ~/Desktop/backup/

src take file or directory, it doesn't support wildcards/regexp to my knowledge.

> However, I have problems with converting the directory into tar in the  
> files inside /tmp in remote machines.I get a warning saying" Try using  
> unarchive .Also, the fetch task failes with a message, the remote task  
> fails, not transferring, ignored.

Find the correct tar command for taring the directory first. And the rest should be easy to figure out.
