-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
42 lines (34 loc) · 1.01 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rack'
require 'puppet/util/command_line'
class ManifestRouter
def initialize(manifest_dir, domain_dir)
@domain_dir = "#{manifest_dir}/#{domain_dir}"
end
def call(env)
request = Rack::Request.new(env)
if request.path =~ %r|/catalog/|
domain = get_domain(request.path)
domains = get_domains(@domain_dir)
if domain and domains.include? domain
ARGV << "--manifest" << "#{@domain_dir}/#{domain}.pp"
end
end
@puppet = Rack::Builder.new do
$0 = "master"
#ARGV << "--debug"
ARGV << "--rack"
ARGV << "--confdir" << "/etc/puppet"
ARGV << "--vardir" << "/var/lib/puppet"
run Puppet::Util::CommandLine.new.execute
end
@puppet.call(env)
end
private
def get_domains(dir)
Dir.glob("#{dir}/*.pp").collect { |f| f.split('/')[-1].gsub('.pp', '') }
end
def get_domain(path)
path.split('/')[3].split('.')[1..-1].join('.')
end
end
run ManifestRouter.new("/path/to/node/manifests", "subdir_containing_import_files")