Thursday, March 13, 2014

Puppet files and git.


If you have puppet files just sitting around on the server and random people changing manifests or uploading files without any type of coordination, that can lead to all kinds of issues. So let's go ahead and bring some order to it.

First, install git on the puppet server
sudo yum install git
Navigate to the directory where we have our puppet files.
cd /etc/puppet/

Initialize git there
git init

Add and commit all files
git add .
git commit -m "Initial commit"


Create bare repository to make it easier for people to clone new puppet repo
git clone --bare . ../puppet-repo.git

Add a pointer to your new bare repo using the origin name
git remote add origin ../puppet-repo.git/

Now open a command prompt on your local machine and execute following command to clone aka get puppet files on your machine. (Before that I created a directory to hold the data)
git clone user_name@host_name_or_ip:/location/of/puppet-repo.git

You will be asked if you want to connect, type 'yes' and provide your password. After which you can monitor the progress of your clone process... Might take a while depending on your network connection and data amount.

Now to avoid making all changes in the notepad, you can install Geppetto, which is A Puppet IDE and availabe as Eclipse plugin. The installation of Geppetto is quite straightforward. If you have an existing Eclipse, its easy to load up Geppetto within it:
•Help —> Install new Software
•Add —> Location = http://download.cloudsmith.com/geppetto/updates
•Select “Geppetto” from the list of potential downloads
•Finish
•Accept any Licenses
•Reload Eclipse

At the time of this writing, there is no option to import already existing Puppet project into Geppetto, so you have two options. Create and tweak .project file in your puppet project folder and then import existing project or you will need to import the project as a 'file system'. Geppetto will then create the xml file for you. I chose to import it as a file system...

Go ahead and play around with your modules and manifests...

Now that you made your changes go ahead and add them to the main repo.
Run git status to verify your changes, run git add . to stage them, and finally run git commit -a to commit. Now to add that to the main repo run git push

If you are getting an exception stating that "insufficient permission for adding an obkect to repository database", that means that you need to make further changes on the main server. Nothing big, just need to make sure that you have read/write set up right.
ssh to server
cd puppet-repo.git

sudo chmod -R g+ws *
sudo chgrp -R mygroup * ---> to find your group run: groups <username>

Try git push again. It should work.

Now that you successfully pushed your updates, go ahead and pull them on the server.

ssh to server
cd to the location of you puppet files and execute
git pull to get the updates.

You shall see the changes made...

This is a two way street. If you must make changes on the server, you can. You just need to commit and push it for others to see your changes.

Now this won't stop someone from modifying the files directly on the server and not committing them, but hey at least it is a start and you can remove the access of average user to this and force people to use git push to commit their changes.

No more Wild West!

No comments:

Post a Comment