anthill-librarian-puppet 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a97b7f6c5989c2322836f64053dd63974ed06f24
4
+ data.tar.gz: 3771626ef22f8a6300125b22a93e4a07d6f9c822
5
+ SHA512:
6
+ metadata.gz: 0d7f61d5946b533f197e7893b04094db1f69be7b9f5d49e4451b6cb68ab4e2f17254c5cc9df4c3227daf5ac5099e129fb5df557050956d95fdab453f330e01d5
7
+ data.tar.gz: 47503911098f98be946677e65add8d72b330d4f4fff7c025e4745aad4a2037808fb1061cb964c4603ccfcf9dad3b4be8e657ce652e38290a032bca691229f5f3
@@ -0,0 +1,5 @@
1
+ pkg/
2
+ Gemfile.lock
3
+ tmp/
4
+ coverage/
5
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012-2014 Tim Sharpe, Carlos Sanchez and others
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,337 @@
1
+ # Librarian-puppet
2
+
3
+ [![Build Status](https://travis-ci.org/voxpupuli/librarian-puppet.png?branch=master)](https://travis-ci.org/voxpupuli/librarian-puppet)
4
+
5
+ ## Introduction
6
+
7
+ Librarian-puppet is a bundler for your puppet infrastructure. You can use
8
+ librarian-puppet to manage the puppet modules your infrastructure depends on,
9
+ whether the modules come from the [Puppet Forge](https://forge.puppet.com/),
10
+ Git repositories or just a path.
11
+
12
+ * Librarian-puppet can reuse the dependencies listed in your `Modulefile` or `metadata.json`
13
+ * Forge modules can be installed from [Puppetlabs Forge](https://forge.puppet.com/) or an internal Forge such as [Pulp](http://www.pulpproject.org/)
14
+ * Git modules can be installed from a branch, tag or specific commit, optionally using a path inside the repository
15
+ * Modules can be installed from GitHub using tarballs, without needing Git installed
16
+ * Modules can be installed from a filesystem path
17
+ * Module dependencies are resolved transitively without needing to list all the modules explicitly
18
+
19
+
20
+ Librarian-puppet manages your `modules/` directory for you based on your
21
+ `Puppetfile`. Your `Puppetfile` becomes the authoritative source for what
22
+ modules you require and at what version, tag or branch.
23
+
24
+ Once using Librarian-puppet you should not modify the contents of your `modules`
25
+ directory. The individual modules' repos should be updated, tagged with a new
26
+ release and the version bumped in your Puppetfile.
27
+
28
+ It is based on [Librarian](https://github.com/applicationsonline/librarian), a
29
+ framework for writing bundlers, which are tools that resolve, fetch, install,
30
+ and isolate a project's dependencies.
31
+
32
+ ## Versions
33
+
34
+ Librarian-Puppet 3.0.0 and newer requires Ruby >= 2.0. Use version 2.2.4 if you need support for Puppet 3.7 or earlier, or Ruby 1.9 or earlier. Note that [Puppet 4.10 and newer require Ruby 2.1](https://puppet.com/docs/puppet/4.10/system_requirements.html#prerequisites) or newer.
35
+
36
+ Librarian-Puppet 2.0.0 and newer requires Ruby >= 1.9 and uses Puppet Forge API v3. For Ruby 1.8 use 1.5.0.
37
+
38
+ See the [Changelog](Changelog.md) for more details.
39
+
40
+ ## The Puppetfile
41
+
42
+ Every Puppet repository that uses Librarian-puppet may have a file named
43
+ `Puppetfile`, `metadata.json` or `Modulefile` in the root directory of that repository.
44
+ The full specification
45
+ for which modules your puppet infrastructure repository depends goes in here.
46
+
47
+ ### Simple usage
48
+
49
+ If no Puppetfile is present, `librarian-puppet` will download all the dependencies
50
+ listed in your `metadata.json` or `Modulefile` from the Puppet Forge,
51
+ as if the Puppetfile contained
52
+
53
+ forge "https://forgeapi.puppetlabs.com"
54
+
55
+ metadata
56
+
57
+
58
+ ### Example Puppetfile
59
+
60
+ forge "https://forgeapi.puppetlabs.com"
61
+
62
+ mod 'puppetlabs-razor'
63
+ mod 'puppetlabs-ntp', "0.0.3"
64
+
65
+ mod 'puppetlabs-apt',
66
+ :git => "git://github.com/puppetlabs/puppetlabs-apt.git"
67
+
68
+ mod 'puppetlabs-stdlib',
69
+ :git => "git://github.com/puppetlabs/puppetlabs-stdlib.git"
70
+
71
+ mod 'puppetlabs-apache', '0.6.0',
72
+ :github_tarball => 'puppetlabs/puppetlabs-apache'
73
+
74
+ mod 'acme-mymodule', :path => './some_folder'
75
+
76
+ exclusion 'acme-bad_module'
77
+
78
+
79
+ ### Recursive module dependency resolution
80
+
81
+ When fetching a module all dependencies specified in its
82
+ `Modulefile`, `metadata.json` and `Puppetfile` will be resolved and installed.
83
+
84
+ ### Puppetfile Breakdown
85
+
86
+ forge "https://forgeapi.puppetlabs.com"
87
+
88
+ This declares that we want to use the official Puppet Labs Forge as our default
89
+ source when pulling down modules. If you run your own local forge, you may
90
+ want to change this.
91
+
92
+ metadata
93
+
94
+ Download all the dependencies listed in your `metadata.json` or `Modulefile` from the Puppet Forge.
95
+
96
+ mod 'puppetlabs-razor'
97
+
98
+ Pull in the latest version of the Puppet Labs Razor module from the default
99
+ source.
100
+
101
+ mod 'puppetlabs-ntp', "0.0.3"
102
+
103
+ Pull in version 0.0.3 of the Puppet Labs NTP module from the default source.
104
+
105
+ mod 'puppetlabs-apt',
106
+ :git => "git://github.com/puppetlabs/puppetlabs-apt.git"
107
+
108
+ Our puppet infrastructure repository depends on the `apt` module from the
109
+ Puppet Labs GitHub repos and checks out the `master` branch.
110
+
111
+ mod 'puppetlabs-apt',
112
+ :git => "git://github.com/puppetlabs/puppetlabs-apt.git",
113
+ :ref => '0.0.3'
114
+
115
+ Our puppet infrastructure repository depends on the `apt` module from the
116
+ Puppet Labs GitHub repos and checks out a tag of `0.0.3`.
117
+
118
+ mod 'puppetlabs-apt',
119
+ :git => "git://github.com/puppetlabs/puppetlabs-apt.git",
120
+ :ref => 'feature/master/dans_refactor'
121
+
122
+ Our puppet infrastructure repository depends on the `apt` module from the
123
+ Puppet Labs GitHub repos and checks out the `dans_refactor` branch.
124
+
125
+ When using a Git source, we do not have to use a `:ref =>`.
126
+ If we do not, then librarian-puppet will assume we meant the `master` branch.
127
+
128
+ If we use a `:ref =>`, we can use anything that Git will recognize as a ref.
129
+ This includes any branch name, tag name, SHA, or SHA unique prefix. If we use a
130
+ branch, we can later ask Librarian-puppet to update the module by fetching the
131
+ most recent version of the module from that same branch.
132
+
133
+ Note that Librarian-puppet recognizes the [r10k Puppetfile's](https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd) additional
134
+ options, `:tag`, `:commit`, and `:branch`, but only as aliases for `:ref`.
135
+ That is, there is no implementation of r10k's optimizations around fetching
136
+ these different types of git objects.
137
+
138
+ The Git source also supports a `:path =>` option. If we use the path option,
139
+ Librarian-puppet will navigate down into the Git repository and only use the
140
+ specified subdirectory. Some people have the habit of having a single repository
141
+ with many modules in it. If we need a module from such a repository, we can
142
+ use the `:path =>` option here to help Librarian-puppet drill down and find the
143
+ module subdirectory.
144
+
145
+ mod 'puppetlabs-apt',
146
+ :git => "git://github.com/fake/puppet-modules.git",
147
+ :path => "modules/apt"
148
+
149
+ Our puppet infrastructure repository depends on the `apt` module, which we have
150
+ stored as a directory under our `puppet-modules` git repos.
151
+
152
+ mod 'puppetlabs-apache', '0.6.0',
153
+ :github_tarball => 'puppetlabs/puppetlabs-apache'
154
+
155
+ Our puppet infrastructure repository depends on the `puppetlabs-apache` module,
156
+ to be downloaded from GitHub tarball.
157
+
158
+ mod 'acme-mymodule', :path => './some_folder'
159
+
160
+ Our puppet infrastructure repository depends on the `acme-mymodule` module,
161
+ which is already in the filesystem.
162
+
163
+ exclusion 'acme-bad_module'
164
+
165
+ Exclude the module `acme-bad_module` from resolution and installation.
166
+
167
+ ## How to Use
168
+
169
+ Install librarian-puppet:
170
+
171
+ $ gem install librarian-puppet
172
+
173
+ Prepare your puppet infrastructure repository:
174
+
175
+ $ cd ~/path/to/puppet-inf-repos
176
+ $ (git) rm -rf modules
177
+ $ librarian-puppet init
178
+
179
+ Librarian-puppet takes over your `modules/` directory, and will always
180
+ reinstall (if missing) the modules listed the `Puppetfile.lock` into your
181
+ `modules/` directory, therefore you do not need your `modules/` directory to be
182
+ tracked in Git.
183
+
184
+ Librarian-puppet uses a `.tmp/` directory for tempfiles and caches. You should
185
+ not track this directory in Git.
186
+
187
+ Running `librarian-puppet init` will create a skeleton Puppetfile for you as
188
+ well as adding `tmp/` and `modules/` to your `.gitignore`.
189
+
190
+ $ librarian-puppet install [--clean] [--verbose]
191
+
192
+ This command looks at each `mod` declaration and fetches the module from the
193
+ source specified. This command writes the complete resolution into
194
+ `Puppetfile.lock` and then copies all of the fetched modules into your
195
+ `modules/` directory, overwriting whatever was there before.
196
+
197
+ Librarian-puppet support both v1 and v3 of the Puppet Forge API.
198
+ Specify a specific API version when installing modules:
199
+
200
+ $ librarian-puppet install --use-v1-api # this is default; ignored for official Puppet Forge
201
+ $ librarian-puppet install --no-use-v1-api # use the v3 API; default for official Puppet Forge
202
+
203
+ Please note that this does not apply for the official Puppet Forge, where v3 is used by default.
204
+
205
+ Get an overview of your `Puppetfile.lock` with:
206
+
207
+ $ librarian-puppet show
208
+
209
+ Inspect the details of specific resolved dependencies with:
210
+
211
+ $ librarian-puppet show NAME1 [NAME2, ...]
212
+
213
+ Find out which dependencies are outdated and may be updated:
214
+
215
+ $ librarian-puppet outdated [--verbose]
216
+
217
+ Update the version of a dependency:
218
+
219
+ $ librarian-puppet update apt [--verbose]
220
+ $ git diff Puppetfile.lock
221
+ $ git add Puppetfile.lock
222
+ $ git commit -m "bumped the version of apt up to 0.0.4."
223
+
224
+ ## Configuration
225
+
226
+ Configuration comes from three sources with the following highest-to-lowest
227
+ precedence:
228
+
229
+ * The local config (`./.librarian/puppet/config`)
230
+ * The environment
231
+ * The global config (`~/.librarian/puppet/config`)
232
+
233
+ You can inspect the final configuration with:
234
+
235
+ $ librarian-puppet config
236
+
237
+ You can find out where a particular key is set with:
238
+
239
+ $ librarian-puppet config KEY
240
+
241
+ You can set a key at the global level with:
242
+
243
+ $ librarian-puppet config KEY VALUE --global
244
+
245
+ And remove it with:
246
+
247
+ $ librarian-puppet config KEY --global --delete
248
+
249
+ You can set a key at the local level with:
250
+
251
+ $ librarian-puppet config KEY VALUE --local
252
+
253
+ And remove it with:
254
+
255
+ $ librarian-puppet config KEY --local --delete
256
+
257
+ You cannot set or delete environment-level config keys with the CLI.
258
+
259
+ Configuration set at either the global or local level will affect subsequent
260
+ invocations of `librarian-puppet`. Configurations set at the environment level are
261
+ not saved and will not affect subsequent invocations of `librarian-puppet`.
262
+
263
+ You can pass a config at the environment level by taking the original config key
264
+ and transforming it: replace hyphens (`-`) with underscores (`_`) and periods
265
+ (`.`) with doubled underscores (`__`), uppercase, and finally prefix with
266
+ `LIBRARIAN_PUPPET_`. For example, to pass a config in the environment for the key
267
+ `part-one.part-two`, set the environment variable
268
+ `LIBRARIAN_PUPPET_PART_ONE__PART_TWO`.
269
+
270
+ Configuration affects how various commands operate.
271
+
272
+ * The `path` config sets the directory to install to. If a relative
273
+ path, it is relative to the directory containing the `Puppetfile`. The
274
+ equivalent environment variable is `LIBRARIAN_PUPPET_PATH`.
275
+
276
+ * The `tmp` config sets the cache directory for librarian. If a relative
277
+ path, it is relative to the directory containing the `Puppetfile`. The
278
+ equivalent environment variable is `LIBRARIAN_PUPPET_TMP`.
279
+
280
+ * The `use-short-cache-path` config shortens the cache path part of the Puppet
281
+ forge URI to the 7 first digits of its SHA1 checksum. This helps additionally
282
+ to the `tmp` config to avoid too long paths under Windows. Under Windows this
283
+ is especially important when you use an alternative Puppet forge with a quite
284
+ longer URI.
285
+
286
+ Configuration can be set by passing specific options to other commands.
287
+
288
+ * The `path` config can be set at the local level by passing the `--path` option
289
+ to the `install` command. It can be unset at the local level by passing the
290
+ `--no-path` option to the `install` command. Note that if this is set at the
291
+ environment or global level then, even if `--no-path` is given as an option,
292
+ the environment or global config will be used.
293
+
294
+
295
+ ## Rsync Option
296
+
297
+ The default convergence strategy between the cache and the module directory is
298
+ to execute an `rm -r` on the module directory and just `cp -r` from the cache.
299
+ This causes the module to be removed from the module path every time librarian
300
+ puppet updates, regardless of whether the content has changed. This can cause
301
+ some problems in environments with lots of change. The problem arises when the
302
+ module directory gets removed while Puppet is trying to read files inside it.
303
+ The `puppet master` process will lose its CWD and the catalog will fail to
304
+ compile. To avoid this, you can use `rsync` to implement a more conservative
305
+ convergence strategy. This will use `rsync` with the `-avz` and `--delete`
306
+ flags instead of a `rm -r` and `cp -r`. To use this feature, just set the
307
+ `rsync` configuration setting to `true`.
308
+
309
+ $ librarian-puppet config rsync true --global
310
+
311
+ Alternatively, using an environment variable:
312
+
313
+ LIBRARIAN_PUPPET_RSYNC='true'
314
+
315
+ Note that the directories will still be purged if you run librarian-puppet with
316
+ the --clean or --destructive flags.
317
+
318
+ ## How to Contribute
319
+
320
+ * Pull requests please.
321
+ * Bonus points for feature branches.
322
+
323
+ ## Reporting Issues
324
+
325
+ Bug reports to the github issue tracker please.
326
+ Please include:
327
+
328
+ * Relevant `Puppetfile` and `Puppetfile.lock` files
329
+ * Version of ruby, librarian-puppet, and puppet
330
+ * What distro
331
+ * Please run the `librarian-puppet` commands in verbose mode by using the
332
+ `--verbose` flag, and include the verbose output in the bug report as well.
333
+
334
+
335
+ ## License
336
+ Please see the [LICENSE](https://github.com/voxpupuli/librarian-puppet/blob/master/LICENSE)
337
+ file.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $:.unshift(lib) unless $:.include?(lib)
5
+
6
+ require 'librarian/puppet/cli'
7
+ Librarian::Puppet::Cli.bin!
@@ -0,0 +1,36 @@
1
+ require 'librarian'
2
+ require 'fileutils'
3
+
4
+ require 'librarian/puppet/extension'
5
+ require 'librarian/puppet/version'
6
+
7
+ require 'librarian/action/install'
8
+
9
+ module Librarian
10
+ module Puppet
11
+ @@puppet_version = nil
12
+
13
+ # Output of puppet --version, typically x.y.z
14
+ # For Puppet Enterprise it contains the PE version too, ie. 3.4.3 (Puppet Enterprise 3.2.1)
15
+ def puppet_version
16
+ return @@puppet_version unless @@puppet_version.nil?
17
+
18
+ begin
19
+ @@puppet_version = Librarian::Posix.run!(%W{puppet --version}).strip
20
+ rescue Errno::ENOENT, Librarian::Posix::CommandFailure => error
21
+ msg = "Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc)."
22
+ msg += "\npuppet --version returned #{error.status}" if error.respond_to? :status
23
+ msg += "\n#{error.message}" unless error.message.nil?
24
+ $stderr.puts msg
25
+ exit 1
26
+ end
27
+ return @@puppet_version
28
+ end
29
+
30
+ # Puppet version x.y.z translated as a Gem version
31
+ def puppet_gem_version
32
+ Gem::Version.create(puppet_version.split(' ').first.strip.gsub('-', '.'))
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require "librarian/puppet/action/install"
2
+ require "librarian/puppet/action/resolve"
@@ -0,0 +1,26 @@
1
+ require 'librarian/action/install'
2
+
3
+ module Librarian
4
+ module Puppet
5
+ module Action
6
+ class Install < Librarian::Action::Install
7
+
8
+ private
9
+
10
+ def create_install_path
11
+ install_path.rmtree if install_path.exist? && destructive?
12
+ install_path.mkpath
13
+ end
14
+
15
+ def destructive?
16
+ environment.config_db.local['destructive'] == 'true'
17
+ end
18
+
19
+ def check_specfile
20
+ # don't fail if Puppetfile doesn't exist as we'll use the Modulefile or metadata.json
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end