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?
DEPLOYING APPS SHOULDN'T BE SO HARD. Ansible is the simplest way to deploy your applications. It gives you the power to deploy multi-tier applications reliably and consistently, all from one common framework. You can configure needed services as well as push application artifacts from one common system.
Used to pull a remote copy of ansible on each managed node, each set to run via cron and update playbook source via a source repository. This inverts the default push architecture of ansible into a pull architecture, which has near-limitless scaling potential.
The setup playbook can be tuned to change the cron frequency, logging locations, and parameters to ansible-pull. This is useful both for extreme scale-out as well as periodic remediation. Usage of the ‘fetch’ module to retrieve logs from ansible-pull runs would be an excellent way to gather and analyze remote logs from ansible-pull.
For example, if you wanted to install code from a GitHub repository every morning at a certain time, to make sure your development environment was up to date with the latest code, you could create a cronjob on your host that runs the ansible-pull command to download the latest master branch or development branch and install it on our server.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With