Git Repository Management
Using git to manage puppet modules
Git has become a very popular version control system in recent years. We can use git to version control our module and will be the input to our development pipeline. Initially, git may seem rather easy and trivial; however, it can quickly get complicated.
We will begin by turning our local module into a local git repository. Most distributions already have git installed, but Ubuntu does not. To install git on Ubuntu run the following command:
$ apt-get install git
Once git is installed, create the local repository in the root of the module directory structure:
$ git init
Create a gitignore file so that we don’t track unnecessary files and directories.
$ vim .gitignore
Add the following contents to the file:
Finally, update the local git repository with our first commit
$ git add . $ git commit -m “initial commit”
You can look at the git with the git log command:
$ git log
This shows you our initial commit
Subscribe to our youtube channel to get new updates..!
Having a local git repository is nice and allows version control, but we more than likely will work in a team and will need something a little more enterprise level. You could use a central git repository using the standard git command line or you could use one of several web based git servers like GitLab or GitHub Enterprise if you are interested in deploying to your local environment. If you are just interested in testing your puppet code automatically then GitHub.com and several other alternatives can be used.
Here, let us use a locally installed GitLab Server since we are interested in deploying to our environment automatically using continuous integration automation.
Login to your GitLab server and create a new repository by clicking on Create Project. Then fill out the form like the following:
Finally, click on Create project.
Enable access to GIT REPOSITORY
Access to your new GitLab repository can occur in several ways. We will use SSH keys to make the process smooth. Run the following command to generate an SSH key on your development system.
$ ssh-keygen -t rsa
This will generate a key ~/.ssh/id_rsa
Show the contents of this file and copy the key to your clipboard.
$ cat ~/.ssh/id_rsa.pub
Paste this key into GitLab by clicking your username in the lower-left corner then clicking on Profile settings. Then on the left click on SSH keys and the Add SSH key button. Paste the key into the Key field. Click Title field and it should automatically populate. If it doesn’t, then simply put in any title you want to represent this key, like your development system’s hostname. Finally, click on Add key.
Upload module to git
Go to the top of the repository page and get the SSH URL for the repository. This will look like the picture below:
Back on your development system, run the following command to add the remote repository to your local repository:
$ git remote add origin
You can now push your local repository to the origin remote repository which is our GitLab server.
$ git push origin master
You will see git push the repository to GitHub.
You will now see your module contents listed in your GitLab Project repository. We have the input to our workflow. Changes to this repository will kick off our continuous integration server which will perform the tests we created automatically and deploy our module to our puppet master.
Configure the WebHook for Jenkins
Go to the project settings page, then click on WebHooks and add a new webhook like below: