puppetbox 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.md +8 -2
- data/lib/puppetbox/driver/vagrant.rb +76 -0
- data/lib/puppetbox/driver.rb +16 -27
- data/lib/puppetbox/logger.rb +5 -1
- data/lib/puppetbox/result.rb +19 -1
- data/lib/puppetbox/version.rb +1 -1
- data/puppetbox.gemspec +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad288284d9a66b09a591260219ab1c3ad31c9562
|
4
|
+
data.tar.gz: 810ebf10d5f24b32eb3ba98d01b45db454805bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b2473e845e2aa9ad67d4012434a81ecaff79266d1a11823e29333eab3cb7cb78ffb8322f9e112b523967b142f7a19a29608c0e52d070fa8f5bb64558695745
|
7
|
+
data.tar.gz: 84b43a030638aad37d350bd7179882e1860f9bcd59ca324380ad7d45d2652cdb0df46276fd1384c77436bb90cf5a24aa43f69c8c6222c1e091ff8602a9c80968
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,9 +25,15 @@ TODO: Write usage instructions here
|
|
25
25
|
|
26
26
|
## Development
|
27
27
|
|
28
|
-
|
28
|
+
### Additional vagrant boxes
|
29
|
+
Many vagrant boxes that would be useful can't be shared for legal reasons, eg windows, suse, etc. These requirements can be worked around by users producing their own Vagrant boxes for internal use.
|
29
30
|
|
30
|
-
|
31
|
+
A really good source of build scripts is [bento](https://github.com/chef/bento) from Chef.
|
32
|
+
|
33
|
+
PuppetBox requires each box:
|
34
|
+
* Has puppet installed
|
35
|
+
* Has all puppet executables in `$PATH`
|
36
|
+
* Has the ability to work with vagrant shared folders. This usually means guestbox additions must be installed, although rsync can work in some situations. When using rsync, remember that your code will only be synced as your VM is reloaded
|
31
37
|
|
32
38
|
## Contributing
|
33
39
|
|
@@ -1,6 +1,82 @@
|
|
1
|
+
require 'vagrantomatic/vagrantomatic'
|
2
|
+
require 'puppetbox/result'
|
3
|
+
require 'fileutils'
|
4
|
+
require "puppetbox/logger"
|
5
|
+
|
1
6
|
module PuppetBox
|
2
7
|
module Driver
|
3
8
|
class Vagrant
|
9
|
+
# fixme - seems abandoned, might need to make my own :(
|
10
|
+
DEFAULT_VAGRANT_BOX = "puppetlabs/centos-7.2-64-puppet"
|
11
|
+
PUPPET_CODE_MOUNT = "/etc/puppetlabs/code/environments/production"
|
12
|
+
|
13
|
+
def initialize(name, codedir, keep_vm:true, working_dir:nil, config:{'box'=> DEFAULT_VAGRANT_BOX}, logger: nil)
|
14
|
+
@name = name
|
15
|
+
@keep_vm = keep_vm
|
16
|
+
@working_dir = working_dir || File.join(Dir.home, '.puppetbox')
|
17
|
+
@config = config
|
18
|
+
@result = PuppetBox::Result.new
|
19
|
+
@logger = PuppetBox::Logger.new(logger).logger
|
20
|
+
|
21
|
+
# Add the code dir to the config has so that it will automatically become
|
22
|
+
# a shared folder when the VM boots
|
23
|
+
@config["folders"] = "#{codedir}:#{PUPPET_CODE_MOUNT}"
|
24
|
+
@logger.debug "instance #{name} initialised"
|
25
|
+
end
|
26
|
+
|
27
|
+
def result
|
28
|
+
@result
|
29
|
+
end
|
30
|
+
|
31
|
+
# convert a derelelict (vagrant library used by vagrantomatic) exectutor to
|
32
|
+
# a result object as used by puppetbox
|
33
|
+
#
|
34
|
+
# Puppet exit status codes:
|
35
|
+
# 0: The run succeeded with no changes or failures; the system was already in the desired state.
|
36
|
+
# 1: The run failed, or wasn't attempted due to another run already in progress.
|
37
|
+
# 2: The run succeeded, and some resources were changed.
|
38
|
+
# 4: The run succeeded, and some resources failed.
|
39
|
+
# 6: The run succeeded, and included both changes and failures.
|
40
|
+
def run_puppet(puppet_class)
|
41
|
+
run_hash = @vm.run("sudo -i puppet apply --detailed-exitcodes -e 'include #{puppet_class}'")
|
42
|
+
@result.report(run_hash[:status], run_hash[:messages])
|
43
|
+
end
|
44
|
+
|
45
|
+
# Open a connection to a box (eg start a vm, ssh to a host etc)
|
46
|
+
def open()
|
47
|
+
# make sure working dir exists...
|
48
|
+
FileUtils.mkdir_p(@working_dir)
|
49
|
+
vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir: @working_dir)
|
50
|
+
|
51
|
+
@logger.debug("reading instance metadata for #{@name}")
|
52
|
+
@vm = vom.instance(@name)
|
53
|
+
|
54
|
+
@logger.debug("...setting instance config and saving")
|
55
|
+
|
56
|
+
@vm.config=(@config)
|
57
|
+
@vm.save
|
58
|
+
@logger.debug("Instance saved and ready for starting")
|
59
|
+
@vm.start
|
60
|
+
end
|
61
|
+
|
62
|
+
# Close a connection to a box (eg stop a vm, probaly doesn't need to do
|
63
|
+
# anything on SSH...)
|
64
|
+
def close()
|
65
|
+
if ! @keep_vm
|
66
|
+
@vm.purge
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Test that a VM is operational and able to run puppet
|
71
|
+
def self_test()
|
72
|
+
@vm.run("sudo -i puppet --version")[:status] == 0
|
73
|
+
end
|
74
|
+
|
75
|
+
def run_puppet_x2(puppet_class)
|
76
|
+
# fixme - link module
|
77
|
+
run_puppet(puppet_class)
|
78
|
+
run_puppet(puppet_class)
|
79
|
+
end
|
4
80
|
|
5
81
|
end
|
6
82
|
end
|
data/lib/puppetbox/driver.rb
CHANGED
@@ -1,31 +1,20 @@
|
|
1
1
|
module PuppetBox
|
2
|
-
|
3
|
-
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
def self.close()
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.puppet_apply_x2(puppet_class)
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.log_error()
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.log_debug()
|
27
|
-
end
|
28
|
-
|
2
|
+
# New drivers must implement the methods in this class (via ductyping)
|
3
|
+
class Driver
|
4
|
+
# def initialize(name, keep_vm=true)
|
5
|
+
# end
|
6
|
+
#
|
7
|
+
# def self.open()
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def self.close()
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def self.selftest()
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def self.puppet_apply_x2(puppet_class)
|
17
|
+
# end
|
29
18
|
end
|
30
19
|
|
31
20
|
end
|
data/lib/puppetbox/logger.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "logger"
|
1
2
|
module PuppetBox
|
2
3
|
# Logger is a class to allow for stateful and separate logs between instances
|
3
4
|
# by passing in individual loggers on initialisation
|
@@ -7,7 +8,10 @@ module PuppetBox
|
|
7
8
|
if logger
|
8
9
|
@logger = logger
|
9
10
|
else
|
10
|
-
logger = Logger.new(STDOUT)
|
11
|
+
@logger = ::Logger.new(STDOUT)
|
12
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
13
|
+
"#{severity}: #{msg}"
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
data/lib/puppetbox/result.rb
CHANGED
@@ -18,7 +18,25 @@ module PuppetBox
|
|
18
18
|
@report = []
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
# 0: The run succeeded with no changes or failures; the system was already in the desired state.
|
22
|
+
# 1: The run failed, or wasn't attempted due to another run already in progress.
|
23
|
+
# 2: The run succeeded, and some resources were changed.
|
24
|
+
# 4: The run succeeded, and some resources failed.
|
25
|
+
# 6: The run succeeded, and included both changes and failures.
|
26
|
+
def report(status_code, messages)
|
27
|
+
status = PS_ERROR
|
28
|
+
if @report.empty?
|
29
|
+
# first run
|
30
|
+
if status_code == 0 or status_code == 2
|
31
|
+
status = PS_OK
|
32
|
+
end
|
33
|
+
else
|
34
|
+
if status_code == 0
|
35
|
+
status = PS_OK
|
36
|
+
elsif status_code == 2
|
37
|
+
status = PS_NOT_IDEMPOTENT
|
38
|
+
end
|
39
|
+
end
|
22
40
|
@report.push({:status => status, :messages => messages})
|
23
41
|
end
|
24
42
|
|
data/lib/puppetbox/version.rb
CHANGED
data/puppetbox.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vagrantomatic
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- geoff@geoffwilliams.me.uk
|