vagrant-opsworks 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.simplecov +7 -0
- data/.travis.yml +13 -0
- data/Gemfile +44 -0
- data/Guardfile +17 -0
- data/Thorfile +59 -0
- data/integration/Gemfile +11 -0
- data/integration/Vagrantfile +8 -0
- data/lib/berkshelf-monkey-patch.rb +26 -0
- data/lib/vagrant-opsworks/action/checkout_cookbooks.rb +71 -0
- data/lib/vagrant-opsworks/action/configure_berks.rb +26 -0
- data/lib/vagrant-opsworks/action/configure_chef.rb +28 -0
- data/lib/vagrant-opsworks/action/create_roles.rb +69 -0
- data/lib/vagrant-opsworks/action/inject_boxes.rb +44 -0
- data/lib/vagrant-opsworks/action/merge_cookbooks.rb +27 -0
- data/lib/vagrant-opsworks/action/setup_environment.rb +34 -0
- data/lib/vagrant-opsworks/action.rb +51 -0
- data/lib/vagrant-opsworks/application.rb +26 -0
- data/lib/vagrant-opsworks/client/app.rb +50 -0
- data/lib/vagrant-opsworks/client/instance.rb +23 -0
- data/lib/vagrant-opsworks/client/layer.rb +39 -0
- data/lib/vagrant-opsworks/client/stack.rb +47 -0
- data/lib/vagrant-opsworks/client.rb +46 -0
- data/lib/vagrant-opsworks/client_old.rb +94 -0
- data/lib/vagrant-opsworks/config.rb +156 -0
- data/lib/vagrant-opsworks/custom_json.rb +22 -0
- data/lib/vagrant-opsworks/env.rb +19 -0
- data/lib/vagrant-opsworks/env_old.rb +162 -0
- data/lib/vagrant-opsworks/errors.rb +13 -0
- data/lib/vagrant-opsworks/loader/client.rb +19 -0
- data/lib/vagrant-opsworks/loader/instances.rb +78 -0
- data/lib/vagrant-opsworks/loader/stack.rb +27 -0
- data/lib/vagrant-opsworks/loader.rb +24 -0
- data/lib/vagrant-opsworks/plugin.rb +32 -0
- data/lib/vagrant-opsworks/stack/app.rb +0 -0
- data/lib/vagrant-opsworks/stack/instance.rb +62 -0
- data/lib/vagrant-opsworks/stack/stack.rb +84 -0
- data/lib/vagrant-opsworks/stack.rb +20 -0
- data/lib/vagrant-opsworks/util/configuration_builder.rb +44 -0
- data/lib/vagrant-opsworks/util/configuration_hash.rb +27 -0
- data/lib/vagrant-opsworks/util/dummy_configuration.rb +33 -0
- data/lib/vagrant-opsworks/util/env_helpers.rb +44 -0
- data/lib/vagrant-opsworks/version.rb +5 -0
- data/lib/vagrant-opsworks.rb +24 -0
- data/locales/en.yml +13 -0
- data/provisioning/client.yml +16 -0
- data/provisioning/install-agent.sh +75 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/unit/vagrant-opsworks/action/create_roles_spec.rb +5 -0
- data/spec/unit/vagrant-opsworks/config_spec.rb +109 -0
- data/vagrant-opsworks.gemspec +34 -0
- metadata +199 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins::OpsWorks::Loader
|
2
|
+
class Stack
|
3
|
+
|
4
|
+
def initialize(app, opsworks)
|
5
|
+
@app = app
|
6
|
+
@opsworks = opsworks
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
return @app.pass(env) unless @opsworks.enabled
|
11
|
+
|
12
|
+
VagrantPlugins::OpsWorks::Loader.select_vmbox(env[:config], env[:client].stack.default_os)
|
13
|
+
|
14
|
+
env[:config].vm.provision :shell do |s|
|
15
|
+
s.inline = File.read(VagrantPlugins::OpsWorks.source_root.join('provisioning/install-agent.sh'))
|
16
|
+
s.args = [@opsworks.agent_version, @opsworks.agent_bucket, @opsworks.asset_bucket]
|
17
|
+
end
|
18
|
+
|
19
|
+
env[:config].vm.provision :shell do |s|
|
20
|
+
s.inline = "DEBIAN_FRONTEND=noninteractive apt-get -qq install acl &&setfacl -m o:rw $SSH_AUTH_SOCK && setfacl -m o:x $(dirname $SSH_AUTH_SOCK)"
|
21
|
+
end
|
22
|
+
|
23
|
+
@app.pass(env)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OpsWorks
|
3
|
+
module Loader
|
4
|
+
require_relative 'loader/client'
|
5
|
+
require_relative 'loader/stack'
|
6
|
+
require_relative 'loader/instances'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def select_vmbox(config, os)
|
11
|
+
suffix = /x86_64/ =~ RUBY_PLATFORM ? '' : '-i386'
|
12
|
+
case os
|
13
|
+
when /^Ubuntu/
|
14
|
+
version = os.split(' ')[1]
|
15
|
+
config.vm.box = "chef/ubuntu-#{version}#{suffix}"
|
16
|
+
else
|
17
|
+
config.vm.box = "chef/centos-6.5#{suffix}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OpsWorks
|
3
|
+
class Plugin < ::Vagrant.plugin('2')
|
4
|
+
require_relative 'action'
|
5
|
+
|
6
|
+
name 'OpsWorks'
|
7
|
+
description 'A Vagrant plugin to provision a stack configured in Amazon OpsWorks'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def provision(hook)
|
11
|
+
require 'berkshelf/vagrant/env_helpers'
|
12
|
+
require 'berkshelf/vagrant/action/configure_chef'
|
13
|
+
hook.prepend(VagrantPlugins::OpsWorks::Action.configure_berks)
|
14
|
+
|
15
|
+
hook.before(::Vagrant::Action::Builtin::ConfigValidate, VagrantPlugins::OpsWorks::Action.setup)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
action_hook(:opsworks_setup, :environment_load) do |hook|
|
20
|
+
hook.append(VagrantPlugins::OpsWorks::Action.prepare_environment)
|
21
|
+
end
|
22
|
+
|
23
|
+
action_hook(:opsworks_provision, :machine_action_up, &method(:provision))
|
24
|
+
action_hook(:opsworks_provision, :machine_action_reload, &method(:provision))
|
25
|
+
action_hook(:opsworks_provision, :machine_action_provision, &method(:provision))
|
26
|
+
|
27
|
+
config(:opsworks) do
|
28
|
+
Config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OpsWorks
|
3
|
+
module Stack
|
4
|
+
class Instance
|
5
|
+
include VagrantPlugins::OpsWorks::Stack
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
# hostname of the instance
|
9
|
+
attr_reader :hostname
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
# operating system of the instance
|
13
|
+
attr_reader :os
|
14
|
+
|
15
|
+
def initialize(opsworks, config)
|
16
|
+
@opsworks = opsworks
|
17
|
+
@hostname = config[:hostname]
|
18
|
+
@os = config[:os]
|
19
|
+
@layers = config[:layer_ids]
|
20
|
+
end
|
21
|
+
|
22
|
+
def roles
|
23
|
+
layers.map{|l| l[:shortname]}
|
24
|
+
end
|
25
|
+
|
26
|
+
def packages
|
27
|
+
layers.map{|l| l[:packages]}.flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def layers
|
31
|
+
@opsworks.layers.select{|l|
|
32
|
+
@layers.include?(l[:layer_id]) && !@opsworks.ignore_layers.include?(l[:shortname])
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_proc
|
37
|
+
return Proc.new { |config|
|
38
|
+
config.vm.define @hostname do |node|
|
39
|
+
node.vm.hostname = "#{@hostname}#{@opsworks.hostname_suffix}"
|
40
|
+
select_vmbox(node, @os)
|
41
|
+
|
42
|
+
#node.vm.provision :shell, inline: "DEBIAN_FRONTEND=noninteractive apt-get -qq install #{packages.join(' ')}"
|
43
|
+
|
44
|
+
node.vm.provision :chef_solo do |chef|
|
45
|
+
roles.each{|role| chef.add_role role }
|
46
|
+
#chef.add_recipe 'hadoop'
|
47
|
+
pkgs = packages.map{|x| [x, nil]}.to_h
|
48
|
+
custom_json = @opsworks.stack.custom_json
|
49
|
+
custom_json[:dependencies] = {} unless custom_json.has_key?(:dependencies)
|
50
|
+
custom_json[:dependencies][:debs] = {} unless custom_json[:dependencies].has_key?(:debs)
|
51
|
+
custom_json[:dependencies][:debs].merge!(pkgs)
|
52
|
+
custom_json[:deploy]['rc2010'][:scm][:revision] = 'master'
|
53
|
+
chef.json = custom_json
|
54
|
+
end
|
55
|
+
end
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OpsWorks
|
3
|
+
module Stack
|
4
|
+
class Stack
|
5
|
+
include VagrantPlugins::OpsWorks::Stack
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(opsworks, config)
|
11
|
+
@opsworks = opsworks
|
12
|
+
@name = config[:name]
|
13
|
+
@custom_json = config[:custom_json]
|
14
|
+
@os = config[:default_os]
|
15
|
+
@custom_cookbooks = config[:use_custom_cookbooks]
|
16
|
+
@configuration_manager = config[:configuration_manager]
|
17
|
+
@chef_configuration = config[:chef_configuration]
|
18
|
+
@cookbooks_source = config[:custom_cookbooks_source]
|
19
|
+
end
|
20
|
+
|
21
|
+
def berks_enabled?
|
22
|
+
@chef_configuration[:manage_berkshelf]
|
23
|
+
end
|
24
|
+
|
25
|
+
def custom_cookbooks?
|
26
|
+
@custom_cookbooks
|
27
|
+
end
|
28
|
+
|
29
|
+
def custom_cookbooks
|
30
|
+
case @cookbooks_source[:type]
|
31
|
+
when 'git'
|
32
|
+
{
|
33
|
+
:type => 'git',
|
34
|
+
:url => @cookbooks_source[:url],
|
35
|
+
:ref => @cookbooks_source[:revision]
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def opsworks_cookbooks
|
41
|
+
{
|
42
|
+
:url => 'git@github.com:aws/opsworks-cookbooks.git',
|
43
|
+
:ref => "release-chef-#{@configuration_manager[:version]}"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Hash]
|
48
|
+
def custom_json
|
49
|
+
merge_hash(merge_hash({:deploy => @opsworks.apps}, JSON.parse(@custom_json)), @opsworks.supplimental_json)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_proc
|
53
|
+
return Proc.new { |config|
|
54
|
+
select_vmbox(config, @os)
|
55
|
+
|
56
|
+
config.vm.provision :shell, inline: File.read(VagrantPlugins::OpsWorks.source_root.join('provisioning/install-agent.sh')), args: [@opsworks.agent_version, @opsworks.agent_bucket, @opsworks.asset_bucket]
|
57
|
+
|
58
|
+
# Fix ssh agent forwarding for sudo as a non privileged user
|
59
|
+
# TODO: incorporate the modified template to prevent $SSH_AUTH_SOCK from being reset
|
60
|
+
# TODO: inject this into chef so it can run after the user is created
|
61
|
+
config.vm.provision :shell, inline: "DEBIAN_FRONTEND=noninteractive apt-get -qq install acl"
|
62
|
+
config.vm.provision :shell, inline: "cat /etc/passwd | awk -F':' '{ print $1 }' | grep deploy && setfacl -m u:deploy:rw $SSH_AUTH_SOCK && setfacl -m u:deploy:x $(dirname $SSH_AUTH_SOCK) || true", run: "always"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def merge_hash(old, new)
|
69
|
+
new.each_pair{|current_key,new_value|
|
70
|
+
old_value = old[current_key]
|
71
|
+
|
72
|
+
old[current_key] = if old_value.is_a?(Hash) && new_value.is_a?(Hash)
|
73
|
+
merge_hash(old_value, new_value)
|
74
|
+
else
|
75
|
+
new_value
|
76
|
+
end
|
77
|
+
}
|
78
|
+
old
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OpsWorks
|
3
|
+
module Stack
|
4
|
+
require_relative 'stack/stack'
|
5
|
+
require_relative 'stack/instance'
|
6
|
+
|
7
|
+
def select_vmbox(config, os)
|
8
|
+
suffix = /x86_64/ =~ RUBY_PLATFORM ? '' : '-i386'
|
9
|
+
case os
|
10
|
+
when /^Ubuntu/
|
11
|
+
version = os.split(' ')[1]
|
12
|
+
config.vm.box = "chef/ubuntu-#{version}#{suffix}"
|
13
|
+
else
|
14
|
+
config.vm.box = "chef/centos-6.5#{suffix}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module VagrantPlugins::OpsWorks::Util
|
2
|
+
class ConfigurationBuilder
|
3
|
+
|
4
|
+
# @return [Array]
|
5
|
+
attr_reader :stack
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@opsworks = config
|
9
|
+
@runner = ::Vagrant::Action::Runner.new({:action_name => :opsworks_configuration})
|
10
|
+
@stack = []
|
11
|
+
@env = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def use(loader, *args, &block)
|
15
|
+
self.stack << finalize_loader(loader, args, block)
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(config)
|
21
|
+
@env.merge!({:config => config})
|
22
|
+
pass(@env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def pass(env)
|
26
|
+
loader = @stack.shift
|
27
|
+
@runner.run(loader, env) if loader
|
28
|
+
end
|
29
|
+
|
30
|
+
def finalize_loader(klass, args, block)
|
31
|
+
args ||= []
|
32
|
+
|
33
|
+
if klass.is_a?(Class)
|
34
|
+
klass.new(self, @opsworks, *args, &block)
|
35
|
+
elsif klass.respond_to?(:call)
|
36
|
+
lambda do |e|
|
37
|
+
klass.call(e)
|
38
|
+
self.call(e)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'vagrant/util/hash_with_indifferent_access'
|
2
|
+
|
3
|
+
module VagrantPlugins::OpsWorks::Util
|
4
|
+
class DummyConfiguration < ::Vagrant::Util::HashWithIndifferentAccess
|
5
|
+
|
6
|
+
def method_missing(m, *args, &block)
|
7
|
+
Proxy.new
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_or_return(key, value)
|
13
|
+
if value.nil?
|
14
|
+
return self[key]
|
15
|
+
else
|
16
|
+
self[key] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Proxy
|
21
|
+
def method_missing(m, *args, &block)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'vagrant/util/hash_with_indifferent_access'
|
2
|
+
|
3
|
+
module VagrantPlugins::OpsWorks::Util
|
4
|
+
class DummyConfiguration < ::Vagrant::Util::HashWithIndifferentAccess
|
5
|
+
|
6
|
+
def initialize(response={})
|
7
|
+
response.each do |k,v|
|
8
|
+
send(k, v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(m, *args, &block)
|
13
|
+
Proxy.new
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_or_return(key, value)
|
19
|
+
if value.nil?
|
20
|
+
return self[key]
|
21
|
+
else
|
22
|
+
self[key] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Proxy
|
27
|
+
def method_missing(m, *args, &block)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module VagrantPlugins::OpsWorks::Util
|
2
|
+
module EnvHelpers
|
3
|
+
|
4
|
+
def enabled?(env)
|
5
|
+
opsworks_config(env).enabled
|
6
|
+
end
|
7
|
+
|
8
|
+
def provisioners(name, env)
|
9
|
+
env[:machine].config.vm.provisioners.select { |p| p.name == name }
|
10
|
+
end
|
11
|
+
|
12
|
+
def chef_solo?(env)
|
13
|
+
provisioners(:chef_solo, env).any?
|
14
|
+
end
|
15
|
+
|
16
|
+
def stack_id(env)
|
17
|
+
opsworks_config(env).stack_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def opsworks_config(env)
|
21
|
+
config(env).opsworks
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def config(env)
|
27
|
+
if env.has_key?(:env)
|
28
|
+
config, _ = env[:env].config_loader.load([:home, :root])
|
29
|
+
elsif env.has_key?(:machine)
|
30
|
+
config = env[:machine].config
|
31
|
+
end
|
32
|
+
config
|
33
|
+
end
|
34
|
+
|
35
|
+
def environment(env)
|
36
|
+
if env.has_key?(:env)
|
37
|
+
env[:env]
|
38
|
+
elsif env.has_key?(:machine)
|
39
|
+
env[:machine].env
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise 'The Vagrant OpsWorks plugin must be run within Vagrant.'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'berkshelf-monkey-patch'
|
8
|
+
|
9
|
+
I18n.load_path << File.expand_path('../../locales/en.yml', __FILE__)
|
10
|
+
|
11
|
+
require 'vagrant-opsworks/version'
|
12
|
+
require 'vagrant-opsworks/config'
|
13
|
+
require 'vagrant-opsworks/errors'
|
14
|
+
require 'vagrant-opsworks/plugin'
|
15
|
+
|
16
|
+
module VagrantPlugins
|
17
|
+
module OpsWorks
|
18
|
+
class << self
|
19
|
+
def source_root
|
20
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_opsworks:
|
3
|
+
action:
|
4
|
+
cookbooks:
|
5
|
+
checkout: "Checking out %{repo_name} from %{repo_url} with revision %{ref}..."
|
6
|
+
config:
|
7
|
+
not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
|
8
|
+
environment:
|
9
|
+
cache_dir: "OpsWorks Cache Directory: %{cache_dir}"
|
10
|
+
stack_id: "OpsWorks Stack ID: %{stack_id}"
|
11
|
+
errors:
|
12
|
+
connect: "Failed to connect to OpsWorks API"
|
13
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# opsworks chef client config file
|
2
|
+
# /var/lib/aws/opsworks/client.yml
|
3
|
+
---
|
4
|
+
|
5
|
+
:local_mode: true
|
6
|
+
:log_level: :info
|
7
|
+
:ohai_plugin_path: /opt/aws/opsworks/current/plugins
|
8
|
+
:cookbook_path: ["/opt/aws/opsworks/current/merged-cookbooks"]
|
9
|
+
:default_cookbooks_path: /opt/aws/opsworks/current/cookbooks
|
10
|
+
:site_cookbooks_path: /opt/aws/opsworks/current/site-cookbooks
|
11
|
+
:merged_cookbooks_path: /opt/aws/opsworks/current/merged-cookbooks
|
12
|
+
:berkshelf_cookbooks_path: /opt/aws/opsworks/current/berkshelf-cookbooks
|
13
|
+
:berkshelf_cache_path: /var/lib/aws/opsworks/berkshelf_cache
|
14
|
+
:file_cache_path: /var/lib/aws/opsworks/cache
|
15
|
+
:search_nodes_path: /var/lib/aws/opsworks/data/nodes
|
16
|
+
:data_bag_path: /var/lib/aws/opsworks/data/data_bags
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
[[ ! -e "/opt/aws/opsworks" ]] || exit 0
|
4
|
+
|
5
|
+
OPSWORKS_VERSION=$1
|
6
|
+
OPSWORKS_AGENT_BUCKET=$2
|
7
|
+
OPSWORKS_ASSETS_BUCKET=$3
|
8
|
+
|
9
|
+
WORKING_DIR=$(mktemp -d 'opsworks-agent.XXXXXXXX')
|
10
|
+
|
11
|
+
DEBIAN_FRONTEND=noninteractive apt-get -qq update
|
12
|
+
DEBIAN_FRONTEND=noninteractive apt-get -qq install curl libxml2-dev libxslt-dev libyaml-dev
|
13
|
+
|
14
|
+
mkdir -p /{etc,opt,var/log,var/lib}/aws/opsworks /var/lib/cloud
|
15
|
+
|
16
|
+
cat <<EOF > /var/lib/aws/opsworks/client.yml
|
17
|
+
# opsworks chef client config file
|
18
|
+
# /var/lib/aws/opsworks/client.yml
|
19
|
+
---
|
20
|
+
|
21
|
+
:local_mode: true
|
22
|
+
:log_level: :info
|
23
|
+
:ohai_plugin_path: /opt/aws/opsworks/current/plugins
|
24
|
+
:cookbook_path: ["/opt/aws/opsworks/current/merged-cookbooks"]
|
25
|
+
:default_cookbooks_path: /opt/aws/opsworks/current/cookbooks
|
26
|
+
:site_cookbooks_path: /opt/aws/opsworks/current/site-cookbooks
|
27
|
+
:merged_cookbooks_path: /opt/aws/opsworks/current/merged-cookbooks
|
28
|
+
:berkshelf_cookbooks_path: /opt/aws/opsworks/current/berkshelf-cookbooks
|
29
|
+
:berkshelf_cache_path: /var/lib/aws/opsworks/berkshelf_cache
|
30
|
+
:file_cache_path: /var/lib/aws/opsworks/cache
|
31
|
+
:search_nodes_path: /var/lib/aws/opsworks/data/nodes
|
32
|
+
:data_bag_path: /var/lib/aws/opsworks/data/data_bags
|
33
|
+
EOF
|
34
|
+
|
35
|
+
ssh-keygen -f "${WORKING_DIR}/instance_key_rsa" -t rsa -N ''
|
36
|
+
|
37
|
+
cat <<EOF > /var/lib/aws/opsworks/pre_config.yml
|
38
|
+
# opsworks-agent pre-config file
|
39
|
+
# /var/lib/aws/opsworks/pre_config.yml
|
40
|
+
---
|
41
|
+
|
42
|
+
:hostname: `hostname`
|
43
|
+
:identity: `uuidgen`
|
44
|
+
:agent_installer_base_url: ${OPSWORKS_AGENT_BUCKET}
|
45
|
+
:agent_installer_tgz: opsworks-agent-installer.tgz
|
46
|
+
:verbose: false
|
47
|
+
:instance_service_region: us-east-1
|
48
|
+
:instance_service_endpoint: localhost
|
49
|
+
:instance_service_port: '65535'
|
50
|
+
:instance_public_key: |
|
51
|
+
`openssl rsa -in /etc/ssh/ssh_host_rsa_key -pubout | sed -e 's/^/ /'`
|
52
|
+
:instance_private_key: |
|
53
|
+
`sed -e 's/^/ /' /etc/ssh/ssh_host_rsa_key`
|
54
|
+
:charlie_public_key: |
|
55
|
+
-----BEGIN PUBLIC KEY-----
|
56
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAni7eKdm34oaCvGiw96Fk
|
57
|
+
lyLX+aPfInYzilkk+AY3pXF6nijpQ2cm3ZeM2EoqZFTv3a/meosNBAs3Q3Sy1e4G
|
58
|
+
7Ibn/xwMof+iSBvimx3PGKFzNP0BhY9yS6AMEMxtmqksHb0glwmFeJcomdhxZV1F
|
59
|
+
ziWTtL6ZEyvCg0I7rxGm1ceQmD25eK90VcZVh4LJtNfnwcZRM4eC+KK9Qllxw5hW
|
60
|
+
vB4Z52JMMZbEG9MYCLydWSY9rnVkAyQ0ngJUaJ3q7JsbkBV/J5BcrGgcbioR1k+h
|
61
|
+
INRoHwBQU9WnT/x8W+N6vwJb4o6v2hBR1H2GSDLwyZ7wC8EVH+XafWYpU1g/nSEe
|
62
|
+
aQIDAQAB
|
63
|
+
-----END PUBLIC KEY-----
|
64
|
+
:wait_between_runs: '60'
|
65
|
+
EOF
|
66
|
+
|
67
|
+
wget -nv "https://${OPSWORKS_AGENT_BUCKET}/${OPSWORKS_VERSION}/opsworks-agent-installer.tgz" -P "${WORKING_DIR}"
|
68
|
+
tar xzpof "${WORKING_DIR}/opsworks-agent-installer.tgz" -C "${WORKING_DIR}"
|
69
|
+
${WORKING_DIR}/opsworks-agent-installer/opsworks-agent/bin/installer_wrapper.sh -R ${OPSWORKS_ASSETS_BUCKET}
|
70
|
+
|
71
|
+
echo 'export PATH=$PATH:/opt/aws/opsworks/current/bin' > /etc/profile.d/opsworks_path.sh
|
72
|
+
|
73
|
+
rm -f /etc/monit.d/opsworks-agent.monitrc /etc/monit/conf.d/opsworks-agent.monitrc
|
74
|
+
|
75
|
+
rm -rf ${WORKING_DIR}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'spork'
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
Spork.prefork do
|
7
|
+
require 'simplecov' unless ENV['DRB']
|
8
|
+
require 'rspec'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run focus: true
|
14
|
+
|
15
|
+
config.order = 'random'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Spork.each_run do
|
20
|
+
require 'simplecov' if ENV['DRB']
|
21
|
+
|
22
|
+
require 'vagrant-opsworks'
|
23
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VagrantPlugins::OpsWorks::Config do
|
4
|
+
let(:unset_value) { described_class::UNSET_VALUE }
|
5
|
+
subject { described_class.new.tap { |s| s.finalize! } }
|
6
|
+
|
7
|
+
context 'when enabled is not set' do
|
8
|
+
before(:each) do
|
9
|
+
subject.enabled = unset_value
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when stack_id is not set' do
|
13
|
+
before do
|
14
|
+
subject.stack_id = unset_value
|
15
|
+
subject.finalize!
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'it sets the value of enabled to false' do
|
19
|
+
subject.enabled.should be false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when stack_id is set' do
|
24
|
+
before do
|
25
|
+
subject.stack_id = 'foo'
|
26
|
+
subject.finalize!
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'it sets the value of enabled to true' do
|
30
|
+
subject.enabled.should be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when enabled is set' do
|
36
|
+
let(:enabled) { 'foo' }
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
subject.enabled = enabled
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when stack_id is not set' do
|
43
|
+
before do
|
44
|
+
subject.stack_id = unset_value
|
45
|
+
subject.finalize!
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'the value of enable should remain unchanged' do
|
49
|
+
subject.enabled.should == enabled
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when stack_id is set' do
|
54
|
+
before do
|
55
|
+
subject.stack_id = 'foo'
|
56
|
+
subject.finalize!
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'it sets the value of enabled to true' do
|
60
|
+
subject.enabled.should == enabled
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#validate" do
|
66
|
+
let(:env) { double('env', root_path: Dir.pwd) }
|
67
|
+
let(:config) { double('config', opsworks: subject) }
|
68
|
+
let(:machine) { double('machine', config: config, env: env) }
|
69
|
+
|
70
|
+
before do
|
71
|
+
subject.finalize!
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when the plugin is enabled' do
|
75
|
+
before(:each) do
|
76
|
+
subject.stub(enabled: true)
|
77
|
+
env.stub_chain(:vagrantfile, :config, :vm, :provisioners, :any?)
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:result) { subject.validate(machine) }
|
81
|
+
|
82
|
+
it "returns a Hash with an 'opsworks configuration' key" do
|
83
|
+
result.should be_a(Hash)
|
84
|
+
result.should have_key("opsworks configuration")
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when all validations pass' do
|
88
|
+
it "contains an empty Array for the 'opsworks configuration' key" do
|
89
|
+
result["opsworks configuration"].should be_a(Array)
|
90
|
+
result["opsworks configuration"].should be_empty
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when the plugin is disabled' do
|
96
|
+
let(:machine) { double('machine', env: env) }
|
97
|
+
|
98
|
+
before do
|
99
|
+
subject.stub(enabled: false)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'does not perform any validations' do
|
103
|
+
machine.should_not_receive(:config)
|
104
|
+
|
105
|
+
subject.validate(machine)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|