move to a more modular approach, allow for external gems to provide resources like a railtie
This commit is contained in:
parent
2d5cfed24a
commit
2cc210c520
@ -1,9 +1,20 @@
|
||||
require "puppet-standalone-mashup/version"
|
||||
|
||||
module Puppet
|
||||
module Standalone
|
||||
module Mashup
|
||||
# Your code goes here...
|
||||
module PuppetStandaloneMashup
|
||||
autoload :Provider, 'puppet-standalone-mashup/provider'
|
||||
autoload :Configuration, 'puppet-standalone-mashup/configuration'
|
||||
|
||||
class ProvideMyself < Provider ; end
|
||||
|
||||
def self.configure
|
||||
yield configuration
|
||||
end
|
||||
|
||||
def self.configuration
|
||||
@configuration ||= Configuration.new
|
||||
end
|
||||
|
||||
def self.paths_for(*args)
|
||||
Provider.paths_for(*args)
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
require 'erb'
|
||||
require 'puppet-standalone-mashup'
|
||||
|
||||
def _cset(name, *args, &block)
|
||||
unless exists?(name)
|
||||
@ -6,10 +7,6 @@ def _cset(name, *args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
module PuppetStandaloneMashup
|
||||
BASE = Pathname(File.expand_path('../../..', __FILE__))
|
||||
end
|
||||
|
||||
require 'capistrano/command'
|
||||
|
||||
module Capistrano
|
||||
@ -117,29 +114,43 @@ Capistrano::Configuration.instance.load do
|
||||
end
|
||||
end
|
||||
|
||||
def upload_directory_safely(source, target, options = {})
|
||||
run "mkdir -p #{target}"
|
||||
|
||||
Dir["#{source}/*"].each do |child|
|
||||
top.upload child, File.join(target, File.basename(child)), options
|
||||
end
|
||||
end
|
||||
|
||||
desc "Copy skel files to remote server"
|
||||
task :copy_skel do
|
||||
top.ensure_puppet_dir
|
||||
|
||||
targets = []
|
||||
|
||||
PuppetStandaloneMashup.paths_for('skel').each do |path|
|
||||
[ '*.erb', "#{distribution}/*.erb" ].each do |dir|
|
||||
Dir[PuppetStandaloneMashup::BASE.join('skel').join(dir).to_s].each do |file|
|
||||
Dir[path.join(dir).to_s].each do |file|
|
||||
data = StringIO.new(ERB.new(File.read(file)).result(binding))
|
||||
|
||||
top.upload data, target = File.join(puppet_dir, File.basename(file, '.erb'))
|
||||
|
||||
run "chmod a+x #{target}"
|
||||
targets << target
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
run "chmod a+x #{targets.join(' ')}"
|
||||
end
|
||||
|
||||
desc "Copy shared"
|
||||
task :copy_shared do
|
||||
top.ensure_puppet_dir
|
||||
|
||||
run "mkdir -p #{puppet_dir}/shared/additional-modules"
|
||||
|
||||
(%w{lib modules templates} + additional_modules.collect { |dir| "additional-modules/#{dir}" }).each do |dir|
|
||||
top.upload PuppetStandaloneMashup::BASE.join('shared', dir).to_s, File.join(puppet_dir, 'shared', dir)
|
||||
PuppetStandaloneMashup.configuration.shared_paths.each do |path|
|
||||
upload_directory_safely path.to_s, File.join(puppet_dir, 'shared', path.target)
|
||||
end
|
||||
end
|
||||
|
||||
@ -164,7 +175,7 @@ Capistrano::Configuration.instance.load do
|
||||
end
|
||||
|
||||
def with_additional_puppet_bin_path
|
||||
additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : ''
|
||||
"PATH=" + (PuppetStandaloneMashup.configuration.bin_path + [ "$PATH" ]).join(':')
|
||||
end
|
||||
|
||||
desc "Get managing user's public key"
|
||||
|
60
lib/puppet-standalone-mashup/configuration.rb
Normal file
60
lib/puppet-standalone-mashup/configuration.rb
Normal file
@ -0,0 +1,60 @@
|
||||
require 'delegate'
|
||||
|
||||
class Pathname
|
||||
def only_valid_paths_for_directories(*dirs)
|
||||
valid_paths = []
|
||||
|
||||
dirs.flatten.each do |dir|
|
||||
target = self.join(dir)
|
||||
|
||||
if target.directory?
|
||||
valid_paths << target
|
||||
end
|
||||
end
|
||||
|
||||
valid_paths
|
||||
end
|
||||
end
|
||||
|
||||
module PuppetStandaloneMashup
|
||||
class TargetedPath < SimpleDelegator
|
||||
attr_reader :path, :target
|
||||
|
||||
def initialize(path, target = path.basename)
|
||||
@path, @target = path, target
|
||||
end
|
||||
|
||||
def __getobj__
|
||||
@path
|
||||
end
|
||||
end
|
||||
|
||||
class Configuration
|
||||
SHARED_DIRS = %w{lib modules templates}
|
||||
|
||||
def additional_modules
|
||||
@additional_modules ||= []
|
||||
end
|
||||
|
||||
def bin_path
|
||||
@bin_path ||= []
|
||||
end
|
||||
|
||||
def shared_paths
|
||||
return @shared_paths if @shared_paths
|
||||
|
||||
@shared_paths = []
|
||||
|
||||
Provider.paths_for('shared').each do |path|
|
||||
@shared_paths += path.only_valid_paths_for_directories(SHARED_DIRS).collect { |dirpath| TargetedPath.new(dirpath) }
|
||||
end
|
||||
|
||||
Provider.paths_for('additional-modules').each do |path|
|
||||
@shared_paths += path.only_valid_paths_for_directories(additional_modules).collect { |dirpath| TargetedPath.new(dirpath, "modules/#{dirpath.basename}") }
|
||||
end
|
||||
|
||||
@shared_paths
|
||||
end
|
||||
end
|
||||
end
|
||||
|
15
lib/puppet-standalone-mashup/provider.rb
Normal file
15
lib/puppet-standalone-mashup/provider.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class PuppetStandaloneMashup::Provider
|
||||
def self.shared_sources
|
||||
@shared_sources ||= []
|
||||
end
|
||||
|
||||
def self.inherited(klass)
|
||||
shared_sources << Pathname(caller.first.gsub(%r{lib/.*}, ''))
|
||||
end
|
||||
|
||||
def self.paths_for(*paths)
|
||||
shared_sources.collect do |source|
|
||||
paths.collect { |path| source.join(path) }
|
||||
end.flatten
|
||||
end
|
||||
end
|
@ -5,7 +5,8 @@ define ssh {
|
||||
ensure => directory,
|
||||
mode => '0700',
|
||||
owner => $name,
|
||||
group => $name
|
||||
group => $name,
|
||||
require => User[$name]
|
||||
}
|
||||
|
||||
file { "${ssh_dir}/authorized_keys":
|
||||
|
@ -5,8 +5,8 @@ RUBYLIB="${PWD}/lib:${PWD}/shared/lib" \
|
||||
<%= with_additional_puppet_bin_path %> \
|
||||
puppet apply <%= additional_puppet_options %> \
|
||||
--confdir=$PWD \
|
||||
--modulepath=$PWD/modules:$PWD/shared/modules:$PWD/shared/additional-modules \
|
||||
--templatedir=$PWD/shared/templates:$PWD/templates \
|
||||
--modulepath=$PWD/modules:$PWD/shared/modules \
|
||||
--templatedir=$PWD/templates:$PWD/shared/templates \
|
||||
-v --no-report $@ \
|
||||
manifests/site.pp
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user