vagrant-config_builder 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +3 -0
- data/.yardopts +5 -0
- data/CHANGELOG +7 -0
- data/Gemfile +2 -0
- data/docs/GettingStarted.markdown +175 -0
- data/lib/config_builder/model.rb +1 -0
- data/lib/config_builder/model/provider/vmware_fusion.rb +36 -0
- data/lib/config_builder/version.rb +1 -1
- data/spec/config_builder/model/provider/vmware_fusion_spec.rb +29 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzdiNDExYzFlYThhOWYwZDUyNGYzMWUzMDEwZDc3MTNmMDIwNjQ1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTk1ZDczYzU4ZjhlOGI5YjIwMjE2ZmMzMTVjZjk1MjcyMDMyOTgwOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWJiOGMxNzI1N2M2NmZhY2NhN2E5MWM4ZGQyZjdiYjhmOWU4YjY5OGI0MTUx
|
10
|
+
ODYxMmQ4MjFhOTA1NjU3NzZhM2VhYTUyYTAzMTczODUwODk3OTcxZjYyNjhm
|
11
|
+
ZTdkZDE5MGE2MDRlN2U0NjJiM2EwNzFhNmYzMGI1YWMwYmY0Mzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGNjZGQ0MjRlOGUzMmQwODY2MGMyNDEyYmRjNWZjNWRhYjQ4MjVmYTBkNDcy
|
14
|
+
NTFiOWY0YjI2M2UzNTJhYjkzNmUwZjU2MDIxYWVjOTQ1MGZiYTkyM2U0Yzg3
|
15
|
+
OWIzNjg3NGQ3NWQxNDIzMzU1YmY2ZDZhY2EzOTU0NDUxYzMzMTg=
|
data/.gitignore
ADDED
data/.yardopts
ADDED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
@@ -7,6 +7,8 @@ group :development do
|
|
7
7
|
# gem dependency because we expect to be installed within the
|
8
8
|
# Vagrant environment itself using `vagrant plugin`.
|
9
9
|
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
10
|
+
gem "yard"
|
11
|
+
gem "redcarpet"
|
10
12
|
end
|
11
13
|
|
12
14
|
if File.exists? "#{__FILE__}.local"
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# @title Getting Started
|
2
|
+
|
3
|
+
# Getting Started
|
4
|
+
|
5
|
+
The vagrant-config_builder plugin is designed to ease the management of complex Vagrant setups.
|
6
|
+
This goal is accomplished by moving configuration data out of the Vagrant DSL and into formats that excel at expressing hierarchical information.
|
7
|
+
Moving the configuration to a dedicated data structure allows multiple VMs to be defined by composing and remixing a set of common components.
|
8
|
+
This guide describes:
|
9
|
+
|
10
|
+
- How to transition a Vagrant configuration to a ConfigBuilder data structure.
|
11
|
+
|
12
|
+
- How vagrant-config_builder maps that structure back to a Vagrant configuration.
|
13
|
+
|
14
|
+
- The methodology that vagrant-config_builder uses to manage components of configuration shared by multiple VMs.
|
15
|
+
|
16
|
+
|
17
|
+
## Expressing Configuration as Data
|
18
|
+
|
19
|
+
This guide will walk through re-implementing the following Vagrantfile using vagrant-config_builder:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# Vagrantfile
|
23
|
+
|
24
|
+
# Requires the following plugins:
|
25
|
+
#
|
26
|
+
# - vagrant-hosts
|
27
|
+
# - vagrant-auto_network
|
28
|
+
#
|
29
|
+
Vagrant.configure('2') do |config|
|
30
|
+
|
31
|
+
box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box'
|
32
|
+
box_name = 'centos-64-x64-vbox4210-nocm'
|
33
|
+
|
34
|
+
config.vm.define :puppetmaster do |node|
|
35
|
+
node.vm.box_url = box_url
|
36
|
+
node.vm.box = box_name
|
37
|
+
|
38
|
+
node.vm.hostname = 'puppetmaster.boxnet'
|
39
|
+
|
40
|
+
node.vm.network :private_network, :ip => '0.0.0.0', :auto_network => true
|
41
|
+
node.vm.provision :hosts
|
42
|
+
|
43
|
+
node.vm.provision :shell, :inline => <<-EOF
|
44
|
+
if which puppet > /dev/null 2>&1; then
|
45
|
+
echo 'Puppet Installed.'
|
46
|
+
else
|
47
|
+
echo 'Installing Puppet Master.'
|
48
|
+
rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
|
49
|
+
yum --nogpgcheck -y install puppet-server
|
50
|
+
echo '*.boxnet' > /etc/puppet/autosign.conf
|
51
|
+
/usr/bin/puppet resource service iptables ensure=stopped enable=false
|
52
|
+
/usr/bin/puppet resource service puppetmaster ensure=running enable=true
|
53
|
+
fi
|
54
|
+
EOF
|
55
|
+
end
|
56
|
+
|
57
|
+
config.vm.define :puppetagent do |node|
|
58
|
+
node.vm.box_url = box_url
|
59
|
+
node.vm.box = box_name
|
60
|
+
|
61
|
+
node.vm.hostname = 'puppetagent.boxnet'
|
62
|
+
|
63
|
+
node.vm.network :private_network, :ip => '0.0.0.0', :auto_network => true
|
64
|
+
node.vm.provision :hosts
|
65
|
+
|
66
|
+
node.vm.provision :shell, :inline => <<-EOF
|
67
|
+
if which puppet > /dev/null 2>&1; then
|
68
|
+
echo 'Puppet Installed.'
|
69
|
+
else
|
70
|
+
echo 'Installing Puppet Agent.'
|
71
|
+
rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
|
72
|
+
yum --nogpgcheck -y install puppet
|
73
|
+
fi
|
74
|
+
EOF
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
The above listing showcases several examples of duplicated configuration: both VMs are using the same Vagrant box, both are configuring their networks in the same way and both are provisioned using nearly identical shell scripts.
|
81
|
+
In fact, the only real difference between the VMs are the hostnames and the few lines of shell that install and configure the Puppet master instead or the Puppet agent.
|
82
|
+
These little bits of shared configuration pop up constantly in multi-machine Vagrant environments and are commonly handled by a combination of copy-and-paste and factoring out bits of data and configuration into variables or methods (such as `box_name` and `box_url` used above).
|
83
|
+
There are some significant drawbacks to this situation:
|
84
|
+
|
85
|
+
- Copy and paste quickly becomes expensive to maintain as the number of machines in the environment increases.
|
86
|
+
|
87
|
+
- Factoring configuration out to variables and methods can help, but requires care to produce something that is portable and reusable across environments.
|
88
|
+
|
89
|
+
- Determining which bits of configuration are shared among which machines is a challenging task to complete quickly and usually requires a careful reading of the Vagrantfile.
|
90
|
+
|
91
|
+
vagrant-config_builder approaches this problem by storing every bit of configuration in a unified data structure.
|
92
|
+
The structure can be loaded from any data source that is convertable to a hash such as YAML, JSON, XML (possibly [interpretive dance][oscar data sources]).
|
93
|
+
Generation of configuration hashes from data sources is implemented through the `ConfigBuilder::Loader` module and is completely pluggable.
|
94
|
+
This guide will use YAML as the configuration storage format as vagrant-config_builder includes a YAML Loader.
|
95
|
+
|
96
|
+
If the Vagrantfile above were to be translated to YAML, it would look like this:
|
97
|
+
|
98
|
+
```yaml
|
99
|
+
# config/vms.yaml
|
100
|
+
---
|
101
|
+
vms:
|
102
|
+
- name: puppetmaster
|
103
|
+
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
104
|
+
box: centos-64-x64-vbox4210-nocm
|
105
|
+
hostname: puppetmaster.boxnet
|
106
|
+
private_networks:
|
107
|
+
- {ip: 0.0.0.0, auto_network: true}
|
108
|
+
provisioners:
|
109
|
+
- type: hosts
|
110
|
+
- type: shell
|
111
|
+
inline: |
|
112
|
+
if which puppet > /dev/null 2>&1; then
|
113
|
+
echo 'Puppet Installed.'
|
114
|
+
else
|
115
|
+
echo 'Installing Puppet Master.'
|
116
|
+
rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
|
117
|
+
yum --nogpgcheck -y install puppet-server
|
118
|
+
echo '*.boxnet' > /etc/puppet/autosign.conf
|
119
|
+
/usr/bin/puppet resource service iptables ensure=stopped enable=false
|
120
|
+
/usr/bin/puppet resource service puppetmaster ensure=running enable=true
|
121
|
+
fi
|
122
|
+
|
123
|
+
- name: puppetagent
|
124
|
+
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
125
|
+
box: centos-64-x64-vbox4210-nocm
|
126
|
+
hostname: puppetagent.boxnet
|
127
|
+
private_networks:
|
128
|
+
- {ip: 0.0.0.0, auto_network: true}
|
129
|
+
provisioners:
|
130
|
+
- type: hosts
|
131
|
+
- type: shell
|
132
|
+
inline: |
|
133
|
+
if which puppet > /dev/null 2>&1; then
|
134
|
+
echo 'Puppet Installed.'
|
135
|
+
else
|
136
|
+
echo 'Installing Puppet Master.'
|
137
|
+
rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
|
138
|
+
yum --nogpgcheck -y install puppet
|
139
|
+
fi
|
140
|
+
```
|
141
|
+
The YAML configuration above maps very closely to the original Vagrant DSL.
|
142
|
+
The major differences are:
|
143
|
+
|
144
|
+
- Repetitive bits of syntax such as `config.vm.*` and `node.vm.*` are now expressed implicitly through the structure of the data.
|
145
|
+
|
146
|
+
- Operations that are executed multiple times are expressed as arrays. These are:
|
147
|
+
|
148
|
+
- Defining VMs.
|
149
|
+
|
150
|
+
- Defining network interfaces on VMs.
|
151
|
+
|
152
|
+
- Running provisioners on VMs.
|
153
|
+
|
154
|
+
The mapping between the ConfigBuilder data and the original Vagrantfile will be covered in detail in the next section.
|
155
|
+
With the YAML configuration saved in `config/vms.yaml`, the Vagrantfile can updated to invoke `ConfigBuilder.load`:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
# Vagrantfile
|
159
|
+
|
160
|
+
# Requires the following plugins:
|
161
|
+
#
|
162
|
+
# - vagrant-hosts
|
163
|
+
# - vagrant-auto_network
|
164
|
+
# - vagrant-config_builder
|
165
|
+
#
|
166
|
+
Vagrant.configure('2', &ConfigBuilder.load(
|
167
|
+
:yaml,
|
168
|
+
:yamldir,
|
169
|
+
File.expand_path('../config', __FILE__)
|
170
|
+
))
|
171
|
+
```
|
172
|
+
|
173
|
+
This calls the `yamldir` method of the YAML Loader and passes a path to a `config` directory located adjacent to the Vagrantfile.
|
174
|
+
|
175
|
+
[oscar data sources]: http://www.youtube.com/watch?v=1TgGQjjLDXg&t=19m27s
|
data/lib/config_builder/model.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# @see http://docs.vagrantup.com/v2/vmware/configuration.html
|
2
|
+
class ConfigBuilder::Model::Provider::VMwareFusion < ConfigBuilder::Model::Base
|
3
|
+
|
4
|
+
# @!attribute [rw] vmx
|
5
|
+
# @return [Hash<String, String>] A hash of VMX options for the given VM
|
6
|
+
# @example
|
7
|
+
# model.vmx = {
|
8
|
+
# 'memsize' => '1024',
|
9
|
+
# 'numvcpus' => '2',
|
10
|
+
# }
|
11
|
+
def_model_attribute :vmx
|
12
|
+
|
13
|
+
# @!attribute [rw] gui
|
14
|
+
# @return [Boolean] Whether the GUI should be launched when the VM is created
|
15
|
+
def_model_attribute :gui
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@defaults = {
|
19
|
+
:gui => false,
|
20
|
+
:vmx => {},
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_proc
|
25
|
+
Proc.new do |vm_config|
|
26
|
+
vm_config.provider 'vmware_fusion' do |fusion_config|
|
27
|
+
fusion_config.gui = attr(:gui)
|
28
|
+
attr(:vmx).each_pair do |key, value|
|
29
|
+
fusion_config.vmx[key] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ConfigBuilder::Model::Provider.register('vmware_fusion', self)
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'config_builder/model'
|
3
|
+
|
4
|
+
describe ConfigBuilder::Model::Provider::VMwareFusion do
|
5
|
+
describe "converting to a proc" do
|
6
|
+
|
7
|
+
let(:vmx) { Hash.new }
|
8
|
+
let(:fusion_config) { double('fusion provider config', :vmx => vmx) }
|
9
|
+
let(:vm_config) { double('vagrant VM config', :provider => fusion_config) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(vm_config).to receive(:provider).and_yield(fusion_config)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "assigns the gui value to the fusion provider object" do
|
16
|
+
subject.attrs = {:gui => 'guivalue'}
|
17
|
+
expect(fusion_config).to receive(:gui=).with('guivalue')
|
18
|
+
p = subject.to_proc
|
19
|
+
p.call(vm_config)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "assigns the vmx value to the fusion provider object" do
|
23
|
+
subject.attrs = {:vmx => {:hello => 'world'}}
|
24
|
+
allow(fusion_config).to receive(:gui=)
|
25
|
+
subject.call(vm_config)
|
26
|
+
expect(vmx).to eq({:hello => 'world'})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-config_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Thebo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -44,10 +44,13 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- .gitignore
|
48
|
+
- .yardopts
|
47
49
|
- CHANGELOG
|
48
50
|
- Gemfile
|
49
51
|
- LICENSE
|
50
52
|
- README.markdown
|
53
|
+
- docs/GettingStarted.markdown
|
51
54
|
- examples/Vagrantfile
|
52
55
|
- examples/roles.yaml
|
53
56
|
- examples/vms.yaml
|
@@ -66,6 +69,7 @@ files:
|
|
66
69
|
- lib/config_builder/model/network/forwarded_port.rb
|
67
70
|
- lib/config_builder/model/network/private_network.rb
|
68
71
|
- lib/config_builder/model/provider/virtualbox.rb
|
72
|
+
- lib/config_builder/model/provider/vmware_fusion.rb
|
69
73
|
- lib/config_builder/model/provisioner/puppet.rb
|
70
74
|
- lib/config_builder/model/provisioner/puppet_server.rb
|
71
75
|
- lib/config_builder/model/provisioner/shell.rb
|
@@ -81,6 +85,7 @@ files:
|
|
81
85
|
- spec/config_builder/filter/boxes_spec.rb
|
82
86
|
- spec/config_builder/filter/roles_spec.rb
|
83
87
|
- spec/config_builder/loader/yaml_spec.rb
|
88
|
+
- spec/config_builder/model/provider/vmware_fusion_spec.rb
|
84
89
|
- spec/spec_helper.rb
|
85
90
|
- templates/locales/en.yml
|
86
91
|
- vagrant-config_builder.gemspec
|