Giter VIP home page Giter VIP logo

pgsvr's Introduction

pgsvr - Puppet Git Sync via REST

Version: 0.0.8

Ventz Petkov [email protected]

PLEASE NOTE

  • This is still a BETA - it works well, but it is FAR from complete.
  • To use this "as is", it requires an r10k for git based environments: (https://github.com/acidprime/r10k)
  • You can change one line and make it to work with just git or any other framework or custom written deploy/sync script.

Short Summary

PGSVR lets you configure a post-receive hook with your git server/github/any other system, that signals over REST so that an r10k run can happen.

It's a simply a fancy way to have a "git push" become "instant files" on your puppet server.

When you have r10k (highly recommended), you also get dynamic environments for free - so that each git branch becomes a puppet environment. You also get the other features that r10k provides, like deploying modules from github/puppet forge by just specifying a line in Puppetfile.

Don't have r10k? Not sure what it is, don't have time, or don't want to bother with it? No problem! By changing one line, you can have your "git push" simply end up mirroring a repo (syncing it) and then cloning it out into your puppet directory.

The goal of this is to provide you with a framework to translate a REST call to a "something" on your puppet server.

Quick Setup and PGSVR Components

This is rather simple. Don't let the length of this readme scare you!

  • You need r10k - "dynamic puppet environments" tied into Git.

This can be obtained with one command:

puppet module install zack/r10k
  • You need to deploy for your dynamic environments.

Create a "deploy_r10k" module with an init.pp which contains:

class { 'r10k':
    remote => '[email protected]:someuser/puppet.git',
}

And apply your module:

puppet apply deploy_r10k/manifests/init.pp

Please make sure that you DO NOT add the "include r10k::prerun_command" bit. The whole point of PGSVR is to do this intelligently and only as needed.

  • Set a shell for your puppet user.

This is needed so that we can execute a "sudo" call for an r10k run:

chsh -s /bin/bash puppet
  • Edit your sudo-ers file (visudo)

For Ubuntu:

Defaults env_keep = "http_proxy https_proxy"
www-data    ALL= NOPASSWD: * /usr/local/bin/r10k

For RHEL/Centos:

Defaults env_keep = "http_proxy https_proxy"
apache2    ALL= NOPASSWD: * /usr/local/bin/r10k
  • You need 2 perl modules (Dancer and Plack)

  • An Apache server with a virtual config (I provide the site config - look through it)

  • A cgi-root (I create it under /var/www/pgsvr with the apache config) to drop the app itself. Make sure it's owned by your web user.

  • Create some "tokens" and configure the proxy variables. A token is a unique string basically.

  • That's it! Now skip down to the "How to Test it" section.

To get it working (detailed version), you need to:

  • Have a "dynamic git puppet environment" You commit to git, and it picks up the branch and then creates the appropriate puppet environment

Something like this in /etc/puppet/puppet.conf on the master:

environment = master
manifest    = $confdir/environments/$environment/manifests/site.pp
modulepath  = $confdir/modules:$confdir/environments/$environment/modules:$confdir/environments/$environment/dist:$confdir/environments/$environment/site

This can be obtained with one command:

puppet module install zack/r10k
  • You need to deploy for your dynamic environments.

Create a "deploy_r10k" module with an init.pp which contains:

class { 'r10k':
    remote => '[email protected]:someuser/puppet.git',
}

And apply your module:

puppet apply deploy_r10k/manifests/init.pp

Please make sure that you DO NOT add the "include r10k::prerun_command" bit. The whole point of PGSVR is to do this intelligently and only as needed.

  • Set a shell for your puppet user.

Use bash for example:

chsh -s /bin/bash puppet
  • Edit your sudo-ers file (visudo)

For Ubuntu:

Defaults env_keep = "http_proxy https_proxy"
www-data    ALL= NOPASSWD: * /usr/local/bin/r10k

For RHEL/Centos:

Defaults env_keep = "http_proxy https_proxy"
apache2    ALL= NOPASSWD: * /usr/local/bin/r10k
  • /etc/puppet/environments need to be owned by 'puppet' and group by apache (www-data on ubuntu)

  • Take the 'pgsvr' repo and grab the 'pgsvr' apache config, and enable it as a virtual host.

  • Take 'pgsvr' folder (inside the 'app' folder) and drop it in /var/www, and make sure everything is owned by your web user.

  • You will need to install 2 Perl modules:

    • Dancer (ubuntu: libdancer-perl) -> REST framework in Perl
    • Plack (ubuntu: libplack-perl) -> Interface for Perl webapp to interface with Apache/other web servers
  • Go into the /var/www/pgsvr/bin/app.pl and create yourself an 'user and token' (see line about MD5 part). In reality, ANYTHING can be used as a token. It's just used for a super rudimentary way of "authenticating".

  • If you use a proxy, please enter it in the apache virtual config file. The variables are passed through sudo to the app.

How to Test it:

Where $user is the 'user' you created

  • Now check if /etc/puppet/environments filled up -- that is, assuming you have checked in a git repo ;)

Background - What is this/How did it come about?

If you are using puppet with git (github or your own server/repo), you have realized really quickly that there are two 'hacky' ways to do it: keep the git server/repo on the puppet server or glue some magic in via SSH from the git server to the puppet server

####Partial Solution: Use r10k. You push your code to your git server, and the r10k module on on your puppet master grabs it every X minutes (20 by default, but you can configure cron down to 1).

Still, that's NOT good enough! Can you imagine having to tell people to wait a whole minute!

####Solution: PGSVR You set it up on your puppet server, and you configure github (or any git server) to have a post-receive hook that simply signals your puppet server. This will initialize a r10k run (or anything else). Simple huh? Yep - simple but effective.

TODO:

  • Create a rest call to read a file of users/tokens
  • Create a config file for the http(s)-proxy variables
  • Create real authentication, and add to config

pgsvr's People

Contributors

ventz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tfhartmann

pgsvr's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.