vagrant-databags 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +141 -0
- data/LICENSE +202 -0
- data/README.md +181 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vagrant-databags.rb +7 -0
- data/lib/vagrant-databags/action.rb +14 -0
- data/lib/vagrant-databags/action/base.rb +36 -0
- data/lib/vagrant-databags/action/clean_databags.rb +24 -0
- data/lib/vagrant-databags/action/destroy_databags.rb +19 -0
- data/lib/vagrant-databags/action/load_databags.rb +55 -0
- data/lib/vagrant-databags/action/persist_databags.rb +42 -0
- data/lib/vagrant-databags/config.rb +65 -0
- data/lib/vagrant-databags/data_bags.rb +178 -0
- data/lib/vagrant-databags/file_util.rb +34 -0
- data/lib/vagrant-databags/plugin.rb +32 -0
- data/lib/vagrant-databags/version.rb +5 -0
- data/vagrant-databags.gemspec +29 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30581440f80dde213e556f44cfd4459e53729b5d
|
4
|
+
data.tar.gz: dcb5d08117ca2410703745547e9602f06814223f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f5fc1edde8ec88940d9de03bf7656df7f148db3502c81e73fca383c12d66ddbe90baab7ff4e2a0658694d39a3f297890f99a2d384f325998c9fa41485edeac5
|
7
|
+
data.tar.gz: e385594ef0fb819b9e9582e52e886d12ceb2b9e144a0928f26314f089b22de24a90ffab27ff473fd3c8081ae0c42789ab37befb25bf476bd8c312e669a0606ce
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
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-databags.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-databags (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.5)
|
133
|
+
rake
|
134
|
+
rspec
|
135
|
+
spork
|
136
|
+
vagrant!
|
137
|
+
vagrant-databags!
|
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,181 @@
|
|
1
|
+
# Vagrant DataBags Plugin
|
2
|
+
|
3
|
+
Vagrant DataBags is a Vagrant plugin that allows dynamic modification of host-served data bags for the Chef provisioners
|
4
|
+
(Chef Solo and Chef Zero).
|
5
|
+
|
6
|
+
The primarily goal of this plugin is to ease the development and testing of Chef recipes intended for use on services
|
7
|
+
like AWS OpsWorks.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
1. Install the latest version of [Vagrant](https://www.vagrantup.com/downloads.html)
|
12
|
+
2. Install the Vagrant DataBags plugin:
|
13
|
+
|
14
|
+
```sh
|
15
|
+
$ vagrant plugin install vagrant-databags
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Example Vagrantfile configuration section for Vagrant DataBags:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Vagrant.configure("2") do |config|
|
24
|
+
# Cleanup on provision.
|
25
|
+
# If set, temp data bag folder will be cleaned up upon provision which might be useful if you will inject sensitive data.
|
26
|
+
# Defaults to false.
|
27
|
+
config.databags.cleanup_on_provision = true
|
28
|
+
|
29
|
+
# Hash of map lambda's per data bag.
|
30
|
+
# Each data bag needs a lambda with 2 parameters: items and env and should return the new hash of data bag items
|
31
|
+
# Parameter items is a hash of items (per item's id)
|
32
|
+
# Parameter env is vagrant-lifecycle plugin's middleware environment hash with various interesting keys:
|
33
|
+
# * env[:ui] is an instance of ::Vagrant::UI::Interface
|
34
|
+
# * env[:machine] is an instance of ::Vagrant::Machine etc.
|
35
|
+
config.databags.map = {
|
36
|
+
:sample_data => lambda { |items, env|
|
37
|
+
items['new_data_bag_item_id'] = {
|
38
|
+
:name => 'New sample data bag item'
|
39
|
+
}
|
40
|
+
items
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Usage with other Vagrant plugins
|
47
|
+
|
48
|
+
Evaluated data bags are available in other Vagrant plugin's middlewares through `:data_bags` key of the environment hash.
|
49
|
+
|
50
|
+
### More examples
|
51
|
+
|
52
|
+
#### Simulate OpsWorks stack
|
53
|
+
|
54
|
+
Additional [vagrant-lifecycle](https://github.com/nstojiljkovic/vagrant-lifecycle) plugin is required for this example.
|
55
|
+
|
56
|
+
[AWS OpsWorks stacks data bag reference](https://docs.aws.amazon.com/opsworks/latest/userguide/data-bags.html) is
|
57
|
+
available on the official AWS documentation website.
|
58
|
+
|
59
|
+
Example Vagrantfile configuration section:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Required for $LAST_MATCH_INFO
|
63
|
+
require 'English'
|
64
|
+
require 'securerandom'
|
65
|
+
require 'json'
|
66
|
+
require 'set'
|
67
|
+
|
68
|
+
Vagrant.configure("2") do |config|
|
69
|
+
node.databags.cleanup_on_provision = false
|
70
|
+
node.databags.map = {
|
71
|
+
# Use Lifecycle event as a command
|
72
|
+
# @see https://github.com/nstojiljkovic/vagrant-lifecycle
|
73
|
+
# @see https://docs.aws.amazon.com/opsworks/latest/userguide/data-bag-json-command.html
|
74
|
+
aws_opsworks_command: lambda {|items, env|
|
75
|
+
command_id = SecureRandom.uuid
|
76
|
+
command_type = env[:lifecycle_event] || env[:machine].config.lifecycle.default_event.to_s
|
77
|
+
items[command_id] = {
|
78
|
+
:type => command_type,
|
79
|
+
:args => {},
|
80
|
+
:sent_at => Time.now.utc.strftime('%FT%T%:z'),
|
81
|
+
:command_id => command_id,
|
82
|
+
:iam_user_arn => nil,
|
83
|
+
:instance_id => env[:machine].name
|
84
|
+
}
|
85
|
+
items
|
86
|
+
},
|
87
|
+
|
88
|
+
# Extract instances from Vagrantfile!
|
89
|
+
# @see https://docs.aws.amazon.com/opsworks/latest/userguide/data-bag-json-instance.html
|
90
|
+
:aws_opsworks_instance => lambda { |items, env|
|
91
|
+
env[:machine].vagrantfile.machine_names.each do |name|
|
92
|
+
|
93
|
+
machine_config = env[:machine].vagrantfile.machine_config(name, nil, nil)
|
94
|
+
instance_roles = []
|
95
|
+
machine_config[:config].vm.provisioners.each do |chef|
|
96
|
+
instance_roles = (chef.config.run_list || []).flat_map {|r|
|
97
|
+
case r
|
98
|
+
when /^role\[(?<role>.*)\]/
|
99
|
+
$LAST_MATCH_INFO['role']
|
100
|
+
else
|
101
|
+
[]
|
102
|
+
end
|
103
|
+
}
|
104
|
+
instance_roles = instance_roles.to_set.to_a
|
105
|
+
end
|
106
|
+
|
107
|
+
private_networks = machine_config[:config].vm.networks.select do |network|
|
108
|
+
network[0] == :private_network && network[1].key?(:ip)
|
109
|
+
end
|
110
|
+
public_networks = machine_config[:config].vm.networks.select do |network|
|
111
|
+
network[0] == :public_network && network[1].key?(:ip)
|
112
|
+
end
|
113
|
+
active_machines = env[:machine].env.active_machines.map do |c|
|
114
|
+
c[0]
|
115
|
+
end
|
116
|
+
|
117
|
+
items[name] = {
|
118
|
+
:architecture => "x86_64",
|
119
|
+
:auto_scaling_type => nil,
|
120
|
+
:availability_zone => "local",
|
121
|
+
:ebs_optimized => false,
|
122
|
+
:ec2_instance_id => name,
|
123
|
+
:elastic_ip => nil,
|
124
|
+
:hostname => machine_config[:config].vm.hostname,
|
125
|
+
:instance_id => name,
|
126
|
+
:instance_type => "custom",
|
127
|
+
:layer_ids => instance_roles,
|
128
|
+
:os => machine_config[:config].vm.box,
|
129
|
+
:private_ip => private_networks.empty? ? nil : private_networks.first[1][:ip],
|
130
|
+
:public_ip => public_networks.empty? ? nil : public_networks.first[1][:ip],
|
131
|
+
:status => active_machines.include?(name) ? "online" : "stopped",
|
132
|
+
:virtualization_type => machine_config[:config].vm.__providers.first,
|
133
|
+
:infrastructure_class => "vagrant",
|
134
|
+
:role => instance_roles,
|
135
|
+
:self => name == env[:machine].name,
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
items
|
140
|
+
},
|
141
|
+
|
142
|
+
# Use Chef roles as OpsWorks layers
|
143
|
+
# @see https://docs.aws.amazon.com/opsworks/latest/userguide/data-bag-json-layer.html
|
144
|
+
:aws_opsworks_layer => lambda { |items, env|
|
145
|
+
roles = Set.new
|
146
|
+
|
147
|
+
env[:machine].vagrantfile.machine_names.each do |name|
|
148
|
+
machine_config = env[:machine].vagrantfile.machine_config(name, nil, nil)
|
149
|
+
|
150
|
+
machine_config[:config].vm.provisioners.each do |chef|
|
151
|
+
instance_roles = (chef.config.run_list || []).flat_map {|r|
|
152
|
+
case r
|
153
|
+
when /^role\[(?<role>.*)\]/
|
154
|
+
$LAST_MATCH_INFO['role']
|
155
|
+
else
|
156
|
+
[]
|
157
|
+
end
|
158
|
+
}
|
159
|
+
roles.merge(instance_roles.to_set)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
roles.each do |v|
|
164
|
+
items[v] = {
|
165
|
+
:layer_id => v,
|
166
|
+
:name => v,
|
167
|
+
:packages => [],
|
168
|
+
:shortname => v,
|
169
|
+
:type => "custom",
|
170
|
+
:volume_configurations => [],
|
171
|
+
:cloud_watch_logs_configuration => {
|
172
|
+
:enabled => false,
|
173
|
+
:log_streams => []
|
174
|
+
}
|
175
|
+
}
|
176
|
+
end
|
177
|
+
items
|
178
|
+
}
|
179
|
+
}
|
180
|
+
end
|
181
|
+
```
|
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-databags"
|
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,14 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DataBags
|
5
|
+
module Action
|
6
|
+
# The autoload farm
|
7
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
8
|
+
autoload :CleanDataBags, action_root.join("clean_databags")
|
9
|
+
autoload :DestroyDataBags, action_root.join("destroy_databags")
|
10
|
+
autoload :LoadDataBags, action_root.join("load_databags")
|
11
|
+
autoload :PersistDataBags, action_root.join("persist_databags")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'vagrant-databags/data_bags'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DataBags
|
5
|
+
module Action
|
6
|
+
class Base
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
|
10
|
+
klass = self.class.name.downcase.split('::').last
|
11
|
+
@logger = Log4r::Logger.new("vagrant::databags::#{klass}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def machine_chef_provisioners(machine)
|
15
|
+
machine.config.vm.provisioners.select do |provisioner|
|
16
|
+
# Vagrant 1.7 changes provisioner.name to provisioner.type
|
17
|
+
if provisioner.respond_to? :type
|
18
|
+
provisioner.type.to_sym == :chef_solo || provisioner.type.to_sym == :chef_zero
|
19
|
+
else
|
20
|
+
provisioner.name.to_sym == :chef_solo || provisioner.name.to_sym == :chef_zero
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def chef_provisioner_type(chef)
|
26
|
+
if chef.respond_to? :type
|
27
|
+
provisioner_type = chef.type.to_sym
|
28
|
+
else
|
29
|
+
provisioner_type = chef.name.to_sym
|
30
|
+
end
|
31
|
+
provisioner_type
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require 'vagrant-databags/data_bags'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
module Action
|
7
|
+
class CleanDataBags < Base
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env[:machine].config.databags.cleanup_on_provision && env[:machine].config.databags.map.size > 0
|
11
|
+
env[:ui].detail "[vagrant-databags] Cleaning up temp data bags folder"
|
12
|
+
chef_provisioners = machine_chef_provisioners(env[:machine])
|
13
|
+
chef_provisioners.each do |chef|
|
14
|
+
provisioner_type = chef_provisioner_type(chef)
|
15
|
+
DataBagsContainer.instance.clean(env[:machine], provisioner_type)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require 'vagrant-databags/data_bags'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
module Action
|
7
|
+
class DestroyDataBags < Base
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].detail "[vagrant-databags] Destroying temp data bags folder"
|
11
|
+
DataBagsContainer.instance.destroy(env[:machine])
|
12
|
+
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require 'vagrant-databags/data_bags'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
module Action
|
7
|
+
class LoadDataBags < Base
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
unless env.key?(:data_bags)
|
11
|
+
env[:data_bags] = {}
|
12
|
+
if env[:machine].config.databags.map.size > 0
|
13
|
+
chef_provisioners = machine_chef_provisioners(env[:machine])
|
14
|
+
|
15
|
+
chef_provisioners.each do |chef|
|
16
|
+
provisioner_type = chef_provisioner_type(chef)
|
17
|
+
env[:ui].detail "[vagrant-databags] Initializing temp data bags folder for provisioner #{provisioner_type}"
|
18
|
+
DataBagsContainer.instance.init_machine_data_bags(env[:machine], provisioner_type, chef.config.data_bags_path)
|
19
|
+
chef.config.data_bags_path = (chef.config.data_bags_path || []).select {|item| item[0].to_sym != :host}
|
20
|
+
chef.config.data_bags_path << DataBagsContainer.instance.init_machine_data_bag_folder(env[:machine], provisioner_type)
|
21
|
+
@logger.debug "Setting data_bags_path = #{chef.config.data_bags_path}"
|
22
|
+
|
23
|
+
env[:ui].detail "[vagrant-databags] Evaluating data bags for provisioner #{provisioner_type}"
|
24
|
+
# @type [MachineDataBags]
|
25
|
+
machine_data_bags = DataBagsContainer.instance.get_machine_data_bags(env[:machine], provisioner_type)
|
26
|
+
|
27
|
+
env[:machine].config.databags.map.each do |data_bag_name, callback|
|
28
|
+
begin
|
29
|
+
new_data_bag_items = callback.call(machine_data_bags.get_data_bag(data_bag_name.to_s).items, env)
|
30
|
+
|
31
|
+
unless new_data_bag_items.kind_of?(Hash)
|
32
|
+
env[:ui].error "Could not evaluate items of the data bag #{data_bag_name}!"
|
33
|
+
env[:interrupted] = true
|
34
|
+
end
|
35
|
+
rescue Exception => e
|
36
|
+
env[:ui].error "Failed while evaluating items of the data bag #{data_bag_name} with error: #{e}"
|
37
|
+
env[:interrupted] = true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
env[:data_bags][provisioner_type.to_sym] = {}
|
42
|
+
machine_data_bags.data_bag_names.each do |data_bag_name|
|
43
|
+
env[:data_bags][provisioner_type.to_sym][data_bag_name.to_sym] = machine_data_bags.get_data_bag(data_bag_name).items
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@app.call(env)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require 'vagrant-databags/data_bags'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
module Action
|
7
|
+
class PersistDataBags < Base
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
|
12
|
+
klass = self.class.name.downcase.split('::').last
|
13
|
+
@logger = Log4r::Logger.new("vagrant::databags::#{klass}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
chef_provisioners = machine_chef_provisioners(env[:machine])
|
18
|
+
|
19
|
+
chef_provisioners.each do |chef|
|
20
|
+
if env[:machine].config.databags.map.size > 0
|
21
|
+
env[:ui].detail "[vagrant-databags] Persisting temp data bags"
|
22
|
+
provisioner_type = chef_provisioner_type(chef)
|
23
|
+
DataBagsContainer.instance.persist_machine_data_bags(env[:machine], provisioner_type)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
def recover(env)
|
31
|
+
chef_provisioners = machine_chef_provisioners(env[:machine])
|
32
|
+
chef_provisioners.each do |chef|
|
33
|
+
provisioner_type = chef_provisioner_type(chef)
|
34
|
+
env[:ui].info "Cleaning up temporal data bags"
|
35
|
+
DataBagsContainer.instance.clean(env[:machine], provisioner_type)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'vagrant/util/hash_with_indifferent_access'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DataBags
|
5
|
+
class Config < Vagrant.plugin("2", :config)
|
6
|
+
MAYBE = Object.new.freeze
|
7
|
+
|
8
|
+
# Data bags map configuration.
|
9
|
+
# @return [Hash]
|
10
|
+
attr_accessor :map
|
11
|
+
|
12
|
+
# Data bags map configuration.
|
13
|
+
# @return [Boolean]
|
14
|
+
attr_accessor :cleanup_on_provision
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super
|
18
|
+
|
19
|
+
@map = Hash.new
|
20
|
+
@cleanup_on_provision = false
|
21
|
+
|
22
|
+
@__finalized = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def finalize!
|
26
|
+
@__finalized = true
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate(machine)
|
30
|
+
errors = _detected_errors
|
31
|
+
|
32
|
+
if @map.is_a?(Hash)
|
33
|
+
@map.each do |k, v|
|
34
|
+
if v.respond_to? :call
|
35
|
+
unless v.arity == 2
|
36
|
+
errors << "#{k} data bag map configuration is expected to be lambda with 2 arguments!"
|
37
|
+
end
|
38
|
+
else
|
39
|
+
errors << "#{k} data bag map configuration is expected to be lambda!"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
errors << "Data bag map configuration is expected to be a hash!"
|
44
|
+
end
|
45
|
+
|
46
|
+
{
|
47
|
+
"DataBags" => errors
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash
|
52
|
+
raise "Must finalize first." if !@__finalized
|
53
|
+
|
54
|
+
{
|
55
|
+
cleanup_on_provision: @cleanup_on_provision,
|
56
|
+
map: @map
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def missing?(obj)
|
61
|
+
obj.to_s.strip.empty?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'singleton'
|
3
|
+
require 'vagrant-databags/file_util'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module DataBags
|
7
|
+
|
8
|
+
class DataBagsContainer
|
9
|
+
include Singleton
|
10
|
+
include FileUtil
|
11
|
+
|
12
|
+
# @return [Hash<Symbol, Hash<Symbol, MachineDataBags>>]
|
13
|
+
attr_accessor :machine_data_bags
|
14
|
+
|
15
|
+
# @return [Array<String>]
|
16
|
+
attr_reader :temp_folders
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@machine_data_bags_map = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [::Vagrant::Machine] machine
|
23
|
+
# @param [Symbol] provisioner_type
|
24
|
+
# @param [Array<String>] data_bags_path
|
25
|
+
# @return [MachineDataBags]
|
26
|
+
def init_machine_data_bags(machine, provisioner_type, data_bags_path)
|
27
|
+
machine_data_bags = get_machine_data_bags(machine, provisioner_type)
|
28
|
+
data_bags_path.each do |data_bag_path|
|
29
|
+
if data_bag_path[0] == :host
|
30
|
+
data_bags_root_path = ::File.join(machine.env.root_path, data_bag_path[1])
|
31
|
+
find_all_object_dirs(data_bags_root_path).each do |data_bag_name|
|
32
|
+
find_all_objects(::File.join(data_bags_root_path, data_bag_name)).each do |item_file_name|
|
33
|
+
item = object_from_json_file(::File.join(data_bags_root_path, data_bag_name, item_file_name))
|
34
|
+
machine_data_bags.add_data_bag_item(data_bag_name, item['id'], item)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@machine_data_bags_map[machine.name.to_sym][provisioner_type.to_sym] = machine_data_bags
|
40
|
+
machine_data_bags
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [::Vagrant::Machine] machine
|
44
|
+
# @param [Symbol] provisioner_type
|
45
|
+
# @return [MachineDataBags]
|
46
|
+
def get_machine_data_bags(machine, provisioner_type)
|
47
|
+
unless @machine_data_bags_map.key?(machine.name.to_sym)
|
48
|
+
@machine_data_bags_map[machine.name.to_sym] = {}
|
49
|
+
end
|
50
|
+
unless @machine_data_bags_map[machine.name.to_sym].key?(provisioner_type.to_sym)
|
51
|
+
@machine_data_bags_map[machine.name.to_sym][provisioner_type.to_sym] = MachineDataBags.new
|
52
|
+
end
|
53
|
+
|
54
|
+
@machine_data_bags_map[machine.name.to_sym][provisioner_type.to_sym]
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [::Vagrant::Machine] machine
|
58
|
+
# @param [Symbol] provisioner_type
|
59
|
+
# @return [Array]
|
60
|
+
def init_machine_data_bag_folder(machine, provisioner_type)
|
61
|
+
rel_temp_folder = get_rel_temp_folder(machine, provisioner_type)
|
62
|
+
::FileUtils.mkdir_p ::File.join(machine.env.root_path, rel_temp_folder)
|
63
|
+
[:host, rel_temp_folder]
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [::Vagrant::Machine] machine
|
67
|
+
# @param [Symbol] provisioner_type
|
68
|
+
# @return [Array]
|
69
|
+
def persist_machine_data_bags(machine, provisioner_type)
|
70
|
+
machine_data_bags = get_machine_data_bags(machine, provisioner_type)
|
71
|
+
rel_temp_folder = get_rel_temp_folder(machine, provisioner_type)
|
72
|
+
temp_folder = ::File.join(machine.env.root_path, rel_temp_folder)
|
73
|
+
|
74
|
+
machine_data_bags.data_bags.each do |data_bag_name, data_bag|
|
75
|
+
data_bag_folder = ::File.join(temp_folder, data_bag_name)
|
76
|
+
::FileUtils.mkdir_p data_bag_folder
|
77
|
+
data_bag.items.each do |item_id, item|
|
78
|
+
open(File.join(data_bag_folder, "#{item_id}.json"), 'w') {|f| f << ::JSON.pretty_generate(item)}
|
79
|
+
end
|
80
|
+
|
81
|
+
find_all_objects(data_bag_folder).each do |file_name|
|
82
|
+
item_id = ::File.basename(file_name, ".*")
|
83
|
+
unless data_bag.items.key?(item_id) || data_bag.items.key?(item_id.to_sym)
|
84
|
+
::FileUtils.rm_r ::File.join(data_bag_folder, file_name), :force => true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
find_all_object_dirs(temp_folder).each do |folder_name|
|
90
|
+
unless machine_data_bags.data_bags.key?(folder_name)
|
91
|
+
::FileUtils.rm_r ::File.join(temp_folder, folder_name), :force => true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
[:host, rel_temp_folder]
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param [::Vagrant::Machine] machine
|
98
|
+
def destroy(machine)
|
99
|
+
::FileUtils.rm_r get_abs_temp_folder(machine), :force => true
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [::Vagrant::Machine] machine
|
103
|
+
# @param [Symbol] provisioner_type
|
104
|
+
def clean(machine, provisioner_type)
|
105
|
+
abs_temp_folder = get_abs_temp_folder(machine, provisioner_type)
|
106
|
+
Dir[::File.join(abs_temp_folder, "*")].each do |f|
|
107
|
+
::FileUtils.rm_r f, :force => true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param [::Vagrant::Machine] machine
|
112
|
+
# @param [Symbol] provisioner_type
|
113
|
+
# @return [String]
|
114
|
+
def get_abs_temp_folder(machine, provisioner_type = nil)
|
115
|
+
::File.join(machine.env.root_path, get_rel_temp_folder(machine, provisioner_type))
|
116
|
+
end
|
117
|
+
|
118
|
+
# @param [::Vagrant::Machine] machine
|
119
|
+
# @param [Symbol] provisioner_type
|
120
|
+
# @return [String]
|
121
|
+
def get_rel_temp_folder(machine, provisioner_type = nil)
|
122
|
+
if provisioner_type.nil?
|
123
|
+
::File.join(".vagrant", "machines", machine.name.to_s, "databags")
|
124
|
+
else
|
125
|
+
::File.join(".vagrant", "machines", machine.name.to_s, "databags", provisioner_type.to_s)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class MachineDataBags
|
131
|
+
# @return [Hash<String, DataBag>]
|
132
|
+
attr_accessor :data_bags
|
133
|
+
|
134
|
+
def initialize
|
135
|
+
@data_bags = {}
|
136
|
+
end
|
137
|
+
|
138
|
+
# @param [String] data_bag_name
|
139
|
+
# @param [String] item_id
|
140
|
+
# @param [Hash] item
|
141
|
+
def add_data_bag_item(data_bag_name, item_id, item)
|
142
|
+
get_data_bag(data_bag_name).add_item(item_id, item)
|
143
|
+
end
|
144
|
+
|
145
|
+
# @param [String] data_bag_name
|
146
|
+
# @return [DataBag]
|
147
|
+
def get_data_bag(data_bag_name)
|
148
|
+
unless @data_bags.key?(data_bag_name)
|
149
|
+
@data_bags[data_bag_name] = DataBag.new(data_bag_name)
|
150
|
+
end
|
151
|
+
@data_bags[data_bag_name]
|
152
|
+
end
|
153
|
+
|
154
|
+
# @return [Array<String>]
|
155
|
+
def data_bag_names
|
156
|
+
@data_bags.keys
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class DataBag
|
161
|
+
# @return [String]
|
162
|
+
attr_reader :name
|
163
|
+
|
164
|
+
# @return [Hash<String, Object>]
|
165
|
+
attr_accessor :items
|
166
|
+
|
167
|
+
def initialize(name)
|
168
|
+
@name = name
|
169
|
+
@items = {}
|
170
|
+
end
|
171
|
+
|
172
|
+
def add_item(item_id, item)
|
173
|
+
@items[item_id] = item
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
module FileUtil
|
7
|
+
def escape_glob_dir(*parts)
|
8
|
+
path = ::Pathname.new(::File.join(*parts)).cleanpath.to_s
|
9
|
+
path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x }
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_all_object_dirs(path)
|
13
|
+
path = ::File.join(escape_glob_dir(::File.expand_path(path)), "*")
|
14
|
+
objects = ::Dir.glob(path)
|
15
|
+
objects.delete_if { |o| !::File.directory?(o) }
|
16
|
+
objects.map { |o| ::File.basename(o) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_all_objects(path)
|
20
|
+
path = ::File.join(escape_glob_dir(::File.expand_path(path)), "*.json")
|
21
|
+
objects = ::Dir.glob(path)
|
22
|
+
objects.map { |o| ::File.basename(o) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def object_from_json_file(filename)
|
26
|
+
r = ::JSON.parse(IO.read(filename))
|
27
|
+
unless r.key?('id')
|
28
|
+
r['id'] = ::File.basename(filename, ".*")
|
29
|
+
end
|
30
|
+
r
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-databags/config'
|
2
|
+
require 'vagrant-databags/version'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DataBags
|
6
|
+
class Plugin < Vagrant.plugin(2)
|
7
|
+
name 'DataBags Plugin'
|
8
|
+
|
9
|
+
[:machine_action_up, :machine_action_reload, :machine_action_provision].each do |action|
|
10
|
+
action_hook(:databags_provision, action) do |hook|
|
11
|
+
# hook.after Vagrant::Action::Builtin::ConfigValidate, Action::LoadDataBags
|
12
|
+
hook.before Vagrant::Action::Builtin::Provision, Action::LoadDataBags
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
action_hook(:databags_provision, :provisioner_run) do |hook|
|
17
|
+
hook.before :run_provisioner, Action::PersistDataBags
|
18
|
+
hook.after :run_provisioner, Action::CleanDataBags
|
19
|
+
end
|
20
|
+
|
21
|
+
action_hook(:databags_provision, :machine_action_destroy) do |hook|
|
22
|
+
hook.before Vagrant::Action::Builtin::ProvisionerCleanup, Action::DestroyDataBags
|
23
|
+
# hook.before Vagrant::Action::Builtin::DestroyConfirm, Plugin.provisioner_destroy
|
24
|
+
end
|
25
|
+
|
26
|
+
config(:databags) do
|
27
|
+
require_relative 'config'
|
28
|
+
Config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -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-databags/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-databags"
|
8
|
+
spec.version = VagrantPlugins::DataBags::VERSION
|
9
|
+
spec.authors = ["Nikola Stojiljkovic"]
|
10
|
+
spec.email = ["xection@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Vagrant plugin to dynamically alter 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-databags"
|
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.5"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-databags
|
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-18 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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-databags.rb
|
75
|
+
- lib/vagrant-databags/action.rb
|
76
|
+
- lib/vagrant-databags/action/base.rb
|
77
|
+
- lib/vagrant-databags/action/clean_databags.rb
|
78
|
+
- lib/vagrant-databags/action/destroy_databags.rb
|
79
|
+
- lib/vagrant-databags/action/load_databags.rb
|
80
|
+
- lib/vagrant-databags/action/persist_databags.rb
|
81
|
+
- lib/vagrant-databags/config.rb
|
82
|
+
- lib/vagrant-databags/data_bags.rb
|
83
|
+
- lib/vagrant-databags/file_util.rb
|
84
|
+
- lib/vagrant-databags/plugin.rb
|
85
|
+
- lib/vagrant-databags/version.rb
|
86
|
+
- vagrant-databags.gemspec
|
87
|
+
homepage: https://github.com/nstojiljkovic/vagrant-databags
|
88
|
+
licenses:
|
89
|
+
- Apache-2.0
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.6.12
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Vagrant plugin to dynamically alter data bags during provisioning
|
111
|
+
test_files: []
|