puppet_transplant 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -12
- data/lib/puppet_transplant/installer.rb +30 -117
- data/lib/puppet_transplant/version.rb +1 -1
- data/lib/rubygems/puppet_transplant.rb +0 -7
- metadata +4 -4
data/README.md
CHANGED
@@ -6,6 +6,14 @@ the puppet gem to relocate the default confdir and vardir. This behaviors
|
|
6
6
|
allows multiple versions of puppet to exist in different gemsets with distinct
|
7
7
|
default base directories.
|
8
8
|
|
9
|
+
The relocation directory is based on the Ruby PREFIX. For example, if the
|
10
|
+
puppet gem is installed using a ruby with a prefix of `/opt/operations` then
|
11
|
+
`operations` will be used to construct a default system confdir of
|
12
|
+
`/etc/operations/puppet` and a default system vardir of
|
13
|
+
`/var/lib/operations/puppet`. Similarly,
|
14
|
+
`/opt/crossfader/versions/ruby/1.9.3-p448` will result in
|
15
|
+
`/etc/crossfader/puppet` and `/var/lib/crossfader/puppet`.
|
16
|
+
|
9
17
|
The design of modifying the default confdir and vardir has been chosen to
|
10
18
|
support Puppet operating as a library in addition to Puppet operating as an
|
11
19
|
application. This approach has the goal of keeping behavior consistent between
|
@@ -15,26 +23,42 @@ inconsistency between application and library use cases.
|
|
15
23
|
|
16
24
|
## Installation
|
17
25
|
|
18
|
-
|
26
|
+
Install this gem before installing Puppet to ensure puppet will be relocated
|
27
|
+
upon installation.
|
28
|
+
|
29
|
+
$ gem install puppet_transplant
|
19
30
|
|
20
|
-
|
31
|
+
If you do not have permission to write to `$GEM_HOME`, try preserving your
|
32
|
+
environment in sudo:
|
21
33
|
|
22
|
-
|
34
|
+
$ sudo -E gem install puppet_transplant
|
23
35
|
|
24
|
-
|
36
|
+
## Usage
|
25
37
|
|
26
|
-
|
38
|
+
Simply install the gem into the current gemset then install a puppet gem
|
39
|
+
afterwards. For example:
|
27
40
|
|
28
|
-
$ gem
|
41
|
+
$ which gem
|
42
|
+
/opt/operations/bin/gem
|
29
43
|
|
30
|
-
|
44
|
+
$ sudo -E gem install puppet_transplant
|
45
|
+
Fetching: puppet_transplant-0.0.2.gem (100%)
|
46
|
+
Successfully installed puppet_transplant-0.0.2
|
47
|
+
1 gem installed
|
48
|
+
Installing ri documentation for puppet_transplant-0.0.2...
|
49
|
+
Installing RDoc documentation for puppet_transplant-0.0.2...
|
31
50
|
|
32
|
-
|
33
|
-
|
34
|
-
|
51
|
+
$ sudo -E gem install puppet --no-ri --no-rdoc
|
52
|
+
Fetching: puppet-3.4.2.gem (100%)
|
53
|
+
Transplanted confdir: /etc/operations/puppet
|
54
|
+
Transplanted vardir: /var/lib/operations/puppet
|
55
|
+
Successfully installed puppet-3.4.2
|
56
|
+
1 gem installed
|
35
57
|
|
36
|
-
|
37
|
-
|
58
|
+
$ sudo -E puppet agent --configprint confdir
|
59
|
+
/etc/operations/puppet
|
60
|
+
$ sudo -E puppet agent --configprint vardir
|
61
|
+
/var/lib/operations/puppet
|
38
62
|
|
39
63
|
## Contributing
|
40
64
|
|
@@ -3,7 +3,24 @@ require 'rbconfig'
|
|
3
3
|
require 'rubygems/installer'
|
4
4
|
|
5
5
|
module PuppetTransplant
|
6
|
+
##
|
7
|
+
# The Installer class contains all of the data and behavior required to
|
8
|
+
# relocate Puppet's default system confdir and vardir settings. The behavior
|
9
|
+
# is intended to be implemented as a [rubygems
|
10
|
+
# plugin](http://rubygems.rubyforge.org/rubygems-update/Gem.html#method-c-post_install),
|
11
|
+
# called using something like the following example.
|
12
|
+
#
|
13
|
+
# module Gem
|
14
|
+
# post_install do |gem_installer|
|
15
|
+
# PuppetTransplant::Installer.post_install(gem_installer)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @author Jeff McCune <jeff@puppetlabs.com>
|
6
20
|
class Installer
|
21
|
+
##
|
22
|
+
# RelocationError instances are raised when modification of Puppet's
|
23
|
+
# behavior fails for some reason. The message should indicate why.
|
7
24
|
class RelocationError < Exception; end
|
8
25
|
|
9
26
|
##
|
@@ -14,31 +31,24 @@ module PuppetTransplant
|
|
14
31
|
#
|
15
32
|
# @param [Gem::Installer] gem_installer The gem installer instance of the
|
16
33
|
# gem just installed, passed from the Gem.post_install callback.
|
34
|
+
#
|
35
|
+
# @return [Boolean] true if relocation succeeded, false if it did not
|
36
|
+
# succeed.
|
17
37
|
def self.post_install(gem_installer)
|
18
38
|
# Do nothing unless we're dealing with Puppet.
|
19
39
|
return unless gem_installer.spec.name == 'puppet'
|
20
40
|
# Perform the relocation
|
21
41
|
installer = new(gem_installer)
|
22
|
-
|
42
|
+
begin
|
43
|
+
installer.relocate_puppet!
|
44
|
+
rescue RelocationError => detail
|
45
|
+
gem_installer.ui.alert_error "PuppetTransplant relocation failed: #{detail}"
|
46
|
+
return false
|
47
|
+
end
|
23
48
|
# Let the user know what happened
|
24
49
|
gem_installer.ui.debug "Transplanted confdir: #{installer.confdir}"
|
25
50
|
gem_installer.ui.debug "Transplanted vardir: #{installer.vardir}"
|
26
|
-
|
27
|
-
|
28
|
-
##
|
29
|
-
# pre_install takes a {Gem::Installer} instance expected to be passed from
|
30
|
-
# a Gem.pre_install callback and overrides the
|
31
|
-
# {Gem::Installer#app_script_text} method if the puppet gem is about to be
|
32
|
-
# installed.
|
33
|
-
#
|
34
|
-
# @deprecated in favor of {.post_install}
|
35
|
-
#
|
36
|
-
# @param [Gem::Installer] gem_installer The gem installer instance of the
|
37
|
-
# gem just installed, passed from the Gem.pre_install callback.
|
38
|
-
def self.pre_install(gem_installer)
|
39
|
-
return unless gem_installer.spec.name == 'puppet'
|
40
|
-
installer = new(gem_installer)
|
41
|
-
installer.modify_app_script_text!
|
51
|
+
return true
|
42
52
|
end
|
43
53
|
|
44
54
|
attr_reader :gem_installer
|
@@ -50,53 +60,6 @@ module PuppetTransplant
|
|
50
60
|
@gem_installer = gem_installer
|
51
61
|
end
|
52
62
|
|
53
|
-
##
|
54
|
-
# modify_app_script_text! monkey patches the
|
55
|
-
# {Gem::Installer#app_script_text}
|
56
|
-
# method to implement the following behavior for the `puppet` binstub:
|
57
|
-
#
|
58
|
-
# 1. If `--confdir` or `--vardir` are specified via ARGV then use the
|
59
|
-
# provided values.
|
60
|
-
# 2. Otherwise modify ARGV to include `--confdir=/etc/#{org}/puppet` and
|
61
|
-
# `--vardir=/var/lib/#{org}/puppet`
|
62
|
-
#
|
63
|
-
# @deprecated in favor of overriding the default and confdir in a manner
|
64
|
-
# that supports consistency between puppet as a library and puppet as an
|
65
|
-
# application. Implementing a wrapper script that sets --confdir and
|
66
|
-
# --vardir creates inconsistent behavior between puppet as a library and
|
67
|
-
# puppet as an application.
|
68
|
-
#
|
69
|
-
# @see {#relocate_puppet!}
|
70
|
-
#
|
71
|
-
# @see #org
|
72
|
-
#
|
73
|
-
# @api private
|
74
|
-
#
|
75
|
-
# @return [String] the text of the modified app script.
|
76
|
-
def modify_app_script_text!
|
77
|
-
custom_app_script_text = method(:app_script_text)
|
78
|
-
bindir = bindir()
|
79
|
-
confdir = confdir()
|
80
|
-
vardir = vardir()
|
81
|
-
|
82
|
-
gem_installer.instance_eval do
|
83
|
-
orig_app_script_text = method(:app_script_text)
|
84
|
-
define_singleton_method(:app_script_text) do |bin_file_name|
|
85
|
-
case bin_file_name
|
86
|
-
when 'puppet'
|
87
|
-
ui.say "***************************************************"
|
88
|
-
ui.say "* PuppetTransplant produced #{bindir}/puppet"
|
89
|
-
ui.say "* confdir: #{confdir}"
|
90
|
-
ui.say "* vardir: #{vardir}"
|
91
|
-
ui.say "***************************************************"
|
92
|
-
custom_app_script_text.call(bin_file_name)
|
93
|
-
else
|
94
|
-
orig_app_script_text.call(bin_file_name)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
63
|
##
|
101
64
|
# relocate_puppet! overrides the default confdir and vardir using one of
|
102
65
|
# two methods. First, if the version of Puppet being relocated provides
|
@@ -115,12 +78,7 @@ module PuppetTransplant
|
|
115
78
|
if puppet_override_api?
|
116
79
|
rval = write_override_files
|
117
80
|
else
|
118
|
-
|
119
|
-
rval = modify_run_mode_in_place
|
120
|
-
rescue RelocationError => detail
|
121
|
-
gem_installer.ui.alert_error "Modification of run_mode.rb failed: #{detail}"
|
122
|
-
return false
|
123
|
-
end
|
81
|
+
rval = modify_run_mode_in_place
|
124
82
|
end
|
125
83
|
!!rval
|
126
84
|
end
|
@@ -144,9 +102,9 @@ module PuppetTransplant
|
|
144
102
|
def modify_run_mode_in_place
|
145
103
|
# Locate the run_mode.rb file
|
146
104
|
dir = gem_installer.dir
|
147
|
-
|
105
|
+
files = spec.files
|
148
106
|
|
149
|
-
if run_mode_file =
|
107
|
+
if run_mode_file = files.find() {|p| p.match(/\/run_mode.rb$/)}
|
150
108
|
run_mode_path = Pathname.new(File.join(dir, run_mode_file))
|
151
109
|
else
|
152
110
|
raise RelocationError, "Could not find run_mode.rb in the file list."
|
@@ -217,34 +175,6 @@ module PuppetTransplant
|
|
217
175
|
Puppet::Util::RunMode.respond_to?(:override_path)
|
218
176
|
end
|
219
177
|
|
220
|
-
##
|
221
|
-
# @deprecated in favor of overriding the default and confdir in a manner
|
222
|
-
# that supports consistency between puppet as a library and puppet as an
|
223
|
-
# application. Implementing a wrapper script that sets --confdir and
|
224
|
-
# --vardir creates inconsistent behavior between puppet as a library and
|
225
|
-
# puppet as an application.
|
226
|
-
#
|
227
|
-
# @see {#relocate_puppet!}
|
228
|
-
#
|
229
|
-
# @api private
|
230
|
-
#
|
231
|
-
# @return [String] the binstub contents
|
232
|
-
def app_script_text(bin_file_name)
|
233
|
-
return <<-TEXT
|
234
|
-
#{shebang bin_file_name}
|
235
|
-
#
|
236
|
-
# This file was generated by PuppetTransplant in order to override the default
|
237
|
-
# confdir and vardir in a generic way without patching.
|
238
|
-
|
239
|
-
require 'rubygems'
|
240
|
-
|
241
|
-
version = "#{Gem::Requirement.default}"
|
242
|
-
|
243
|
-
gem '#{spec.name}', version
|
244
|
-
load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version)
|
245
|
-
TEXT
|
246
|
-
end
|
247
|
-
|
248
178
|
##
|
249
179
|
# org parses the filesystem path of the location of the ruby prefix path to
|
250
180
|
# determine the organization name. For example, if Ruby is installed with
|
@@ -285,11 +215,6 @@ TEXT
|
|
285
215
|
end
|
286
216
|
private :spec
|
287
217
|
|
288
|
-
def shebang(bin_file_name)
|
289
|
-
gem_installer.shebang(bin_file_name)
|
290
|
-
end
|
291
|
-
private :shebang
|
292
|
-
|
293
218
|
##
|
294
219
|
# is_windows returns true if the ruby interpreter is currently running on a
|
295
220
|
# windows platform.
|
@@ -323,17 +248,5 @@ TEXT
|
|
323
248
|
def vardir
|
324
249
|
@vardir ||= "/var/lib/#{org}/puppet"
|
325
250
|
end
|
326
|
-
|
327
|
-
##
|
328
|
-
# bindir returns the bin directory where binstub scripts will be written.
|
329
|
-
def bindir
|
330
|
-
bindir = gem_installer.bin_dir || Gem.bindir(gem_home)
|
331
|
-
end
|
332
|
-
private :bindir
|
333
|
-
|
334
|
-
def gem_home
|
335
|
-
gem_installer.gem_home
|
336
|
-
end
|
337
|
-
private :gem_home
|
338
251
|
end
|
339
252
|
end
|
@@ -2,13 +2,6 @@
|
|
2
2
|
require 'puppet_transplant/installer'
|
3
3
|
|
4
4
|
module Gem
|
5
|
-
## We're no longer going the route of patching the binstub. Instead, we're
|
6
|
-
# going to override the default confdir and vardir in an effort to keep the
|
7
|
-
# behavior of puppet as a library and puppet as an application consistent.
|
8
|
-
# pre_install do |gem_installer|
|
9
|
-
# PuppetTransplant::Installer.pre_install(gem_installer)
|
10
|
-
# end
|
11
|
-
|
12
5
|
# Register a callback to override the default puppet confdir and vardir
|
13
6
|
post_install do |gem_installer|
|
14
7
|
PuppetTransplant::Installer.post_install(gem_installer)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet_transplant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: 4590383034694438716
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash:
|
123
|
+
hash: 4590383034694438716
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
126
|
rubygems_version: 1.8.23
|