How to pull while deployment in ansible

This works for me using a shell command:

- hosts: myserver
  become: yes
  tasks:
  - name: pull changes
    shell: chdir=/path/whereis/myrepo git pull https://mygituser:[email protected]/company/myrepo.git master

i had to specify the remote url using user and password because it hangs with simple "git pull".


Ansible is a declarative tool in which you describe how you want your server/environment to look and Ansible attempts to make that happen. It is also designed to be idempotent which means that re-running your plays should reproduce the same end result each time as long as nothing underneath has changed.

The git module also ascribes to this and simply tries to make sure that the remote host has the repo on it and to the version (or branch/tag) that you optionally asked for.

So when you run the git task in your question on a fresh environment it will clone the repo to the destination folder. On future runs, the repo is already there so it simply does a git pull.

If you specify a tag/branch/commit ref to the update property then it will simply check that version out and pull that.