vagrant-lifecycle 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1adfe0fd188550f1ce0ae66be31da607e6f9eb70
4
- data.tar.gz: '082e1254bdc78785e15fd46a43d401769d9884c8'
3
+ metadata.gz: c7cba661db2ccbce052ecedd8c595e4d2fe10281
4
+ data.tar.gz: 8547b53d8ca47345faa5e59f28b836d7d4ed915b
5
5
  SHA512:
6
- metadata.gz: ec1d88ac133062baee4af4149098e3036ec6645f77654e6cb3ee8661ee7d91a3601a9e6342916406f4066c3a0cfd869e7acb9166e89884f5b3792c0f14a8c0cd
7
- data.tar.gz: ae2802b31cdb3010cd78131a19ed8cc38786cb03f149da7c1d621e1f87500efb33357e1d70e78969d7e0539188a5b7f352460177f4184efa7d317e16768a8f84
6
+ metadata.gz: a6ae430f852bce5e02cbf3f520611dfc529ea69a51e7ff6c16a630bdc4b870d088eb338b022ff50715c0d53bbaa1f2ae2ff2916ab0e7b5b67ab91ab28c38e7ce
7
+ data.tar.gz: 7b02208f54e5927cf85b32b806fbf14898df1a317dce1295760ecbbdc5c3ef7a9b25f66ecfa199d4d673dfe58ea77d1a93dcd601bcff7fa7f41f05b715083c07
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # vagrant-lifecycle Changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ Changed Vagrant action the plugin hooks to so it can be used together with vagrant-databags plugin (with guaranteed
6
+ order of execution).
7
+
3
8
  ## 0.1.3
4
9
 
5
10
  Added support for Chef Zero and Chef Client provisioners.
data/Gemfile.lock CHANGED
@@ -33,7 +33,7 @@ GIT
33
33
  PATH
34
34
  remote: .
35
35
  specs:
36
- vagrant-lifecycle (0.1.3)
36
+ vagrant-lifecycle (0.1.4)
37
37
 
38
38
  GEM
39
39
  remote: https://rubygems.org/
@@ -129,7 +129,7 @@ PLATFORMS
129
129
  ruby
130
130
 
131
131
  DEPENDENCIES
132
- bundler (~> 1.16)
132
+ bundler (~> 1.5)
133
133
  rake
134
134
  rspec
135
135
  spork
data/README.md CHANGED
@@ -179,4 +179,10 @@ Vagrant.configure("2") do |config|
179
179
  }
180
180
  }
181
181
  end
