I am using Ansible for configuration management and the following task to clone a Git repo:
# Example git checkout from Ansible Playbooks
- git: repo=git://foosball.example.org/path/to/repo.git
dest=/srv/checkout
version=release-0.22
This clones the repo with the particular version.
Does it do a git pull
when run again if the repo already exists? Or does it simply clone the repo all the time? How to do a git pull
in Ansible if the repo already exists and how can we run a specific command if the repo exists and same if the repo is cloned for the first time?
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.
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:mypassword@bitbucket.org/company/myrepo.git master
i had to specify the remote url using user and password because it hangs with simple "git pull".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.