1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.swp
pkg
spec/fixtures/
spec/fixtures/manifests/site.pp
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ env:
- PUPPET_VERSION="~> 3.2.0"
- PUPPET_VERSION="~> 3.3.0"
- PUPPET_VERSION="~> 3.4.0"
- PUPPET_VERSION="~> 3.5.1"
- PUPPET_VERSION="~> 3.6.0"
global:
- PUBLISHER_LOGIN=acidprime
matrix:
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ class { 'r10k':

This will configure `/etc/r10k.yaml` and install the r10k gem after installing
ruby using the [puppetlabs/ruby](http://forge.puppetlabs.com/puppetlabs/ruby) module. It also has a few helper classes that do
some useful things. The following will add a `prerun_command` to puppet.conf.
some useful things. The following entry in Hiera will add a `prerun_command` to puppet.conf.

```puppet
include r10k::prerun_command
```
r10k::include_prerun_command: true
```

The concept here is that this is declared on the puppet master(s) that have
been configured with r10k. This will cause r10k to synchronize before each
puppet run. Any errors synchronizing will be logged to the standard puppet run.

## symlink to r10k.yaml
These entries in Hiera will create a symlink at `/etc/r10k.yaml` that points to the config file at `/etc/puppet/r10k.yaml`

```
r10k::configfile: /etc/puppet/r10k.yaml
r10k::manage_configfile_symlink: true
r10k::configfile_symlink: /etc/r10k.yaml
```

### Mcollective Support

![alt tag](https://gist.github.com/acidprime/7013041/raw/6748f6173b406c03067884199174ce1df313ad58/post_recieve_overview.png)
Expand Down
78 changes: 50 additions & 28 deletions files/agent/r10k.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,35 @@ metadata :name => "r10k",
:url => "http://puppetlabs.com",
:timeout => 900

['push',
'pull',
'status'].each do |act|
action act, :description => "#{act.capitalize} " do
input :path,
:prompt => "Module path",
:description => "Operating on #{act}",
:type => :string,
:validation => '.',
:optional => false,
:maxlength => 256
['push',
'pull',
'status'].each do |act|
action act, :description => "#{act.capitalize} " do
input :path,
:prompt => "Module path",
:description => "Operating on #{act}",
:type => :string,
:validation => '.',
:optional => false,
:maxlength => 256

output :path,
:description => "Operating on #{act}",
:display_as => "Path"
output :output,
:description => "Output from git",
:display_as => "Output"
output :path,
:description => "Operating on #{act}",
:display_as => "Path"

output :error,
:description => "Error from git",
:display_as => "Errors"
display :always
end
output :output,
:description => "Output from git",
:display_as => "Output"

output :error,
:description => "Error from git",
:display_as => "Errors"
display :always
end
['cache',
'environment',
'module',
'synchronize',
'deploy_all',
'sync'].each do |act|
end
['cache',
'synchronize',
'sync'].each do |act|
action act, :description => "#{act.capitalize} " do
output :output,
:description => "Output from git",
Expand All @@ -48,4 +46,28 @@ metadata :name => "r10k",
display :always
end
end
action 'deploy', :description => "Deploy a specific environment, and its Puppetfile specified modules" do
input :environment,
:prompt => "Specific environment",
:description => "Deploy a particular environment",
:type => :string,
# Wanted to rubyize the following regex but didn't have time to test: ^(?!/|.*([/.]\.|//|@\{|\\\\))[^\040\177 ~^:?*\[]+(?<!\.lock|[/.])$
:validation => '.',
:optional => true,
:maxlength => 256

output :environment,
:description => "Deploy a particular environment",
:display_as => "Specific environment"

output :output,
:description => "Output from r10k",
:display_as => "Output"

output :error,
:description => "Error from r10k",
:display_as => "Errors"

display :always
end
# vim: set syntax=ruby:
67 changes: 36 additions & 31 deletions files/agent/r10k.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,51 @@ class R10k<RPC::Agent
['push',
'pull',
'status'].each do |act|
action act do
validate :path, :shellsafe
path = request[:path]
reply.fail "Path not found #{path}" unless File.exists?(path)
return unless reply.statuscode == 0
run_cmd act, path
reply[:path] = path
action act do
validate :path, :shellsafe
path = request[:path]
reply.fail "Path not found #{path}" unless File.exists?(path)
return unless reply.statuscode == 0
run_cmd act, path
reply[:path] = path
end
end
end
['cache',
'environment',
'module',
'synchronize',
'deploy_all',
'sync'].each do |act|
action act do
run_cmd act
'synchronize',
'deploy',
'sync'].each do |act|
action act do
if act == 'deploy'
validate :environment, :shellsafe
environment = request[:environment]
run_cmd act, environment
reply[:environment] = environment
else
run_cmd act
end
end
end
end
private

def run_cmd(action,path=nil)
def run_cmd(action,arg=nil)
output = ''
git = ['/usr/bin/env', 'git']
r10k = ['/usr/bin/env', 'r10k']
case action
when 'push','pull','status'
cmd = git
cmd << 'push' if action == 'push'
cmd << 'pull' if action == 'pull'
cmd << 'status' if action == 'status'
reply[:status] = run(cmd, :stderr => :error, :stdout => :output, :chomp => true, :cwd => path )
when 'cache','environment','module','synchronize','sync', 'deploy_all'
cmd = r10k
cmd << 'cache' if action == 'cache'
cmd << 'synchronize' if action == 'synchronize' or action == 'sync'
cmd << 'environment' if action == 'environment'
cmd << 'module' if action == 'module'
cmd << 'deploy' << 'environment' << '-p' if action == 'deploy_all'
reply[:status] = run(cmd, :stderr => :error, :stdout => :output, :chomp => true)
when 'push','pull','status'
cmd = git
cmd << 'push' if action == 'push'
cmd << 'pull' if action == 'pull'
cmd << 'status' if action == 'status'
reply[:status] = run(cmd, :stderr => :error, :stdout => :output, :chomp => true, :cwd => arg )
when 'cache','synchronize','sync', 'deploy'
cmd = r10k
cmd << 'cache' if action == 'cache'
cmd << 'deploy' << 'environment' << '-p' if action == 'synchronize' or action == 'sync'
if action == 'deploy'
cmd << 'deploy' << 'environment' << arg << '-p'
end
reply[:status] = run(cmd, :stderr => :error, :stdout => :output, :chomp => true)
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions files/application/r10k.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ def post_option_parser(configuration)
case configuration[:command]
when 'push','pull','status'
configuration[:path] = ARGV.shift || docs
when 'deploy'
configuration[:environment] = ARGV.shift || docs
end
else
docs
end
end

def docs
puts "Usage: #{$0} push | pull | status"
puts "Usage: #{$0} push | pull | status | deploy"
end

def main
mc = rpcclient("r10k", :chomp => true)
options = {:path => configuration[:path]} if ['push','pull','status'].include? configuration[:command]
options = {:environment => configuration[:environment]} if ['deploy'].include? configuration[:command]
mc.send(configuration[:command], options).each do |resp|
puts "#{resp[:sender]}:"
if resp[:statuscode] == 0
responses = resp[:data][:output]
puts responses if responses and ['push','pull','status'].include? configuration[:command]
puts responses if responses and ['push','pull','status','deploy'].include? configuration[:command]
else
puts resp[:statusmsg]
end
Expand Down
38 changes: 31 additions & 7 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# * [*purgedirs*]
# An Array of directory paths to purge of any subdirectories that do not
# correspond to a dynamic environment managed by r10k. Default: []
# * [*manage_configfile_symlink*]
# Boolean to determine if a symlink to the r10k config file is to be managed.
# Default: false
# * [*configfile_symlink*]
# Location of symlink that points to configfile. Default: /etc/r10k.yaml
#
# === Examples
#
Expand Down Expand Up @@ -45,16 +50,27 @@
$configfile,
$cachedir,
$manage_modulepath,
$modulepath = undef,
$remote = '',
$sources = 'UNSET',
$purgedirs = [],
$puppetconf_path = $r10k::params::puppetconf_path,
$r10k_basedir = $r10k::params::r10k_basedir,
$modulepath = undef,
$remote = '',
$sources = 'UNSET',
$purgedirs = [],
$puppetconf_path = $r10k::params::puppetconf_path,
$r10k_basedir = $r10k::params::r10k_basedir,
$manage_configfile_symlink = $r10k::params::manage_configfile_symlink,
$configfile_symlink = '/etc/r10k.yaml',
) inherits r10k::params {

validate_bool($manage_modulepath)

if type($manage_configfile_symlink) == 'string' {
$manage_configfile_symlink_real = str2bool($manage_configfile_symlink)
} else {
$manage_configfile_symlink_real = $manage_configfile_symlink
}
validate_bool($manage_configfile_symlink_real)

validate_absolute_path($configfile_symlink)

if $sources == 'UNSET' {
$r10k_sources = {
'puppet' => {
Expand All @@ -74,7 +90,15 @@
group => '0',
mode => '0644',
path => $configfile,
content => template("${module_name}/${configfile}.erb"),
content => template('r10k/r10k.yaml.erb'),
}

if $manage_configfile_symlink_real == true {
file { 'symlink_r10k.yaml':
ensure => 'link',
path => $configfile_symlink,
target => $configfile,
}
}

if $manage_modulepath {
Expand Down
60 changes: 38 additions & 22 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
# This class configures r10k
class r10k (
$remote = $r10k::params::remote,
$sources = $r10k::params::sources,
$purgedirs = $r10k::params::r10k_purgedirs,
$cachedir = $r10k::params::r10k_cache_dir,
$configfile = $r10k::params::r10k_config_file,
$version = $r10k::params::version,
$modulepath = $r10k::params::modulepath,
$manage_modulepath = $r10k::params::manage_modulepath,
$r10k_basedir = $r10k::params::r10k_basedir,
$package_name = $r10k::params::package_name,
$provider = $r10k::params::provider,
$gentoo_keywords = $r10k::params::gentoo_keywords,
$install_options = $r10k::params::install_options,
$mcollective = $r10k::params::mcollective,
$remote = $r10k::params::remote,
$sources = $r10k::params::sources,
$purgedirs = $r10k::params::r10k_purgedirs,
$cachedir = $r10k::params::r10k_cache_dir,
$configfile = $r10k::params::r10k_config_file,
$version = $r10k::params::version,
$modulepath = $r10k::params::modulepath,
$manage_modulepath = $r10k::params::manage_modulepath,
$r10k_basedir = $r10k::params::r10k_basedir,
$package_name = $r10k::params::package_name,
$provider = $r10k::params::provider,
$gentoo_keywords = $r10k::params::gentoo_keywords,
$install_options = $r10k::params::install_options,
$mcollective = $r10k::params::mcollective,
$manage_configfile_symlink = $r10k::params::manage_configfile_symlink,
$configfile_symlink = $r10k::params::configfile_symlink,
$include_prerun_command = false,
) inherits r10k::params {

if type($include_prerun_command) == 'string' {
$include_prerun_command_real = str2bool($include_prerun_command)
} else {
$include_prerun_command_real = $include_prerun_command
}
validate_bool($include_prerun_command_real)

if $include_prerun_command_real == true {
include r10k::prerun_command
}

class { 'r10k::install':
package_name => $package_name,
version => $version,
Expand All @@ -25,14 +39,16 @@
}

class { 'r10k::config':
cachedir => $cachedir,
configfile => $configfile,
sources => $sources,
purgedirs => $purgedirs,
modulepath => $modulepath,
remote => $remote,
manage_modulepath => $manage_modulepath,
r10k_basedir => $r10k_basedir,
cachedir => $cachedir,
configfile => $configfile,
sources => $sources,
purgedirs => $purgedirs,
modulepath => $modulepath,
remote => $remote,
manage_modulepath => $manage_modulepath,
r10k_basedir => $r10k_basedir,
manage_configfile_symlink => $manage_configfile_symlink,
configfile_symlink => $configfile_symlink,
}

if $mcollective {
Expand Down
Loading