puppet_local 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/puppet-local +6 -0
- data/lib/puppet_local/command/install.rb +84 -0
- data/lib/puppet_local/command.rb +34 -0
- data/lib/puppet_local/command_manager.rb +6 -0
- data/lib/puppet_local.rb +13 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26cfce8053e572ee73932f77f7f098677f187750
|
4
|
+
data.tar.gz: cd500ed6317c5ec032c4055fb37a9071df972133
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2beb37fb56c94863c1022dac1301d8924480ab97cc6e2a60e777eb7ad30cac9792b72198c94d86ad06577a64542673b0da28be3dcdc102ae9fc28e6d6d617736
|
7
|
+
data.tar.gz: 0151e44910b59f48460f62bf70aea722a990e9f617443ec3590540ce229e66a87a7f01fe6897d5c7630d6ef74bd87a3b5eba3699bfd589b02c62ac8d4dec3dde
|
data/bin/puppet-local
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module PuppetLocal
|
2
|
+
class Command::Install < Command
|
3
|
+
|
4
|
+
option '--debug', :flag, 'enable puppet debug mode'
|
5
|
+
parameter 'hiera_file', 'hiera configuration file', :attribute_name => :hiera_path
|
6
|
+
|
7
|
+
def execute
|
8
|
+
puts 'Setting up environment...'
|
9
|
+
setup
|
10
|
+
create_puppet_hiera_config
|
11
|
+
puts 'Checking out git-modules...'
|
12
|
+
clone_git_modules
|
13
|
+
puts 'Applying catalog...'
|
14
|
+
apply
|
15
|
+
print on_green ' '
|
16
|
+
puts ' Puppet apply succeeded'
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
raise '`' + @hiera_path + '` does not exist' unless File.exists? @hiera_path
|
21
|
+
FileUtils.mkdir_p local_path
|
22
|
+
file = File.new(hiera_path_absolute, 'r')
|
23
|
+
@hiera = JSON.parse file.read
|
24
|
+
file.close
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_puppet_hiera_config
|
28
|
+
hiera_config = {
|
29
|
+
:backends => ['json'],
|
30
|
+
:hierarchy => [File.basename(@hiera_path).sub(/\.json$/, '')],
|
31
|
+
:json => {
|
32
|
+
:datadir => File.dirname(hiera_path_absolute)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
file = File.new(puppet_hiera_config, 'w')
|
36
|
+
file.puts(hiera_config.to_yaml.gsub('!ruby/sym ', ':'))
|
37
|
+
file.close
|
38
|
+
end
|
39
|
+
|
40
|
+
def clone_git_modules
|
41
|
+
@puppet_module_paths = []
|
42
|
+
if @hiera.include? 'git-modules'
|
43
|
+
@hiera['git-modules'].each do |source, version|
|
44
|
+
repo_path = local_path Digest::MD5.hexdigest(source)
|
45
|
+
if File.directory? repo_path
|
46
|
+
repo = Git.open repo_path
|
47
|
+
else
|
48
|
+
repo = Git.clone source, repo_path
|
49
|
+
end
|
50
|
+
repo.checkout version
|
51
|
+
@puppet_module_paths.push repo.dir.path + '/modules'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def apply
|
57
|
+
puppet_code = 'include hiera("classes", [])'
|
58
|
+
params = {
|
59
|
+
'--debug' => debug?,
|
60
|
+
'-e' => puppet_code,
|
61
|
+
'--hiera_config' => puppet_hiera_config,
|
62
|
+
'--modulepath' => puppet_module_path
|
63
|
+
}
|
64
|
+
system_command 'puppet apply', params
|
65
|
+
end
|
66
|
+
|
67
|
+
def hiera_path_absolute
|
68
|
+
File.expand_path @hiera_path
|
69
|
+
end
|
70
|
+
|
71
|
+
def local_path(path = '')
|
72
|
+
ENV['HOME'] + '/.puppet-local/' + Digest::MD5.hexdigest(hiera_path_absolute) + '/' + path
|
73
|
+
end
|
74
|
+
|
75
|
+
def puppet_hiera_config
|
76
|
+
local_path 'hiera.yaml'
|
77
|
+
end
|
78
|
+
|
79
|
+
def puppet_module_path
|
80
|
+
@puppet_module_paths.join(':')
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PuppetLocal
|
2
|
+
class Command < Clamp::Command
|
3
|
+
|
4
|
+
include Term::ANSIColor
|
5
|
+
|
6
|
+
def system_command(command, options={})
|
7
|
+
options.each do |name, value|
|
8
|
+
command += ' '
|
9
|
+
if value.is_a? String
|
10
|
+
command += name + ' ' + Shellwords.escape(value)
|
11
|
+
elsif value.is_a? TrueClass
|
12
|
+
command += name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
system command
|
16
|
+
raise 'Puppet apply failed' unless $?.success?
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(arguments)
|
20
|
+
begin
|
21
|
+
super
|
22
|
+
rescue Exception => e
|
23
|
+
$stderr.print on_red ' '
|
24
|
+
$stderr.print bold ' Error: '
|
25
|
+
if e.message.empty?
|
26
|
+
$stderr.puts 'Unknown error/Interrupt'
|
27
|
+
else
|
28
|
+
$stderr.puts e.message
|
29
|
+
end
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/puppet_local.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module PuppetLocal
|
2
|
+
require 'clamp'
|
3
|
+
require 'git'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
require 'io/console'
|
6
|
+
require 'json'
|
7
|
+
require 'puppet'
|
8
|
+
require 'shellwords'
|
9
|
+
require 'digest/md5'
|
10
|
+
require 'puppet_local/command'
|
11
|
+
require 'puppet_local/command/install'
|
12
|
+
require 'puppet_local/command_manager'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet_local
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomasz Durka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clamp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puppet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: git
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
description:
|
70
|
+
email: tomasz@durka.pl
|
71
|
+
executables:
|
72
|
+
- puppet-local
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/puppet_local/command/install.rb
|
77
|
+
- lib/puppet_local/command.rb
|
78
|
+
- lib/puppet_local/command_manager.rb
|
79
|
+
- lib/puppet_local.rb
|
80
|
+
- bin/puppet-local
|
81
|
+
homepage: https://github.com/tomaszdurka/puppet-local
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.1.9
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Simple tool for applying puppet modules from single hiera data source file
|
105
|
+
test_files: []
|