Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Sync script to sync a copy of a GIT branch to your puppet master.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Merge pull request #8 from uphillian/master

adding -q (--quiet) option for use in scripts
latest commit 5f22f69527
Spencer Krum nibalizer authored
Octocat-spinner-32 extra Renaming executable puppet-sync -> puppetsync December 15, 2011
Octocat-spinner-32 README.textile Update README.textile January 14, 2014
Octocat-spinner-32 post-receive Fix spelling error in example post-receive filename January 23, 2013
Octocat-spinner-32 puppet-sync adding -q (--quiet) option for use in scripts March 28, 2014
README.textile

Puppet Sync

This project provides a script to synchronize your manifests from a GIT
repository to your Puppet master.

Usage

Usage: puppet-sync -b BRANCH [options]
    -b, --branch BRANCH              Mandatory, specify the git branch to clone.
    -d, --deploy DIR                 Specify the directory to deploy to.
    -e, --environment DIR            Specify the name of the environment to deploy to, defaults to the branch.
    -D, --delete                     Remove the specified branch from the deployment directory.
    -r, --repository URL             Git url for the repository.
    -s SUBMODULES                    Comma-seperated list of submodule paths to enable.
        --submodules-enabled
Common options:
    -V, --version                    Display the script version.
    -v, --verbose                    Be more verbose.
    -h, --help                       Show this message

To sync a specific branch, to specific location, from a specific repository run the
script with the following arguments:

  puppet-sync --branch master \
              --deploy /etc/puppet/environments \
              --repository ssh+git://git/puppet.git

Git Hook

I usually call this script from a GIT hook. If your GIT repository is located
on a different server as your Puppet master, you will need to ensure that
a certain user can login to your Puppet server, without manual interactions.
I use the “puppet” user for this purpose.

  # change to the user and generate a key
  sudo -u puppet ssh-keygen -t rsa -b 4096 -f ~puppet/.ssh/id_rsa

  # copy the public key file to your puppetmaster server (where you have already
  # created the puppet user)
  ssh server 'cat - >> ~puppet/.ssh/authorized_keys' < ~puppet/.ssh/id_rsa.pub

Now you need to add the following to the Git hook file:

  #!/bin/sh
  # File: /git/puppet.git/hooks/post-receive

  REPO="git@githost.cat.pdx.edu:puppet.git"
  DEPLOY="/etc/puppet/environments"
  SSH_ARGS="-i /path/to/privatekey"
  PUPPETMASTER="puppet@puppetmaster.cat.pdx.edu"
  SYNC_COMMAND="/usr/local/bin/puppet-sync"

  while read oldrev newrev refname
  do
    BRANCH=`echo $refname | sed -n 's/^refs\/heads\///p'`
    [ "$newrev" -eq 0 ] 2> /dev/null && DELETE='--delete' || DELETE=''

    ssh $SSH_ARGS "$PUPPETMASTER" "$SYNC_COMMAND" \
      --branch "$BRANCH" \
      --repository "$REPO" \
      --deploy "$DEPLOY" \
      $DELETE

  done
Something went wrong with that request. Please try again.