Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull while deployment in ansible

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?

like image 938
Ajeet Khan Avatar asked Nov 10 '15 08:11

Ajeet Khan


People also ask

How hard is it to deploy an ansible application?

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.

What is pull architecture in Ansible?

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.

How to get remote logs from Ansible-pull?

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.

How do I install code from a GitHub repository on Ansible?

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.


1 Answers

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.

like image 168
ydaetskcoR Avatar answered Oct 28 '22 19:10

ydaetskcoR