Using GIT to deploy scripts to production servers

If you find this free website useful – why don’t you support this with a donation? It is easy…. read more ….

This is how I use GIT to deploy script configurations to multiple servers.

In this instance I have fail2ban  configuration that I want to be able to deploy to multiple servers easily & quickly

I assume you are root – otherwise prefix commands with sudo as appropriate

I also assume that you have remote root ssh access ( by  private / public keys is best   of course )

Step 1  Install GIT if you don’t have it , e.g. on Debian

apt-get install git

The key is to set up a GIT directory on the remote server and use the hook to deploy to the correct directory

cd /var
mkdir repo
mkdir f2ban.git && cd f2ban.git
git init --bare

We make a bare repo – the convention is a bare repo directory ends in git

Now we move to the hooks directory

cd hooks

And we need to create a file called post-receive that will process the files on being pushed here

The file needs to contain ( use vim or similar )

git --work-tree=/etc/fail2ban --git-dir=/var/repo/f2ban.git checkout -f

Basically saying when files come here – put them into the fail2ban directory

And post-receive need to be executable i.e.

chmod +x post-receive

On the localmachine in your git directory you need to add the remote server

git remote add myservername ssh://root@myprodserver/var/repo/f2ban.git

And after normal git adding & committing you can push to your server e.g.

git push myservername master

You can repeat this with different servers or different /var/repo/xxx.gits as rerequired









, , ,




Leave a Reply

Your email address will not be published. Required fields are marked *