182
- ```
182
+ ```
183
+
184
+ #### Simulate OpsWorks stack
185
+
186
+ Both vagrant-lifecycle and [vagrant-databags](https://github.com/nstojiljkovic/vagrant-databags) plugins are required for
187
+ this example. Sample code is available in the
188
+ [vagrant-databags documentation](https://github.com/nstojiljkovic/vagrant-databags#simulate-opsworks-stack).
@@ -1,7 +1,7 @@
1
1
  require 'vagrant'
2
2
 
3
+ require_relative 'vagrant-lifecycle/action'
3
4
  require_relative 'vagrant-lifecycle/config'
4
- require_relative 'vagrant-lifecycle/middleware'
5
5
  require_relative 'vagrant-lifecycle/plugin'
6
6
  require_relative 'vagrant-lifecycle/version'
7
7
 
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+
3
+ module VagrantPlugins
4
+ module Lifecycle
5
+ module Action
6
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
7
+ autoload :EvalLifecycleRunList, action_root.join("eval_lifecycle_run_list")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,61 @@
1
+ module VagrantPlugins
2
+ module Lifecycle
3
+ module Action
4
+ class EvalLifecycleRunList
5
+ def initialize(app, env)
6
+ @app = app
7
+
8
+ klass = self.class.name.downcase.split('::').last
9
+ @logger = Log4r::Logger.new("vagrant::lifecycle::#{klass}")
10
+ end
11
+
12
+ def call(env)
13
+ event = env[:lifecycle_event] || env[:machine].config.lifecycle.default_event || nil
14
+
15
+ if event.nil?
16
+ @app.call(env)
17
+ else
18
+ chef_provisioners = env[:machine].config.vm.provisioners.select do |provisioner|
19
+ # Vagrant 1.7 changes provisioner.name to provisioner.type
20
+ if provisioner.respond_to? :type
21
+ provisioner.type.to_sym == :chef_solo || provisioner.type.to_sym == :chef_client || provisioner.type.to_sym == :chef_zero
22
+ else
23
+ provisioner.name.to_sym == :chef_solo || provisioner.name.to_sym == :chef_client || provisioner.name.to_sym == :chef_zero
24
+ end
25
+ end
26
+
27
+ # @type [Hash]
28
+ lifecycle_events = env[:machine].config.lifecycle.events
29
+
30
+ if lifecycle_events.key?(event) || lifecycle_events.key?(event.to_sym) || lifecycle_events.key?(event.to_s)
31
+ # @type [lambda]
32
+ event_lambda = lifecycle_events[event] || lifecycle_events[event.to_sym] || lifecycle_events[event.to_s]
33
+
34
+ chef_provisioners.each do |chef|
35
+ begin
36
+ new_run_list = event_lambda.call(chef.config.run_list || [], env)
37
+ @logger.debug "Setting run_list = #{new_run_list.inspect}"
38
+
39
+ if new_run_list.kind_of?(Array)
40
+ chef.config.run_list = new_run_list
41
+ else
42
+ env[:ui].error "Could not evaluate proper run list for the lifecycle event #{event}!"
43
+ env[:interrupted] = true
44
+ end
45
+ rescue Exception => e
46
+ env[:ui].error "Failed while evaluating run list for the event #{event} with error: #{e}"
47
+ env[:interrupted] = true
48
+ end
49
+ end
50
+ else
51
+ env[:ui].error "Lifecycle event #{event} not configured!"
52
+ env[:interrupted] = true
53
+ end
54
+
55
+ @app.call(env)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,6 +1,5 @@
1
1
  require 'vagrant-lifecycle/command'
2
2
  require 'vagrant-lifecycle/config'
3
- require 'vagrant-lifecycle/middleware'
4
3
  require 'vagrant-lifecycle/version'
5
4
 
6
5
  module VagrantPlugins
@@ -8,15 +7,10 @@ module VagrantPlugins
8
7
  class Plugin < Vagrant.plugin(2)
9
8
  name 'Lifecycle Plugin'
10
9
 
11
- def self.provision
12
- Vagrant::Action::Builder.new.tap do |b|
13
- b.use MiddleWare
14
- end
15
- end
16
-
17
10
  [:machine_action_up, :machine_action_reload, :machine_action_provision].each do |action|
18
11
  action_hook(:lifecycle_provision, action) do |hook|
19
- hook.before(Vagrant::Action::Builtin::Provision, Plugin.provision)
12
+ # contrary to how this might sound, this hook is run before :run_provisioner
13
+ hook.after Vagrant::Action::Builtin::Provision, Action::EvalLifecycleRunList
20
14
  end
21
15
  end
22
16
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Lifecycle
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Nikola Stojiljkovic"]
10
10
  spec.email = ["xection@gmail.com"]
11
11
 
12
- spec.summary = %q{Vagrant plugin to run custom Chef run list and filtered data bags during provisioning}
12
+ spec.summary = %q{Vagrant plugin to run custom Chef run list during provisioning}
13
13
  # spec.description = %q{TODO: Write a longer description or delete this line.}
14
14
  spec.homepage = "https://github.com/nstojiljkovic/vagrant-lifecycle"
15
15
  spec.license = "Apache-2.0"
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lifecycle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikola Stojiljkovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2018-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,9 +72,10 @@ files:
72
72
  - bin/console
73
73
  - bin/setup
74
74
  - lib/vagrant-lifecycle.rb
75
+ - lib/vagrant-lifecycle/action.rb
76
+ - lib/vagrant-lifecycle/action/eval_lifecycle_run_list.rb
75
77
  - lib/vagrant-lifecycle/command.rb
76
78
  - lib/vagrant-lifecycle/config.rb
77
- - lib/vagrant-lifecycle/middleware.rb
78
79
  - lib/vagrant-lifecycle/plugin.rb
79
80
  - lib/vagrant-lifecycle/version.rb
80
81
  - vagrant-lifecycle.gemspec
@@ -101,6 +102,5 @@ rubyforge_project:
101
102
  rubygems_version: 2.6.12
102
103
  signing_key:
103
104
  specification_version: 4
104
- summary: Vagrant plugin to run custom Chef run list and filtered data bags during
105
- provisioning
105
+ summary: Vagrant plugin to run custom Chef run list during provisioning
106
106
  test_files: []
@@ -1,59 +0,0 @@
1
- module VagrantPlugins
2
- module Lifecycle
3
- class MiddleWare
4
- def initialize(app, env)
5
- @app = app
6
-
7
- klass = self.class.name.downcase.split('::').last
8
- @logger = Log4r::Logger.new("vagrant::lifecycle::#{klass}")
9
- end
10
-
11
- def call(env)
12
- event = env[:lifecycle_event] || env[:machine].config.lifecycle.default_event || nil
13
-
14
- if event.nil?
15
- @app.call(env)
16
- else
17
- chef_provisioners = env[:machine].config.vm.provisioners.select do |provisioner|
18
- # Vagrant 1.7 changes provisioner.name to provisioner.type
19
- if provisioner.respond_to? :type
20
- provisioner.type.to_sym == :chef_solo || provisioner.type.to_sym == :chef_client || provisioner.type.to_sym == :chef_zero
21
- else
22
- provisioner.name.to_sym == :chef_solo || provisioner.name.to_sym == :chef_client || provisioner.name.to_sym == :chef_zero
23
- end
24
- end
25
-
26
- # @type [Hash]
27
- lifecycle_events = env[:machine].config.lifecycle.events
28
-
29
- if lifecycle_events.key?(event) || lifecycle_events.key?(event.to_sym) || lifecycle_events.key?(event.to_s)
30
- # @type [lambda]
31
- event_lambda = lifecycle_events[event] || lifecycle_events[event.to_sym] || lifecycle_events[event.to_s]
32
-
33
- chef_provisioners.each do |chef|
34
- begin
35
- new_run_list = event_lambda.call(chef.config.run_list || [], env)
36
- @logger.debug "Setting run_list = #{new_run_list.inspect}"
37
-
38
- if new_run_list.kind_of?(Array)
39
- chef.config.run_list = new_run_list
40
- else
41
- env[:ui].error "Could not evaluate proper run list for the lifecycle event #{event}!"
42
- env[:interrupted] = true
43
- end
44
- rescue Exception => e
45
- env[:ui].error "Failed while evaluating run list for the event #{event} with error: #{e}"
46
- env[:interrupted] = true
47
- end
48
- end
49
- else
50
- env[:ui].error "Lifecycle event #{event} not configured!"
51
- env[:interrupted] = true
52
- end
53
-
54
- @app.call(env)
55
- end
56
- end
57
- end
58
- end
59
- end