vagrant-puppetfile 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8761f1af7bc1c83e86d12993be22e5520c049069
4
+ data.tar.gz: 3467da7324d67e7dac0d1c42013b2c198ac0a47e
5
+ SHA512:
6
+ metadata.gz: a2ec4e586cf490120233b69e30d1e014a3c1f137708c3c6395917c503a84c6225f538f38326dd4cfaa9b1c3d3a162d41d4794b9e63c4838f50ac34742ffbef3f
7
+ data.tar.gz: 413429affbd4b8f0cd4f93fff66a813421ba0091d8c8fb9c0310cacbb14dfb2734bc62f910c474d7a1af909ff22236faef668fc26a44a097ba5804d331f2a41e
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright (c) 2016 Catalyst.net Ltd
3
+ #
4
+ # This file is part of vagrant-puppetfile.
5
+ #
6
+ # vagrant-puppetfile is free software: you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation, either version 3 of the
9
+ # License, or (at your option) any later version.
10
+ #
11
+ # vagrant-puppetfile is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with vagrant-puppetfile. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'vagrant'
22
+ require 'vagrant/puppetfile'
@@ -0,0 +1,152 @@
1
+ #
2
+ # Copyright (c) 2016 Catalyst.net Ltd
3
+ #
4
+ # This file is part of vagrant-puppetfile.
5
+ #
6
+ # vagrant-puppetfile is free software: you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation, either version 3 of the
9
+ # License, or (at your option) any later version.
10
+ #
11
+ # vagrant-puppetfile is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with vagrant-puppetfile. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'logger'
22
+ require 'open3'
23
+ require 'optparse'
24
+ require 'shellwords'
25
+
26
+ module Vagrant
27
+ module Puppetfile
28
+ class Provisioner < Vagrant.plugin('2', :provisioner)
29
+ def initialize(machine, _)
30
+ @logger = Vagrant::UI::Prefixed.new(machine.env.ui, machine.name)
31
+ end
32
+
33
+ def provision
34
+ Puppetfile.new.eval(@logger)
35
+ rescue Exception => e
36
+ @logger.error("Failed to evaluate Puppetfile: #{e.message}")
37
+ end
38
+ end
39
+
40
+ class Command < Vagrant.plugin('2', :command)
41
+ def execute
42
+ # FIXME use vagrant ui objects for these
43
+ stdout = Logger.new(STDOUT)
44
+ stderr = Logger.new(STDERR)
45
+
46
+ options = OptionParser.new do |o|
47
+ o.banner = 'Usage: vagrant puppetfile install'
48
+ o.separator ''
49
+ o.separator 'Options:'
50
+ o.on('-h', '--help', 'Print this help') do
51
+ return stdout.info(o.help)
52
+ end
53
+ end
54
+
55
+ case parse_options(options)
56
+ when ['install']
57
+ stdout.notice('Evaluating Puppetfile ...')
58
+ Puppetfile.new.eval(stdout)
59
+ else
60
+ stderr.warn(options.help)
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ def Command.synopsis
66
+ 'installs all modules listed in a Puppetfile'
67
+ end
68
+ end
69
+
70
+ class Plugin < Vagrant.plugin('2')
71
+ name 'puppetfile'
72
+ provisioner('puppetfile') { Provisioner }
73
+ command('puppetfile') { Command }
74
+ end
75
+
76
+ class Puppetfile < File
77
+ def initialize(*args)
78
+ super('Puppetfile', *args)
79
+ end
80
+
81
+ def eval(logger)
82
+ Evaluator.new(logger).instance_eval(Puppetfile.read(path))
83
+ end
84
+ end
85
+
86
+ class Logger < Logger
87
+ alias detail info
88
+ def initialize(*_)
89
+ super
90
+ self.formatter = Proc.new { |_, _, _, message| message }
91
+ end
92
+
93
+ def notice(message)
94
+ info("Notice: #{message}\n")
95
+ end
96
+ end
97
+
98
+ class Evaluator
99
+ if defined? Vagrant
100
+ class Exception < Vagrant::Errors::VagrantError
101
+ def error_message
102
+ 'Puppetfile module installation failed'
103
+ end
104
+ end
105
+ end
106
+
107
+ def unsupported(option, method, *args)
108
+ option = option.inspect
109
+ args = args.map(&:inspect).join(', ')
110
+ @logger.error "Unsupported option #{option} in `#{method} #{args}'"
111
+ raise Exception
112
+ end
113
+
114
+ def initialize(logger)
115
+ @logger = logger
116
+ @moduledir = 'modules'
117
+ end
118
+
119
+ def moduledir(path)
120
+ @moduledir = path
121
+ end
122
+
123
+ def forge(forge)
124
+ @forge = forge
125
+ end
126
+
127
+ def mod(name, version = :latest, options = {})
128
+ unless options.is_a?(Hash) and options.empty?
129
+ unsupported options, 'mod', name, version, options
130
+ end
131
+
132
+ unless version.is_a?(String) or version == :latest
133
+ unsupported version, 'mod', name, version
134
+ end
135
+
136
+ module_option = '--target-dir', @moduledir
137
+ forge_option = '--module_repository', @forge if @forge.is_a?(String)
138
+ version_option = '--version', version if version.is_a?(String)
139
+
140
+ command = 'puppet', 'module', 'install', name, *module_option, *forge_option, *version_option
141
+ output, status = Open3.capture2e *command.map(&:shellescape)
142
+
143
+ if status.success?
144
+ output.lines.each { |l| @logger.detail(l) }
145
+ else
146
+ output.lines.each { |l| @logger.error(l) }
147
+ raise Exception, output
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright (c) 2016 Catalyst.net Ltd
3
+ #
4
+ # This file is part of vagrant-puppetfile.
5
+ #
6
+ # vagrant-puppetfile is free software: you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation, either version 3 of the
9
+ # License, or (at your option) any later version.
10
+ #
11
+ # vagrant-puppetfile is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with vagrant-puppetfile. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Vagrant
22
+ module Puppetfile
23
+ NAME = 'vagrant-puppetfile'
24
+ VERSION = '0.3.0'
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-puppetfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan Hanson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automatically installs puppet modules from a Puppetfile during Vagrant
14
+ provisioning
15
+ email: evanh@catalyst.net.nz
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/vagrant-puppetfile.rb
21
+ - lib/vagrant/puppetfile.rb
22
+ - lib/vagrant/puppetfile/version.rb
23
+ homepage: https://gitlab.com/catalyst-it/vagrant-puppetfile
24
+ licenses:
25
+ - GPL-3.0
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Puppetfile provisioner
47
+ test_files: []