-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rbenv and add chruby #59
- Loading branch information
Showing
8 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
repo_dir="$(dirname $0)/.." | ||
. "${repo_dir}/bin/functions" | ||
app=${1:-undef} | ||
repo=${2:-https://github.com/example42/pdk-module-template-psick-base-profile} | ||
|
||
show_help () { | ||
cat << EOF | ||
This script wraps pdk (Puppet Development Kit) to create a new base profile. | ||
It requires the pdk command from Puppet Development Kit (https://docs.puppet.com/pdk/) | ||
You must specify the name of the base profile name and an optional source git repo. | ||
The default template used is: https://github.com/example42/pdk-module-template-psick-base-profile | ||
Usage: | ||
$0 <app> [repo] | ||
EOF | ||
} | ||
|
||
if [ "x${app}" == "xundef" ]; then | ||
show_help | ||
exit 1 | ||
fi | ||
|
||
if [ ! -z $(which pdk) ]; then | ||
echo_title "Creating a new psick profile class with pdk" | ||
cd $repo_dir | ||
pdk new class --template-url=$repo $app | ||
else | ||
show_help | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# psick::chruby | ||
# | ||
# @summary This psick profile manages chruby. | ||
# | ||
# @example Include it to install chruby | ||
# include psick::chruby | ||
# | ||
# @example Include in PSICK via hiera (yaml) | ||
# psick::profiles::linux_classes: | ||
# chruby: psick::chruby | ||
# | ||
# @example Set no-noop mode and enforce changes even if noop is set for the agent | ||
# psick::chruby::no_noop: true | ||
# | ||
# @param manage If to actually manage any resource in this profile or not | ||
# @param auto_prereq If to automatically install eventual dependencies. | ||
# Set to false if you have problems with duplicated resources, being sure that you | ||
# provide the needed prerequistes. | ||
# @param no_noop Set noop metaparameter to false to all the resources of this class. | ||
# This overrides any noop setting which might be in place. | ||
class psick::chruby ( | ||
Psick::Ensure $ensure = 'present', | ||
String $version = '0.3.7', | ||
String $default_ruby_version = '2.4.2', | ||
StdLib::AbsolutePath $ruby_prefix = '/opt/rubies', | ||
String $user = 'puppet', | ||
Optional[String] $group = undef, | ||
Optional[String] $sources_root = undef, | ||
Optional[String] $download_root = undef, | ||
|
||
Boolean $manage = $::psick::manage, | ||
Boolean $auto_prereq = $::psick::auto_prereq, | ||
Boolean $no_noop = false, | ||
|
||
) { | ||
|
||
# We declare resources only if $manage = true | ||
if $manage { | ||
|
||
# If no_noop is set it's enforced, unless psick::noop_mode is | ||
if ! $::psick::noop_mode and $no_noop { | ||
info('Forced no-noop mode in psick::chruby') | ||
noop(false) | ||
} | ||
|
||
$sources_dest = $sources_root ? { | ||
undef => "${staging_root}/sources", | ||
default => $sources_root | ||
} | ||
$download_dest = $download_root ? { | ||
undef => "${staging_root}/downloads", | ||
default => $download_root | ||
} | ||
psick::netinstall { "chruby-v${version}.tar.gz": | ||
destination_dir => $sources_dest, | ||
url => "https://github.com/postmodern/chruby/archive/v${version}.tar.gz", | ||
extract_command => 'tar -zxf', | ||
owner => $user, | ||
group => $group, | ||
creates => "${sources_dest}/chruby-${version}", | ||
before => Exec['install chruby'], | ||
} | ||
|
||
exec { 'install chruby': | ||
cwd => "${sources_dest}/chruby-${version}", | ||
command => 'make install', | ||
creates => '/usr/local/share/chruby', | ||
path => [ '/sbin', '/usr/sbin', '/bin', '/usr/bin' ], | ||
} | ||
|
||
file { '/etc/profile.d/chruby.sh': | ||
ensure => 'file', | ||
content => '. "/usr/local/share/chruby/chruby.sh"', | ||
require => Exec['install chruby'], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Derived from justinstoller/chruby module | ||
# | ||
define psick::chruby::gem ( | ||
String $gem = $title, | ||
Optional[String] $gem_version = undef, | ||
String $ruby_version = '1.9' | ||
) { | ||
|
||
if $gem_version { | ||
$version_check = "| grep ${gem_version}" | ||
$version_string = "-v${gem_version}" | ||
} else { | ||
$version_check = '' | ||
$version_string = '' | ||
} | ||
|
||
$chruby = '/usr/local/bin/chruby-exec' | ||
$gem_cmd = "gem install ${gem} ${version_string} --no-ri --no-rdoc" | ||
$grep = "grep '^${gem}' ${version_check}" | ||
|
||
exec { "install ${gem} on ${ruby_version}": | ||
command => "${chruby} ${ruby_version} -- ${gem_cmd}", | ||
unless => "${chruby} ${ruby_version} -- gem list | ${grep}", | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
require 'yaml' | ||
facts_yaml = File.dirname(__FILE__) + '/../../fixtures/facts/spec.yaml' | ||
facts = YAML.load_file(facts_yaml) | ||
|
||
describe 'psick::chruby' do | ||
on_supported_os(facterversion: '2.4').select { |k, _v| k == 'redhat-7-x86_64' || k == 'ubuntu-16.04-x86_64' }.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) { os_facts.merge(facts) } | ||
let(:pre_condition) { 'include psick' } | ||
|
||
describe 'with default params' do | ||
it { is_expected.to compile } | ||
it { is_expected.to contain_class('psick::chruby') } | ||
end | ||
|
||
describe 'with manage => false' do | ||
let(:params) { { 'manage' => false } } | ||
|
||
it { is_expected.to have_resource_count(0) } | ||
end | ||
|
||
describe 'with no_noop => true' do | ||
let(:params) { { 'no_noop' => true } } | ||
|
||
# it { is_expected.to contain_package('chruby').with('noop': false) } | ||
end | ||
end | ||
end | ||
end |