vagrant-lifecycle 0.1.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: acc3f9c22d171906e4d9441cfa09c9b4ddcb2d14
4
+ data.tar.gz: 739256ae5085416d0412adc1024e1593e1f550c8
5
+ SHA512:
6
+ metadata.gz: b321d9b9b04872e632cbfef4add27da35520219170d79a054989c764244a7564ec7c657c941084385d5ae705442a3e43572dbf5832789fa422ddcbf256723242
7
+ data.tar.gz: da3743042710113cd2082bf714db0c41eb7556e113512140b853899679ca708a4c81a130371812fc3e5ee7d18c667e05ce92c99d246f8db33a743ba52e2391fc
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+ /*.gem
11
+ /*.iml
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+
5
+ branches:
6
+ only:
7
+ master
8
+
9
+ matrix:
10
+ include:
11
+ - rvm: 2.2.8
12
+ - rvm: 2.3.5
13
+ - rvm: 2.4.2
14
+
15
+ script: bundle exec rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # vagrant-lifecycle Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Contribution Process
2
+
3
+ Process for contributions:
4
+
5
+ 1. Fork this GitHub repo and commit changes to a git branch.
6
+ 2. Create a GitHub Pull Request for your change.
7
+ 3. Perform a Code Review on the pull request.
8
+
9
+ By submitting the pull request you confirm that your submission is licensed under Apache License Version 2.0.
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ # git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ group :plugins do
6
+ # Dependencies need to be specified in vagrant-lifecycle.gemspec
7
+ gemspec
8
+ end
9
+
10
+ group :development do
11
+ # We depend on Vagrant for development, but we don't add it as a
12
+ # gem dependency because we expect to be installed within the
13
+ # Vagrant environment itself using `vagrant plugin`.
14
+ gem 'vagrant', git: "https://github.com/mitchellh/vagrant.git"
15
+ gem 'vagrant-spec', git: "https://github.com/mitchellh/vagrant-spec.git"
16
+ gem 'spork'
17
+ gem 'rspec'
18
+ gem 'rake'
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,141 @@
1
+ GIT
2
+ remote: https://github.com/mitchellh/vagrant-spec.git
3
+ revision: 9413ab298407114528766efefd1fb1ff24589636
4
+ specs:
5
+ vagrant-spec (0.0.1)
6
+ childprocess (~> 0.6.0)
7
+ log4r (~> 1.1.9)
8
+ rspec (~> 3.5.0)
9
+ thor (~> 0.18.1)
10
+
11
+ GIT
12
+ remote: https://github.com/mitchellh/vagrant.git
13
+ revision: 2c24bcc433f327d2104050ad3a062454f97979dc
14
+ specs:
15
+ vagrant (2.1.2.dev)
16
+ childprocess (~> 0.6.0)
17
+ erubis (~> 2.7.0)
18
+ hashicorp-checkpoint (~> 0.1.5)
19
+ i18n (>= 0.6.0, <= 0.8.0)
20
+ listen (~> 3.1.5)
21
+ log4r (~> 1.1.9, < 1.1.11)
22
+ net-scp (~> 1.2.0)
23
+ net-sftp (~> 2.1)
24
+ net-ssh (~> 4.2.0)
25
+ rb-kqueue (~> 0.2.0)
26
+ rest-client (>= 1.6.0, < 3.0)
27
+ ruby_dep (<= 1.3.1)
28
+ wdm (~> 0.1.0)
29
+ winrm (~> 2.1)
30
+ winrm-elevated (~> 1.1)
31
+ winrm-fs (~> 1.0)
32
+
33
+ PATH
34
+ remote: .
35
+ specs:
36
+ vagrant-lifecycle (0.1.0)
37
+
38
+ GEM
39
+ remote: https://rubygems.org/
40
+ specs:
41
+ builder (3.2.3)
42
+ childprocess (0.6.3)
43
+ ffi (~> 1.0, >= 1.0.11)
44
+ diff-lcs (1.3)
45
+ domain_name (0.5.20180417)
46
+ unf (>= 0.0.5, < 1.0.0)
47
+ erubis (2.7.0)
48
+ ffi (1.9.25)
49
+ gssapi (1.2.0)
50
+ ffi (>= 1.0.1)
51
+ gyoku (1.3.1)
52
+ builder (>= 2.1.2)
53
+ hashicorp-checkpoint (0.1.5)
54
+ http-cookie (1.0.3)
55
+ domain_name (~> 0.5)
56
+ httpclient (2.8.3)
57
+ i18n (0.8.0)
58
+ listen (3.1.5)
59
+ rb-fsevent (~> 0.9, >= 0.9.4)
60
+ rb-inotify (~> 0.9, >= 0.9.7)
61
+ ruby_dep (~> 1.2)
62
+ little-plugger (1.1.4)
63
+ log4r (1.1.10)
64
+ logging (2.2.2)
65
+ little-plugger (~> 1.1)
66
+ multi_json (~> 1.10)
67
+ mime-types (3.1)
68
+ mime-types-data (~> 3.2015)
69
+ mime-types-data (3.2016.0521)
70
+ multi_json (1.13.1)
71
+ net-scp (1.2.1)
72
+ net-ssh (>= 2.6.5)
73
+ net-sftp (2.1.2)
74
+ net-ssh (>= 2.6.5)
75
+ net-ssh (4.2.0)
76
+ netrc (0.11.0)
77
+ nori (2.6.0)
78
+ rake (10.5.0)
79
+ rb-fsevent (0.10.3)
80
+ rb-inotify (0.9.10)
81
+ ffi (>= 0.5.0, < 2)
82
+ rb-kqueue (0.2.5)
83
+ ffi (>= 0.5.0)
84
+ rest-client (2.0.2)
85
+ http-cookie (>= 1.0.2, < 2.0)
86
+ mime-types (>= 1.16, < 4.0)
87
+ netrc (~> 0.8)
88
+ rspec (3.5.0)
89
+ rspec-core (~> 3.5.0)
90
+ rspec-expectations (~> 3.5.0)
91
+ rspec-mocks (~> 3.5.0)
92
+ rspec-core (3.5.4)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-expectations (3.5.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-mocks (3.5.0)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.5.0)
100
+ rspec-support (3.5.0)
101
+ ruby_dep (1.3.1)
102
+ rubyntlm (0.6.2)
103
+ rubyzip (1.2.1)
104
+ spork (0.9.2)
105
+ thor (0.18.1)
106
+ unf (0.1.4)
107
+ unf_ext
108
+ unf_ext (0.0.7.5)
109
+ wdm (0.1.1)
110
+ winrm (2.2.3)
111
+ builder (>= 2.1.2)
112
+ erubis (~> 2.7)
113
+ gssapi (~> 1.2)
114
+ gyoku (~> 1.0)
115
+ httpclient (~> 2.2, >= 2.2.0.2)
116
+ logging (>= 1.6.1, < 3.0)
117
+ nori (~> 2.0)
118
+ rubyntlm (~> 0.6.0, >= 0.6.1)
119
+ winrm-elevated (1.1.0)
120
+ winrm (~> 2.0)
121
+ winrm-fs (~> 1.0)
122
+ winrm-fs (1.2.0)
123
+ erubis (~> 2.7)
124
+ logging (>= 1.6.1, < 3.0)
125
+ rubyzip (~> 1.1)
126
+ winrm (~> 2.0)
127
+
128
+ PLATFORMS
129
+ ruby
130
+
131
+ DEPENDENCIES
132
+ bundler (~> 1.16)
133
+ rake
134
+ rspec
135
+ spork
136
+ vagrant!
137
+ vagrant-lifecycle!
138
+ vagrant-spec!
139
+
140
+ BUNDLED WITH
141
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # Vagrant Lifecycle Plugin
2
+
3
+ Vagrant Lifecycle is a Vagrant plugin that allows execution of custom provisioning events for the Chef provisioners.
4
+
5
+ ## Installation
6
+
7
+ 1. Install the latest version of [Vagrant](https://www.vagrantup.com/downloads.html)
8
+ 2. Install the Vagrant Lifecycle plugin:
9
+
10
+ ```sh
11
+ $ vagrant plugin install vagrant-lifecycle
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Example Vagrantfile configuration section for Vagrant Lifecycle:
17
+
18
+ ```ruby
19
+ Vagrant.configure("2") do |config|
20
+ # Default lifecycle event.
21
+ # If set, the vagrant-lifecycle with alter the default vagrant provision run list.
22
+ config.lifecycle.default_event = :setup
23
+
24
+ # Lifecycle events configuration hash.
25
+ # Each event needs a lambda with 2 parameters run_list and env and should return the new run list
26
+ # Parameter env is vagrant-lifecycle plugin's middleware environment hash with various interesting keys:
27
+ # * env[:ui] is an instance of ::Vagrant::UI::Interface
28
+ # * env[:machine] is an instance of ::Vagrant::Machine etc.
29
+ config.lifecycle.events = {
30
+ :configure => lambda {|run_list, env|
31
+ run_list + ["recipe[sample_cookbook::configure]"]
32
+ },
33
+ :deploy => lambda {|run_list, env|
34
+ run_list + ["recipe[sample_cookbook::deploy]"]
35
+ },
36
+ :setup => lambda {|run_list, env|
37
+ run_list + ["recipe[sample_cookbook::setup]"]
38
+ }
39
+ }
40
+ end
41
+ ```
42
+
43
+ If you have configured the default_event, it will be run when you run provision the usual way:
44
+
45
+ ```bash
46
+ $ vagrant provision
47
+ ```
48
+
49
+ You can execute provisioning on the specific lifecycle event via command (for example for deploy event):
50
+
51
+ ```bash
52
+ $ vagrant lifecycle -e deploy
53
+ ```
54
+
55
+ ## More examples
56
+
57
+ ### Evaluate run list based on lifecycle event and node roles
58
+
59
+ Example Vagrantfile configuration section:
60
+
61
+ ```ruby
62
+ # Required for $LAST_MATCH_INFO used bellow
63
+ require "English"
64
+
65
+ Vagrant.configure("2") do |config|
66
+ config.lifecycle.events = {
67
+ :configure => lambda {|run_list, env|
68
+ run_list.flat_map {|r|
69
+ case r
70
+ when /^role\[(?<role>.*)\]/
71
+ %W(role[#{$LAST_MATCH_INFO['role']}] recipe[layer_#{$LAST_MATCH_INFO['role']}::configure])
72
+ else
73
+ [r]
74
+ end
75
+ }
76
+ },
77
+ :deploy => lambda {|run_list, env|
78
+ run_list.flat_map {|r|
79
+ case r
80
+ when /^role\[(?<role>.*)\]/
81
+ %W(role[#{$LAST_MATCH_INFO['role']}] recipe[layer_#{$LAST_MATCH_INFO['role']}::configure] recipe[layer_#{$LAST_MATCH_INFO['role']}::deploy])
82
+ else
83
+ [r]
84
+ end
85
+ }
86
+ },
87
+ :setup => lambda {|run_list, env|
88
+ run_list.flat_map {|r|
89
+ case r
90
+ when /^role\[(?<role>.*)\]/
91
+ %W(role[#{$LAST_MATCH_INFO['role']}] recipe[layer_#{$LAST_MATCH_INFO['role']}::setup])
92
+ else
93
+ [r]
94
+ end
95
+ }
96
+ }
97
+ }
98
+ end
99
+ ```
100
+
101
+ ### Require additional parameter(s) for a specific lifecycle event
102
+
103
+ Example Vagrantfile configuration section:
104
+
105
+ ```ruby
106
+ # Required for $LAST_MATCH_INFO used bellow
107
+ require "English"
108
+
109
+ Vagrant.configure("2") do |config|
110
+ config.lifecycle.events = {
111
+ :deploy => lambda {|run_list, env|
112
+ options = {}
113
+ opt_parser = OptionParser.new do |parser|
114
+ parser.on("-a", "--application APPLICATION", "Application to deploy") do |p|
115
+ options[:application] = p
116
+ end
117
+ parser.parse!
118
+ end
119
+ opt_parser.program_name="vagrant -e deploy"
120
+
121
+ if options.empty?
122
+ puts opt_parser.help
123
+ exit
124
+ end
125
+
126
+ unless options.key?(:application)
127
+ env[:ui].error "Application parameter missing!"
128
+ exit 1
129
+ end
130
+
131
+ run_list.flat_map {|r|
132
+ case r
133
+ when /^role\[(?<role>.*)\]/
134
+ %W(role[#{$LAST_MATCH_INFO['role']}] recipe[layer_#{$LAST_MATCH_INFO['role']}::configure] recipe[layer_#{$LAST_MATCH_INFO['role']}::deploy_#{options[:application]}])
135
+ else
136
+ [r]
137
+ end
138
+ }
139
+ }
140
+ }
141
+ end
142
+ ```
143
+
144
+ Sample usage:
145
+
146
+ ```bash
147
+ $ vagrant lifecycle -e deploy -a really_cool_app
148
+ ```
149
+
150
+ ### Use specific machine info
151
+
152
+ Example Vagrantfile configuration section:
153
+
154
+
155
+ ```ruby
156
+ Vagrant.configure("2") do |config|
157
+ config.lifecycle.events = {
158
+ :configure => lambda {|run_list, env|
159
+ run_list + ["recipe[sample_cookbook::configure]"]
160
+ },
161
+ :deploy => lambda {|run_list, env|
162
+ if env[:machine].name.to_s == "node1"
163
+ run_list + ["recipe[sample_cookbook::deploy]"]
164
+ else
165
+ run_list
166
+ end
167
+ },
168
+ :setup => lambda {|run_list, env|
169
+ run_list + ["recipe[sample_cookbook::setup]"]
170
+ }
171
+ }
172
+ end
173
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = [].tap do |a|
6
+ a.push('--color')
7
+ a.push('--format progress')
8
+ end.join(' ')
9
+ end
10
+
11
+ desc 'Run all tests'
12
+ task :test => [:spec]
13
+
14
+ task :default => [:test]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant-lifecycle"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ require "vagrant-lifecycle/version"
2
+
3
+ require 'json'
4
+
5
+ module VagrantPlugins
6
+ module Lifecycle
7
+ class Command < Vagrant.plugin(2, :command)
8
+ def self.synopsis
9
+ "Lifecycle..."
10
+ end
11
+
12
+ def execute
13
+ MiddleWareConfig.instance.enabled = true
14
+
15
+ with_target_vms([], reverse: true) do |machine|
16
+ machine.action(:provision)
17
+ end
18
+
19
+ exit 0
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ require 'pathname'
2
+ require 'vagrant/util/hash_with_indifferent_access'
3
+
4
+ module VagrantPlugins
5
+ module Lifecycle
6
+ class Config < Vagrant.plugin("2", :config)
7
+ MAYBE = Object.new.freeze
8
+
9
+ # Lifecycle events configuration.
10
+ # @return [Hash]
11
+ attr_accessor :events
12
+
13
+ # Override default provision
14
+ # @return [Symbol]
15
+ attr_accessor :default_event
16
+
17
+ def initialize
18
+ super
19
+
20
+ @default_event = nil
21
+ @events = Hash.new
22
+
23
+ @__finalized = false
24
+ end
25
+
26
+ def finalize!
27
+ @__finalized = true
28
+ end
29
+
30
+ def validate(machine)
31
+ errors = _detected_errors
32
+
33
+ unless @default_event.nil?
34
+ unless @events.key?(@default_event) || @events.key?(@default_event.to_s) || @events.key?(@default_event.to_sym)
35
+ errors << "#{@default_event} event configuration not found!"
36
+ end
37
+ end
38
+
39
+ if @events.is_a?(Hash)
40
+ @events.each do |k, v|
41
+ if v.respond_to? :call
42
+ unless v.arity == 2
43
+ errors << "#{k} event configuration is expected to be lambda with 2 arguments!"
44
+ end
45
+ else
46
+ errors << "#{k} event configuration is expected to be lambda!"
47
+ end
48
+ end
49
+ else
50
+ errors << "events configuration is expected to be a hash!"
51
+ end
52
+
53
+ {
54
+ "Lifecycle" => errors
55
+ }
56
+ end
57
+
58
+ def to_hash
59
+ raise "Must finalize first." if !@__finalized
60
+
61
+ {
62
+ default_event: @default_event,
63
+ events: @events
64
+ }
65
+ end
66
+
67
+ def missing?(obj)
68
+ obj.to_s.strip.empty?
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,101 @@
1
+ require "vagrant-lifecycle/version"
2
+ require "singleton"
3
+ require 'json'
4
+
5
+ module VagrantPlugins
6
+ module Lifecycle
7
+ class MiddleWareConfig
8
+ include Singleton
9
+
10
+ attr_accessor :enabled
11
+
12
+ def initialize
13
+ @enabled = false
14
+ end
15
+ end
16
+
17
+ class MiddleWare
18
+ def initialize(app, env)
19
+ @app = app
20
+
21
+ klass = self.class.name.downcase.split('::').last
22
+ @logger = Log4r::Logger.new("vagrant::lifecycle::#{klass}")
23
+ end
24
+
25
+ # Like OptionParser.order!, but leave any unrecognized --switches alone
26
+ def order_recognized!(parser, args)
27
+ extra_opts = []
28
+ begin
29
+ parser.order!(args) {|a| extra_opts << a}
30
+ rescue OptionParser::InvalidOption => e
31
+ extra_opts << e.args[0]
32
+ retry
33
+ end
34
+ args[0, 0] = extra_opts
35
+ end
36
+
37
+ def call(env)
38
+ if MiddleWareConfig.instance.enabled
39
+ options = Hash.new
40
+ opts = OptionParser.new do |parser|
41
+ parser.on("-e", "--event EVENT", "Lifecycle event to execute") do |p|
42
+ options[:event] = p
43
+ end
44
+ order_recognized!(parser, ARGV)
45
+ end
46
+
47
+ unless options.key?(:event)
48
+ env[:ui].error "Lifecycle event parameter missing!"
49
+ env[:interrupted] = true
50
+ end
51
+ event = options[:event]
52
+ else
53
+ event = env[:machine].config.lifecycle.default_event
54
+ end
55
+
56
+ if event.nil?
57
+ @app.call(env)
58
+ else
59
+ chef_provisioners = env[:machine].config.vm.provisioners.select do |provisioner|
60
+ # Vagrant 1.7 changes provisioner.name to provisioner.type
61
+ if provisioner.respond_to? :type
62
+ provisioner.type.to_sym == :chef_solo
63
+ else
64
+ provisioner.name.to_sym == :chef_solo
65
+ end
66
+ end
67
+
68
+ # @type [Hash]
69
+ lifecycle_events = env[:machine].config.lifecycle.events
70
+
71
+ if lifecycle_events.key?(event) || lifecycle_events.key?(event.to_sym) || lifecycle_events.key?(event.to_s)
72
+ # @type [lambda]
73
+ event_lambda = lifecycle_events[event] || lifecycle_events[event.to_sym] || lifecycle_events[event.to_s]
74
+
75
+ chef_provisioners.each do |chef|
76
+ begin
77
+ new_run_list = event_lambda.call(chef.config.run_list || [], env)
78
+ @logger.debug "Setting run_list = #{new_run_list.inspect}"
79
+
80
+ if new_run_list.kind_of?(Array)
81
+ chef.config.run_list = new_run_list
82
+ else
83
+ env[:ui].error "Could not evaluate proper run list for the lifecycle event #{event}!"
84
+ env[:interrupted] = true
85
+ end
86
+ rescue Exception => e
87
+ env[:ui].error "Failed while evaluating run list for the event #{event} with error: #{e}"
88
+ env[:interrupted] = true
89
+ end
90
+ end
91
+ else
92
+ env[:ui].error "Lifecycle event #{event} not configured!"
93
+ env[:interrupted] = true
94
+ end
95
+
96
+ @app.call(env)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,35 @@
1
+ require "vagrant-lifecycle/command"
2
+ require "vagrant-lifecycle/middleware"
3
+ require "vagrant-lifecycle/version"
4
+
5
+ require 'json'
6
+
7
+ module VagrantPlugins
8
+ module Lifecycle
9
+ class Plugin < Vagrant.plugin(2)
10
+ name "Lifecycle Plugin"
11
+
12
+ def self.provision
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use MiddleWare
15
+ end
16
+ end
17
+
18
+ [:machine_action_up, :machine_action_reload, :machine_action_provision].each do |action|
19
+ action_hook(:lifecycle_provision, action) do |hook|
20
+ # hook.after(Vagrant::Action::Builtin::ConfigValidate, Plugin.provision_init)
21
+ hook.before(Vagrant::Action::Builtin::Provision, Plugin.provision)
22
+ end
23
+ end
24
+
25
+ command "lifecycle" do
26
+ Command
27
+ end
28
+
29
+ config(:lifecycle) do
30
+ require_relative "config"
31
+ Config
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Lifecycle
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'vagrant'
2
+
3
+ require_relative 'vagrant-lifecycle/config'
4
+ require_relative 'vagrant-lifecycle/middleware'
5
+ require_relative 'vagrant-lifecycle/plugin'
6
+ require_relative 'vagrant-lifecycle/version'
7
+
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vagrant-lifecycle/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-lifecycle"
8
+ spec.version = VagrantPlugins::Lifecycle::VERSION
9
+ spec.authors = ["Nikola Stojiljkovic"]
10
+ spec.email = ["xection@gmail.com"]
11
+
12
+ spec.summary = %q{Vagrant plugin to run custom Chef run list and filtered data bags during provisioning}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/nstojiljkovic/vagrant-lifecycle"
15
+ spec.license = "Apache-2.0"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-lifecycle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikola Stojiljkovic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - xection@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CHANGELOG.md
66
+ - CONTRIBUTING.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/vagrant-lifecycle.rb
75
+ - lib/vagrant-lifecycle/command.rb
76
+ - lib/vagrant-lifecycle/config.rb
77
+ - lib/vagrant-lifecycle/middleware.rb
78
+ - lib/vagrant-lifecycle/plugin.rb
79
+ - lib/vagrant-lifecycle/version.rb
80
+ - vagrant-lifecycle.gemspec
81
+ homepage: https://github.com/nstojiljkovic/vagrant-lifecycle
82
+ licenses:
83
+ - Apache-2.0
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.12
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Vagrant plugin to run custom Chef run list and filtered data bags during
105
+ provisioning
106
+ test_files: []