Do no send .git directory with git module

197 views
Skip to first unread message

Renan Aguiar

unread,
Jun 9, 2014, 5:31:41 PM6/9/14
to ansible...@googlegroups.com
i'm new to ansible and I'm doing a simple test deployment.
Everything works fine. My problem is related to git module deploying the .git directory to server. I don't want this.
My playbook is simple

---
- hosts: rffa
  remote_user: rffa
  tasks:
    - name: git deploy ansible test
      git: repo=g...@bitbucket.org:rffaguiar/capistrano-test.git
           dest=/var/www/lab.rffaguiar.com/public_html

I just have an index.html for tests and other files that were ignored by .gitignore.
However the entire .git folder is deployed to 'rffa' hosts.
Do git module have some argument to prevent this? 
I know I can delete the .git folder after deploy task. But can I do this before/during deploy?

Nathan Howell

unread,
Jun 10, 2014, 1:50:34 PM6/10/14
to ansible...@googlegroups.com
I don't think the git module can do anything about this, but you can separate the .git and working tree by setting an environment variable like GIT_DIR or GIT_WORK_TREE.

Nathan

ra...@future500.nl

unread,
Jun 11, 2014, 4:00:44 AM6/11/14
to ansible...@googlegroups.com
The git module does't do this by default, but I take a different approach. First use the git module to update your project on the server in a separate folder, and then copy the files (excluding the .git folder) to the actual path you want to deploy to. It makes for faster deploys, as you're only updating your repo instead of doing a full clone.

Alternatively, if you only want your project files to be sent to the server, you can use the "synchronize" module which uses rsync (and you can exclude the .git folder from rsync by using a .rsync-filter file, see the module's documentation http://docs.ansible.com/synchronize_module.html).

We've implemented both strategies in a galaxy role called "project_deploy" that mimics Capistrano-like deploys, and is configurable to do (or not do) additional things like creating symlink for a shared folder and do composer installs (composer is a PHP package manager - other package managers will be supported).


--
Ramon de la Fuente

Luis Borbon

unread,
Jul 15, 2016, 7:59:19 PM7/15/16
to Ansible Project
Hi Renan,

As Nathan mentioned, setting the environment variable solved the issue for me.

    - name: git deploy ansible test
      git: repo=g...@bitbucket.org:rffaguiar/capistrano-test.git dest=/var/www/lab.rffaguiar.com/public_html
      environment:
        GIT_DIR: /var/www/lab.rffaguiar.com/.git
Reply all
Reply to author
Forward
0 new messages