6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.2.0 - Multiple Authors
* Support for TFS/Visual Studio Git #259
* Lowercase Environment names #256
* Obsure Software version #253
* Fix Postrun command spaces #252
* Tagged Release events #251
3.1.1 - Corey Osman & Nate McCurdy
* r10k_path fact throwing error on agents
3.1.0 - Mickaël Canévet & Ben Ford
Expand Down
61 changes: 47 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
[![Build Status](https://travis-ci.org/acidprime/r10k.png?branch=master)](https://travis-ci.org/acidprime/r10k)
[![Github Tag](https://img.shields.io/github/tag/acidprime/r10k.svg)](https://github.com/acidprime/r10k)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/acidprime/r10k?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/zack/r10k.svg)](https://forge.puppetlabs.com/zack/r10k)
[![Puppet Forge Endorsement](https://img.shields.io/puppetforge/e/zack/r10k.svg)](https://forge.puppetlabs.com/zack/r10k)


#### Table of Contents

Expand Down Expand Up @@ -56,10 +59,10 @@ class { 'r10k':

* Installation of the r10k `gem`
* Installation of git
* Installation of ruby when not using an existing ruby stack i.e. when using `pe_gem` or `puppet_gem`
* Installation of ruby when not using an existing ruby stack i.e. when using `pe_gem` or `puppet_gem`
* Installation of ruby if not using an existing ruby stack i.e. when using `pe_gem` or `puppet_gem`.
* Management of the `r10k.yaml` in /etc
* Instllation and configuration of a sinatra app when using the [webhook](#webhook-support).
* Installation and configuration of a sinatra app when using the [webhook](#webhook-support).


#### Version chart
Expand Down Expand Up @@ -246,11 +249,13 @@ For version control systems that use web driven post-receive processes you can u
This webhook currently only runs on Puppet Enterprise and uses mcollective to automatically synchronize your environment across multiple masters.
The webhook must be configured on the respective "control" repository a master that has mco installed and can contact the other masters in your fleet.

### Webhook Github Enterprise - Non Authenticated
### Webhook Github Enterprise - Non Authenticated
This is an example of using the webhook without authentication.
The `git_webhook` type will use the [api token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) to add the webhook to the "control" repo that contains your puppetfile. This is typically useful when you want to automate the addtion of the webhook to the repo.

```puppet
# Required unless you disable mcollective
include r10k::mcollective
# Internal webhooks often don't need authentication and ssl
# Change the url below if this is changed
class {'r10k::webhook::config':
Expand Down Expand Up @@ -290,13 +295,17 @@ git_webhook { 'web_post_receive_webhook_for_module' :
}
```

### Webhook Github Example - Authenticated
### Webhook Github Example - Authenticated
This is an example of using the webhook with authentication
The `git_webhook` type will use the [api token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) to add the webhook to the "control" repo that contains your puppetfile. This is typically useful when you want to automate the addtion of the webhook to the repo.

```puppet
# Required unless you disable mcollective
include r10k::mcollective
# External webhooks often need authentication and ssl and authentication
# Change the url below if this is changed
class {'r10k::webhook::config':
enable_ssl => true,
protected => true,
Expand Down Expand Up @@ -329,7 +338,7 @@ git_webhook { 'web_post_receive_webhook' :
# All characters with left and including any hyphen are removed i.e. <puppet->
git_webhook { 'web_post_receive_webhook_for_module' :
ensure => present,
webhook_url => 'https://puppet:puppet@hole.in.firewall:8088/module',
webhook_url => 'https://puppet:puppet@hole.in.firewall:8088/module',
token => hiera('github_api_token'),
project_name => 'organization/puppet-module_name',
server_url => 'https://api.github.com',
Expand Down Expand Up @@ -381,6 +390,9 @@ file {'/usr/local/bin/prefix_command.rb':
source => 'puppet:///modules/r10k/prefix_command.rb',
}
# Required unless you disable mcollective
include r10k::mcollective
class {'r10k::webhook::config':
prefix => true,
prefix_command => '/usr/local/bin/prefix_command.rb',
Expand Down Expand Up @@ -439,22 +451,22 @@ A string to be passed in as the source with a hardcode prefix of `puppet`
A hash of all sources, this gets read out into the file as yaml. Must not be declared with `remote`

##### `cachedir`
A single string setting the `r10k.yaml` configuration value of the same name
A single string setting the `r10k.yaml` configuration value of the same name

##### `configfile`
A path to the configuration file to manage. Be aware Puppet Enterprise 4.0 and higher may conflict if you manage `/etc/puppetlabs/puppet/r10k.yaml`

##### `version`
A value passed to the package resource for managing the gem version
A value passed to the package resource for managing the gem version

##### `modulepath`
Deprecated: for older [configfile](https://docs.puppetlabs.com/puppet/latest/reference/environments_classic.html) environments configuration of modulepath in puppet.conf
Deprecated: for older [configfile](https://docs.puppetlabs.com/puppet/latest/reference/environments_classic.html) environments configuration of modulepath in puppet.conf

##### `manage_modulepath`
Deprecated: declare a resource for managing `modulepath` in Puppet.conf
Deprecated: declare a resource for managing `modulepath` in Puppet.conf

##### `manage_ruby_dependency`
When using system ruby , options on how to declare
When using system ruby , options on how to declare

##### `r10k_basedir`
This module requires the [puppetlabs-ruby](https://github.com/puppetlabs/puppetlabs-ruby.git) module. In the event that your environment already includes
Expand All @@ -472,7 +484,7 @@ is outlined below:

* *ignore* This will assume that ruby is handled via some other mechanism than
a puppet module named `ruby`. It is left to the user to insure the
requirement be met.
requirement be met.
##### `package_name`
The name of the package to be installed via the provider

Expand All @@ -494,7 +506,7 @@ See `r10k::install::portage` class for more information
Options to pass to the `provider` declaration

##### `mcollective`
Install mcollective application and agents. This does NOT configure mcollective automatically
Install mcollective application and agents. This does NOT configure mcollective automatically

##### `manage_configfile_symlink`
Manage a symlink to the configuration file, for systems installed in weird file system configurations
Expand All @@ -515,6 +527,21 @@ rugged support.
}
```

##### `forge_settings`
This is the `forge:` key in r10k, it accepts a hash that contains settings for downloading modules from the Puppet Forge.

```puppet
$forge_settings = {
'proxy' => 'https://proxy.example.com:3128',
'baseurl' => 'https://forgeapi.puppetlabs.com',
}
class {'r10k':
remote => 'git@github.com:acidprime/puppet.git',
forge_settings => $forge_settings,
}
```

##### `configfile_symlink`
boolean if to manage symlink

Expand Down Expand Up @@ -561,7 +588,7 @@ Quickstart:
gem install bundler
bundle install
bundle exec rake spec
bundle exec rake lint
bundle exec rake lint
```

####Ruby = 1.8.7
Expand All @@ -570,7 +597,13 @@ Quickstart:
gem install bundler
bundle install --without system_tests
bundle exec rake spec
bundle exec rake lint
bundle exec rake lint
```

Check the .travis.yml for supported Operating System Versions

[Puppetconf](http://puppetconf.com) beer fund for all those that submit pull
requests:


[![Support via Gratipay](https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.svg)](https://gratipay.com/acidprime/)
14 changes: 11 additions & 3 deletions files/prefix_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
json_data = JSON.parse(STDIN.read)
url = json_data['repository']['url']

prefix = prefixes[:sources].each.map do |key,value|
key if url == value['remote']
end.compact
prefix = ""

prefixes[:sources].each do |key,value|
if url == value['remote'] then
if value['prefix'] == true
prefix = key
elsif value['prefix'].is_a? String
prefix = value['prefix']
end
end
end

puts prefix
end
14 changes: 13 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
# Hash containing data sources to be used by r10k to create dynamic Puppet
# environments. Default: {}
# * [*postrun*]
# **Optional:** Array containing the parts of a system call.
# **Optional:** Array containing the parts of a system call.
# Example: ['/usr/bin/curl', '-F', 'deploy=done', 'http://my-app.site/endpoint']
# Default: undef
# * [*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
# * [*forge_settings*]
# Hash containing settings for downloading modules from the Puppet Forge.
#
# === Examples
#
Expand Down Expand Up @@ -57,6 +59,7 @@
$configfile_symlink = '/etc/r10k.yaml',
$r10k_yaml_template = 'r10k/r10k.yaml.erb',
$git_settings = {},
$forge_settings = {},
) inherits r10k::params {

validate_bool($manage_modulepath)
Expand Down Expand Up @@ -89,6 +92,15 @@
validate_array($postrun)
}

if $configfile == '/etc/puppetlabs/r10k/r10k.yaml' {
file {'/etc/puppetlabs/r10k':
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0755',
}
}

file { 'r10k.yaml':
ensure => file,
owner => 'root',
Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$manage_configfile_symlink = $r10k::params::manage_configfile_symlink,
$configfile_symlink = $r10k::params::configfile_symlink,
$git_settings = $r10k::params::git_settings,
$forge_settings = $r10k::params::forge_settings,
$postrun = undef,
$include_prerun_command = false,
$include_postrun_command = false,
Expand All @@ -34,7 +35,7 @@

$ruby_dependency_options=['include','declare','ignore']
validate_re($manage_ruby_dependency,$ruby_dependency_options)
validate_hash($git_settings)
validate_hash($git_settings, $forge_settings)

# TODO: Clean this up when 4.0 to require a boolean
if $include_prerun_command == true or $include_prerun_command == 'true'{
Expand Down Expand Up @@ -68,6 +69,7 @@
manage_configfile_symlink => $manage_configfile_symlink,
configfile_symlink => $configfile_symlink,
git_settings => $git_settings,
forge_settings => $forge_settings,
postrun => $postrun,
}

Expand Down
6 changes: 5 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$manage_configfile_symlink = false
$configfile_symlink = '/etc/r10k.yaml'
$git_settings = {}
$forge_settings = {}
# Git configuration
$git_server = $::settings::ca_server
$repo_path = '/var/repos'
Expand All @@ -41,13 +42,16 @@
$webhook_client_timeout = 120
$webhook_prefix = false # ':repo' | ':user' | ':command' (or true for backwards compatibility) | 'string' | false
$webhook_prefix_command = '/bin/echo example'
$webhook_server_software = 'WebHook'
$webhook_enable_ssl = true
$webhook_use_mcollective = true
$webhook_r10k_deploy_arguments = '-pv'
$webhook_bin_template = 'r10k/webhook.bin.erb'
$webhook_yaml_template = 'r10k/webhook.yaml.erb'
$webhook_r10k_command_prefix = 'umask 0022;' # 'sudo' is the canonical example for this
$webhook_repository_events = undef
$webhook_enable_mutex_lock = false
$webhook_allow_uppercase = true # for backwards compatibility. Default to off on a major semver update.

if $::osfamily == 'Debian' {
$functions_path = '/lib/lsb/init-functions'
Expand Down Expand Up @@ -132,7 +136,7 @@

# Mcollective configuration dynamic
$mc_service_name = 'mcollective'
$plugins_dir = '/opt/puppetlabs/mcollective/plugins'
$plugins_dir = '/opt/puppetlabs/mcollective/plugins/mcollective'
$modulepath = undef
$provider = 'puppet_gem'
$r10k_binary = 'r10k'
Expand Down
6 changes: 6 additions & 0 deletions manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$client_timeout = $r10k::params::webhook_client_timeout,
$prefix = $r10k::params::webhook_prefix,
$prefix_command = $r10k::params::webhook_prefix_command,
$server_software = $r10k::params::webhook_server_software,
$enable_ssl = $r10k::params::webhook_enable_ssl,
$use_mcollective = $r10k::params::webhook_use_mcollective,
$r10k_deploy_arguments = $r10k::params::webhook_r10k_deploy_arguments,
Expand All @@ -29,9 +30,11 @@
$yaml_template = $r10k::params::webhook_yaml_template,
$command_prefix = $r10k::params::webhook_r10k_command_prefix,
$repository_events = $r10k::params::webhook_repository_events,
$allow_uppercase = $r10k::params::webhook_allow_uppercase,
$configfile = '/etc/webhook.yaml',
$manage_symlink = false,
$configfile_symlink = '/etc/webhook.yaml',
$enable_mutex_lock = $r10k::params::webhook_enable_mutex_lock,
) inherits r10k::params {

if $hash == 'UNSET' {
Expand All @@ -51,13 +54,16 @@
'protected' => $protected,
'prefix' => $prefix,
'prefix_command' => $prefix_command,
'server_software' => $server_software,
'enable_ssl' => $enable_ssl,
'use_mcollective' => $use_mcollective,
'r10k_deploy_arguments' => $r10k_deploy_arguments,
'public_key_path' => $public_key_path,
'private_key_path' => $private_key_path,
'command_prefix' => $command_prefix,
'repository_events' => $repository_events,
'enable_mutex_lock' => $enable_mutex_lock,
'allow_uppercase' => $allow_uppercase,
}
} else {
validate_hash($hash)
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": "https://github.com/acidprime/r10k",
"summary": "Module for setting up dynamic environments using r10k",
"tags": ["git", "pe", "environment", "mcollective","r10k"],
"version": "3.1.1",
"version": "3.2.0",
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand Down
22 changes: 22 additions & 0 deletions spec/acceptance/prefix_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class { 'r10k':
'basedir' => '${::settings::confdir}/environments',
'prefix' => true,
},
'noprefix' => {
'remote' => 'https://github.com/noprefix/repo.git',
'basedir' => '${::settings::confdir}/environments'
},
'customprefix' => {
'remote' => 'https://github.com/customprefix/repo.git',
'basedir' => '${::settings::confdir}/environments',
'prefix' => 'custom'
}
},
}
class {'r10k::webhook::config':
Expand Down Expand Up @@ -61,5 +70,18 @@ class {'r10k::webhook':
expect(r.exit_code).to eq(0)
end
end
it 'should calculate custom prefix with Github payloads via payload end point' do
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/customprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
expect(r.stdout).to match(/^.*custom_production.*$/)
expect(r.exit_code).to eq(0)
end
end

it 'should calculate no prefix Github payloads via payload end point' do
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/noprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
expect(r.stdout).to match(/^.* production.*$/)
expect(r.exit_code).to eq(0)
end
end
end
end
Loading