Just enough GiT for Puppet Automation – Part5

All Posts in this Series

 

Creating a master Git repo

We’re going to make a copy of our existing Puppet repo, which we can then clone on a new machine.

1. Create a directory to hold the repo:

igurkul@demo:~/puppet$ sudo mkdir /var/git

2. Clone the repo, using the –bare flag:

igurkul@demo:~/puppet$ cd /var/git
igurkul@demo:/var/git$ sudo git clone –bare /home/ubuntu/puppet
Cloning into bare repository ‘puppet.git’…
done.

3. Now create a git user that will own the master repo and control access to it:

igurkul@demo:/var/git$ sudo useradd -d /var/git git
igurkul@demo:/var/git$ sudo chown -R git:git /var/git

4. Just to verify that these steps have worked, check out a temporary clone of the master repo:

igurkul@demo:/tmp$ cd /tmp
igurkul@demo:/tmp$ git clone /var/git/puppet.git
Cloning into ‘puppet’…
done.
igurkul@demo:/tmp$ ls puppet
manifests modules
igurkul@demo:/tmp$ rm -r puppet

5. Now create a secure shell (SSH) keypair for the git user so that it can log in from remote machines to clone and update the Git repo. When prompted for a passphrase, just hit Enter.

igurkul@demo:/tmp$ sudo su – git
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/git/.ssh/id_rsa):
Created directory ‘/var/git/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/git/.ssh/id_rsa.
Your public key has been saved in /var/git/.ssh/id_rsa.pub.
The key fingerprint is:
87:12:a4:3d:e3:da:79:01:19:d1:0b:1c:15:f8:7c:93 igurkul@demo
The key’s randomart image is:
+–[ RSA 2048]—-+
| .=*o. |
| ++o. |
| . B+ . . |
| . =+.E |
| o S… |
| o o o |
| . o . |
| . |
| |
+—————–+
The fingerprint and image will be different for your key, but that’s fine.

6. Create an authorized_keys file for git containing the public key you just generated:

igurkul@demo:~$ cd .ssh
igurkul@demo:~/.ssh$ ls
igurkul@demo:~/.ssh$ cp id_rsa.pub authorized_keys

7. You should now be able to log into the git account via SSH using this key:

igurkul@demo:~/.ssh$ ssh git@localhost
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-29-virtual x86_64)

You now have a master Git repo containing your manifests, and an SSH key that you can use to check out the repo on other machines.

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us

What is your Learning Goal for Next Six Months ? Talk to us