# git checkout and remote rsync

**URL:** <https://forum.ansible.com/t/git-checkout-and-remote-rsync/15873>\
**Category:** Ansible Project\
**Created:** [August 6, 2014, 5:27pm UTC](https://forum.ansible.com/t/git-checkout-and-remote-rsync/15873 "2014-08-06T17:27:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quentin\_Stafford-Fra](https://avatars.discourse-cdn.com/v4/letter/q/b2d939/32.png) [@Quentin\_Stafford-Fra](https://forum.ansible.com/u/Quentin_Stafford-Fra)\
**Post date:** [August 6, 2014, 5:27pm UTC](https://forum.ansible.com/t/git-checkout-and-remote-rsync/15873/1 "2014-08-06T17:27:16Z")

</div>

Hi there -

A common deployment model I’m using is to checkout a git repo on the target machine and then copy the subdirectory(s) I actually want into position (e.g. under /var/www somewhere) using a remote rsync command.

There may be a better way to do this, but here’s how I run rsync so that it shows up correctly in the ‘changed’ statistics, just in case it’s useful for others.

- name: copy repo to live directory  
command: rsync -rlpEtv -i --delete  
–out-format=‘[changed] %f’  
{{repo\_root}}/my\_key\_subdirectory/  
{{app\_root\_dir}}/  
register: rsync\_result  
changed\_when: “'[changed] ’ in rsync\_result.stdout”

rsync tends to output various statistics even if nothing needs to be copied, so I tell it to use an easily-recognisable output format, where it will print:

[changed] filename1

etc in the output for any files affected. Then I just look for instances of ‘[changed]’ in stdout.

Suggestions for more elegant ways to get a subset of a git archive efficiently are most welcome!

Quentin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 7, 2014, 9:17pm UTC](https://forum.ansible.com/t/git-checkout-and-remote-rsync/15873/2 "2014-08-07T21:17:42Z")

</div>

I’m not entirely following this, but have you read the docs for the synchronize module yet? This wraps rsync and makes it easier than composing the rsync CLI command.
