knife-sync 1.0.0.pre.a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.gitlab-ci.yml +32 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CONTRIBUTING.md +62 -0
- data/Gemfile +5 -0
- data/LICENSE +202 -0
- data/README.md +68 -0
- data/Rakefile +24 -0
- data/bin/console +31 -0
- data/bin/setup +23 -0
- data/knife-sync.gemspec +47 -0
- data/lib/chef/knife/data_bag_sync.rb +207 -0
- data/lib/chef/knife/environment_sync.rb +102 -0
- data/lib/chef/knife/node_sync.rb +102 -0
- data/lib/chef/knife/role_sync.rb +101 -0
- data/lib/knife-sync/version.rb +24 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e33049cd263d4481daa0eff361aa4724da4a551e53c445a3f4d8dba7818828f
|
4
|
+
data.tar.gz: e211e3d1a4da11bb26a6ef0137df503e6c73306aea661a00cd2e9c55b2fbd6a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edbeb08b1166c2cfa04480e43fa06c21f099f6e31f99d86b52054063b85e3c4755435da7c06ca3d6f55914eccbad85f2b5458ffb750b3a55678502331b2ab8f3
|
7
|
+
data.tar.gz: 9c2dea3a51025289902b89e3ac0e4991d32a1ebab2f06bc86e5bddeeb8fadef5fe40b1e90ad03663d4523d7f819628417bc29de254c186be564634d444393835
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
stages:
|
2
|
+
- checks
|
3
|
+
|
4
|
+
image: sbernard/arch-kitchen-docker
|
5
|
+
|
6
|
+
variables:
|
7
|
+
CHECKS_REPO: https://gitlab.com/samuel.bernard/checks/raw/master
|
8
|
+
|
9
|
+
.checks_template:
|
10
|
+
stage: checks
|
11
|
+
before_script:
|
12
|
+
- bundle install
|
13
|
+
|
14
|
+
rubocop:
|
15
|
+
extends: .checks_template
|
16
|
+
script:
|
17
|
+
- bundle exec rubocop
|
18
|
+
|
19
|
+
lines_length:
|
20
|
+
extends: .checks_template
|
21
|
+
script:
|
22
|
+
- curl -s $CHECKS_REPO/check_lines_length.sh | bash
|
23
|
+
|
24
|
+
git_history:
|
25
|
+
extends: .checks_template
|
26
|
+
script:
|
27
|
+
- curl -s $CHECKS_REPO/check_git_history.sh | bash
|
28
|
+
|
29
|
+
rspec:
|
30
|
+
extends: .checks_template
|
31
|
+
script:
|
32
|
+
- bundle exec rspec
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
Contributing
|
2
|
+
------------
|
3
|
+
|
4
|
+
You are more than welcome to submit issues and merge requests to this project.
|
5
|
+
|
6
|
+
### Foodcritic, Rubocop and Tests
|
7
|
+
|
8
|
+
Your commits must not break any tests, foodcritic nor rubocop.
|
9
|
+
|
10
|
+
### Commits format
|
11
|
+
|
12
|
+
Your commits must pass `git log --check` and messages should be formatted
|
13
|
+
like this (read
|
14
|
+
[post](http://karma-runner.github.io/1.0/dev/git-commit-msg.html)
|
15
|
+
for details):
|
16
|
+
|
17
|
+
```
|
18
|
+
type(scope): subject, all in 50 characters or less
|
19
|
+
|
20
|
+
body: Provide more detail after the first line. Leave one blank line
|
21
|
+
below the summary and wrap all lines at 72 characters or less.
|
22
|
+
|
23
|
+
Uses the imperative, present tense: “change” not “changed” nor
|
24
|
+
"changes". Includes motivation for the change and contrasts with
|
25
|
+
previous behavior.
|
26
|
+
|
27
|
+
If the change fixes an issue, leave another blank line after the final
|
28
|
+
paragraph and indicate which issue is fixed in the specific format
|
29
|
+
below.
|
30
|
+
|
31
|
+
Fix #42
|
32
|
+
```
|
33
|
+
|
34
|
+
Allowed <type> values:
|
35
|
+
|
36
|
+
- feat (new feature for the user, not a new feature for build script)
|
37
|
+
- fix (bug fix for the user, not a fix to a build script)
|
38
|
+
- doc (changes to the documentation)
|
39
|
+
- style (formatting, missing semi colons, etc; no production code change)
|
40
|
+
- refactor (refactoring production code, eg. renaming a variable)
|
41
|
+
- test (adding missing tests, refactoring tests; no production code change)
|
42
|
+
- chore (updating grunt tasks etc; no production code change)
|
43
|
+
|
44
|
+
Example <scope> values:
|
45
|
+
|
46
|
+
- recipe name (like config, install, etc.)
|
47
|
+
- rubocop, foodcritic, kitchen (when dealing with specific tool)
|
48
|
+
- etc.
|
49
|
+
|
50
|
+
The <scope> can be empty (e.g. if the change is a global or difficult to assign
|
51
|
+
to a single component), in which case the parentheses are omitted.
|
52
|
+
|
53
|
+
Also do your best to factor commits appropriately, ie not too large with
|
54
|
+
unrelated things in the same commit, and not too small with the same small
|
55
|
+
change applied N times in N different commits. If there was some accidental
|
56
|
+
reformatting or whitespace changes during the course of your commits, please
|
57
|
+
rebase them away before submitting the MR.
|
58
|
+
|
59
|
+
### Files
|
60
|
+
|
61
|
+
All files must be 80 columns width formatted (actually 79), exception only
|
62
|
+
when it is really not possible.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright (c) 2017-2019 Make.org
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
Knife Sync
|
2
|
+
==========
|
3
|
+
|
4
|
+
Knife Sync is a plugin knife to check that your local chef-repo
|
5
|
+
and the Chef server are well synchronized.
|
6
|
+
|
7
|
+
It displays sync state of following Chef policies :
|
8
|
+
- Nodes Run-list
|
9
|
+
- Roles
|
10
|
+
- Environments
|
11
|
+
- Data Bags
|
12
|
+
|
13
|
+
Installation
|
14
|
+
------------
|
15
|
+
|
16
|
+
$ gem install knife-sync
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
20
|
+
|
21
|
+
This plugin adds the following set of subcommands:
|
22
|
+
|
23
|
+
knife sync node [NODE] (options)
|
24
|
+
knife sync role [ROLE] (options)
|
25
|
+
knife sync environment [ENVIRONMENT] (options)
|
26
|
+
knife sync role [BAG] [ITEM] (options)
|
27
|
+
|
28
|
+
Available options:
|
29
|
+
|
30
|
+
--diff Show differences between items
|
31
|
+
--abbrev Abbrev diff path as string instead of array
|
32
|
+
|
33
|
+
Release
|
34
|
+
-------
|
35
|
+
|
36
|
+
To Rubygems:
|
37
|
+
|
38
|
+
```
|
39
|
+
rake clobber
|
40
|
+
rake build
|
41
|
+
gem push pkg/knife-sync-$VERSION.gem
|
42
|
+
```
|
43
|
+
|
44
|
+
Contributing
|
45
|
+
------------
|
46
|
+
|
47
|
+
Please read carefully [CONTRIBUTING.md](CONTRIBUTING.md) before making a merge
|
48
|
+
request.
|
49
|
+
|
50
|
+
License and Author
|
51
|
+
------------------
|
52
|
+
|
53
|
+
- Author:: Sylvain Arrambourg (<saye@sknss.net>)
|
54
|
+
|
55
|
+
```text
|
56
|
+
Copyright (c) 2017-2019 Make.org
|
57
|
+
|
58
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
59
|
+
you may not use this file except in compliance with the License.
|
60
|
+
You may obtain a copy of the License at
|
61
|
+
|
62
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
63
|
+
|
64
|
+
Unless required by applicable law or agreed to in writing, software
|
65
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
66
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
67
|
+
See the License for the specific language governing permissions and
|
68
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019 Make.org
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
|
22
|
+
RSpec::Core::RakeTask.new(:spec) { |task| task.verbose = false }
|
23
|
+
|
24
|
+
task default: 'spec'
|
data/bin/console
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Make.org
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'bundler/setup'
|
21
|
+
require 'knife/sync'
|
22
|
+
|
23
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
24
|
+
# with your gem easier. You can also use a different console, if you like.
|
25
|
+
|
26
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
27
|
+
# require "pry"
|
28
|
+
# Pry.start
|
29
|
+
|
30
|
+
require 'irb'
|
31
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
#
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
set -euo pipefail
|
18
|
+
IFS=$'\n\t'
|
19
|
+
set -vx
|
20
|
+
|
21
|
+
bundle install
|
22
|
+
|
23
|
+
# Do any other automated setup that you need to do here
|
data/knife-sync.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
lib = File.expand_path('lib', __dir__)
|
19
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
20
|
+
require 'knife-sync/version'
|
21
|
+
|
22
|
+
Gem::Specification.new do |spec|
|
23
|
+
spec.name = 'knife-sync'
|
24
|
+
spec.version = Knife::Sync::VERSION
|
25
|
+
spec.authors = ['Sylvain Arrambourg']
|
26
|
+
spec.email = ['incoming+sre-gems/knife-sync@incoming.gitlab.com']
|
27
|
+
spec.license = 'Apache-2.0'
|
28
|
+
|
29
|
+
spec.summary = 'Knife Sync Plugin'
|
30
|
+
spec.description = 'Knife Sync Plugin'
|
31
|
+
spec.homepage = 'https://gitlab.com/sre-gems/knife-sync'
|
32
|
+
|
33
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
34
|
+
f.match(%r{^(test|spec|features)/})
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
|
40
|
+
spec.add_dependency 'hashdiff', '~> 0.3.0'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
43
|
+
spec.add_development_dependency 'chef', '>= 13.0'
|
44
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
45
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
46
|
+
spec.add_development_dependency 'rubocop', '~> 0.65'
|
47
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
class Knife
|
22
|
+
# DataBagSync class
|
23
|
+
# rubocop:disable Metrics/ClassLength
|
24
|
+
class DataBagSync < Chef::Knife
|
25
|
+
include DataBagSecretOptions
|
26
|
+
|
27
|
+
deps do
|
28
|
+
require 'chef/data_bag'
|
29
|
+
require 'chef/data_bag_item'
|
30
|
+
require 'chef/encrypted_data_bag_item'
|
31
|
+
require 'chef/knife/core/object_loader'
|
32
|
+
require 'chef/knife/data_bag_secret_options'
|
33
|
+
require 'hashdiff'
|
34
|
+
require 'find'
|
35
|
+
end
|
36
|
+
|
37
|
+
banner 'knife data bag sync [BAG] [ITEM] (options)'
|
38
|
+
category 'data bag'
|
39
|
+
|
40
|
+
option :diff,
|
41
|
+
long: '--diff',
|
42
|
+
description: 'Show differences between items'
|
43
|
+
|
44
|
+
option :abbrev,
|
45
|
+
long: '--abbrev',
|
46
|
+
description: 'Abbrev diff path as string instead of array'
|
47
|
+
|
48
|
+
def loader
|
49
|
+
@loader ||= Core::ObjectLoader.new(Chef::DataBagItem, ui)
|
50
|
+
end
|
51
|
+
|
52
|
+
def compare(chef_data_bag, local_data_bag)
|
53
|
+
chef_data_bag.each do |item, data|
|
54
|
+
if local_data_bag.key?(item)
|
55
|
+
compare_item(item, data, local_data_bag[item])
|
56
|
+
else
|
57
|
+
ui.error("Data bag item '#{item}' could not be locally found")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def compare_item(item, chef_item, local_item)
|
63
|
+
msg = "Item '#{item}':".ljust(50)
|
64
|
+
opts = config[:abbrev] ? {} : { array_path: true }
|
65
|
+
diff = ::HashDiff.diff(chef_item, local_item, opts)
|
66
|
+
diff.empty? ? show_success(msg) : show_error(msg, diff)
|
67
|
+
end
|
68
|
+
|
69
|
+
def data_bag_from_chef(data_bag)
|
70
|
+
items = find_chef_data_bag_items(data_bag)
|
71
|
+
if items.empty?
|
72
|
+
ui.error("No items founded in chef data bag '#{data_bag}'")
|
73
|
+
end
|
74
|
+
items
|
75
|
+
rescue Net::HTTPServerException
|
76
|
+
ui.error("Data bag '#{data_bag}' could not be found on chef server")
|
77
|
+
{}
|
78
|
+
end
|
79
|
+
|
80
|
+
def data_bag_path
|
81
|
+
config_path = Chef::Config[:data_bag_path]
|
82
|
+
config_path.is_a?(String) ? [config_path] : config_path
|
83
|
+
end
|
84
|
+
|
85
|
+
# rubocop:disable Metrics/MethodLength
|
86
|
+
def data_bag_from_file(data_bag, list)
|
87
|
+
items = nil
|
88
|
+
data_bag_path.map do |data_bag_path|
|
89
|
+
path = File.join(data_bag_path, data_bag)
|
90
|
+
next unless File.directory?(path)
|
91
|
+
|
92
|
+
items = find_local_data_bag_items(path, list)
|
93
|
+
if items.empty?
|
94
|
+
ui.error("No items founded in local data bag '#{data_bag}'")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
if items.nil?
|
99
|
+
ui.error("Data bag '#{data_bag}' could not be locally found")
|
100
|
+
items = {}
|
101
|
+
end
|
102
|
+
items
|
103
|
+
end
|
104
|
+
# rubocop:enable Metrics/MethodLength
|
105
|
+
|
106
|
+
def data_bag_item_from_chef(data_bag, item)
|
107
|
+
data_bag_item = Chef::DataBagItem.load(data_bag, item).raw_data
|
108
|
+
if encrypted?(data_bag_item) && secret
|
109
|
+
data_bag_item =
|
110
|
+
Chef::EncryptedDataBagItem.load(data_bag, item, secret).to_h
|
111
|
+
end
|
112
|
+
data_bag_item
|
113
|
+
rescue Net::HTTPServerException
|
114
|
+
ui.error("Item '#{item}' could not be found on chef server")
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def data_bag_item_from_file(data_bag_path, item)
|
119
|
+
path = Pathname.new(data_bag_path)
|
120
|
+
data = loader.load_from(path.parent, File.basename(path), item)
|
121
|
+
encrypted?(data) ? decrypt(item, data) : data
|
122
|
+
rescue SystemExit
|
123
|
+
ui.error("Data bag item #{item} could not be loaded")
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def decrypt(name, data)
|
128
|
+
if secret
|
129
|
+
Chef::EncryptedDataBagItem.new(data, secret).to_hash
|
130
|
+
else
|
131
|
+
ui.warn(
|
132
|
+
"Data bag item '#{name}' is encrypted, but no secret provided " \
|
133
|
+
'for decoding (will be ignored)'
|
134
|
+
)
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def find_chef_data_bag_items(data_bag)
|
140
|
+
Chef::DataBag.load(data_bag).to_hash.map do |item, _|
|
141
|
+
[item, data_bag_item_from_chef(data_bag, item)]
|
142
|
+
end.to_h
|
143
|
+
end
|
144
|
+
|
145
|
+
def find_local_data_bag_items(data_bag_path, list)
|
146
|
+
items = {}
|
147
|
+
::Find.find(data_bag_path) do |path|
|
148
|
+
item = File.basename(path, File.extname(path))
|
149
|
+
if File.file?(path) && list.include?(item)
|
150
|
+
items[item] = data_bag_item_from_file(data_bag_path, path)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
items.compact
|
154
|
+
end
|
155
|
+
|
156
|
+
def run
|
157
|
+
case @name_args.length
|
158
|
+
when 0
|
159
|
+
sync_data_bags(Chef::DataBag.list.keys)
|
160
|
+
when 1
|
161
|
+
sync_data_bags(@name_args)
|
162
|
+
when 2
|
163
|
+
sync_item(@name_args[0], @name_args[1])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def secret
|
168
|
+
encryption_secret_provided_ignore_encrypt_flag? ? read_secret : nil
|
169
|
+
end
|
170
|
+
|
171
|
+
def show_success(msg)
|
172
|
+
ui.info(msg + ui.color('properly synchronized.', :green))
|
173
|
+
end
|
174
|
+
|
175
|
+
def show_error(msg, diff)
|
176
|
+
ui.info(msg + ui.color('difference(s) found', :yellow))
|
177
|
+
pp(diff) if config[:diff]
|
178
|
+
end
|
179
|
+
|
180
|
+
def sync_data_bags(data_bags)
|
181
|
+
data_bags.each do |data_bag|
|
182
|
+
ui.info("--> Checking data bag '#{data_bag}'")
|
183
|
+
chef_data_bag = data_bag_from_chef(data_bag)
|
184
|
+
msg = "No items founded in chef data bag '#{data_bag}'"
|
185
|
+
next ui.error(msg) if chef_data_bag.empty?
|
186
|
+
|
187
|
+
local_data_bag = data_bag_from_file(data_bag, chef_data_bag.keys)
|
188
|
+
next if local_data_bag.empty?
|
189
|
+
|
190
|
+
compare(chef_data_bag, local_data_bag)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def sync_item(data_bag, item)
|
195
|
+
ui.info("-> Checking item '#{item}' from data bag '#{data_bag}'")
|
196
|
+
chef_item = data_bag_item_from_chef(data_bag, item)
|
197
|
+
local_item = data_bag_from_file(data_bag, [item])
|
198
|
+
if local_item.empty?
|
199
|
+
ui.error("Data bag item '#{item}' could not be locally found")
|
200
|
+
else
|
201
|
+
compare_item(item, chef_item, local_item[item])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
# rubocop:enable Metrics/ClassLength
|
207
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
class Knife
|
22
|
+
# EnvironmentSync class
|
23
|
+
class EnvironmentSync < Chef::Knife
|
24
|
+
deps do
|
25
|
+
require 'chef/environment'
|
26
|
+
require 'chef/knife/core/object_loader'
|
27
|
+
require 'hashdiff'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner 'knife environment sync [ENVIRONMENT] (options)'
|
31
|
+
category 'environment'
|
32
|
+
|
33
|
+
option :diff,
|
34
|
+
long: '--diff',
|
35
|
+
description: 'Show differences between items'
|
36
|
+
|
37
|
+
option :abbrev,
|
38
|
+
long: '--abbrev',
|
39
|
+
description: 'Abbrev diff path as string instead of array'
|
40
|
+
|
41
|
+
def loader
|
42
|
+
@loader ||= Core::ObjectLoader.new(Chef::Environment, ui)
|
43
|
+
end
|
44
|
+
|
45
|
+
def compare(env, chef_env, local_env)
|
46
|
+
msg = "--> Checking #{env}".ljust(50)
|
47
|
+
opts = config[:abbrev] ? {} : { array_path: true }
|
48
|
+
diff = ::HashDiff.diff(chef_env, local_env, opts)
|
49
|
+
diff.empty? ? show_success(msg) : show_error(msg, diff)
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_env_file(env)
|
53
|
+
config_path = Chef::Config[:environment_path]
|
54
|
+
env_paths = config_path.is_a?(String) ? [config_path] : config_path
|
55
|
+
env_paths.map do |env_path|
|
56
|
+
path_glob =
|
57
|
+
File.join(Chef::Util::PathHelper.escape_glob_dir(env_path), '**')
|
58
|
+
path_glob << "/#{env.gsub(/[_-]/, '{-,_}')}.{json,rb}"
|
59
|
+
Dir.glob(path_glob)
|
60
|
+
end.flatten
|
61
|
+
end
|
62
|
+
|
63
|
+
def env_from_chef(env)
|
64
|
+
Chef::Environment.load(env).to_hash
|
65
|
+
rescue Net::HTTPServerException
|
66
|
+
ui.error("Environment '#{env}' could not be found on chef server")
|
67
|
+
end
|
68
|
+
|
69
|
+
def env_from_file(env)
|
70
|
+
files = find_env_file(env.tr('-', '_'))
|
71
|
+
if files.empty?
|
72
|
+
ui.error("Environment '#{env}' could not be found on disk")
|
73
|
+
elsif files.count > 1
|
74
|
+
ui.error("Duplicate file environment for '#{env}'")
|
75
|
+
else
|
76
|
+
loader.object_from_file(files.first).to_hash
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def run
|
81
|
+
envs = name_args.empty? ? Chef::Environment.list.keys : name_args
|
82
|
+
envs.delete('_default')
|
83
|
+
envs.each do |env|
|
84
|
+
chef_env = env_from_chef(env)
|
85
|
+
local_env = env_from_file(env)
|
86
|
+
next if chef_env.nil? || local_env.nil?
|
87
|
+
|
88
|
+
compare(env, chef_env, local_env)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def show_success(msg)
|
93
|
+
ui.info(msg + ui.color('properly synchronized.', :green))
|
94
|
+
end
|
95
|
+
|
96
|
+
def show_error(msg, diff)
|
97
|
+
ui.info(msg + ui.color('difference(s) found', :yellow))
|
98
|
+
pp(diff) if config[:diff]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
class Knife
|
22
|
+
# NodeSync class
|
23
|
+
class NodeSync < Knife
|
24
|
+
deps do
|
25
|
+
require 'chef/node'
|
26
|
+
require 'chef/knife/core/object_loader'
|
27
|
+
require 'hashdiff'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner 'knife node sync [NODE] (options)'
|
31
|
+
category 'node'
|
32
|
+
|
33
|
+
option :diff,
|
34
|
+
long: '--diff',
|
35
|
+
description: 'Show differences between items'
|
36
|
+
|
37
|
+
option :abbrev,
|
38
|
+
long: '--abbrev',
|
39
|
+
description: 'Abbrev diff path as string instead of array'
|
40
|
+
|
41
|
+
def loader
|
42
|
+
@loader ||= Core::ObjectLoader.new(Chef::Node, ui)
|
43
|
+
end
|
44
|
+
|
45
|
+
def compare(node, chef_node, local_node)
|
46
|
+
msg = "--> Checking #{node}".ljust(50)
|
47
|
+
chef_node = chef_node.select { |k, _| local_node.key?(k) }
|
48
|
+
opts = config[:abbrev] ? {} : { array_path: true }
|
49
|
+
diff = ::HashDiff.diff(chef_node, local_node, opts)
|
50
|
+
diff.empty? ? show_success(msg) : show_error(msg, diff)
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_node_file(node)
|
54
|
+
config_path = Chef::Config[:node_path]
|
55
|
+
node_paths = config_path.is_a?(String) ? [config_path] : config_path
|
56
|
+
node_paths.map do |node_path|
|
57
|
+
path_glob =
|
58
|
+
File.join(Chef::Util::PathHelper.escape_glob_dir(node_path), '**')
|
59
|
+
path_glob << "/#{node.gsub(/[_-]/, '{-,_}')}.{json,rb}"
|
60
|
+
Dir.glob(path_glob)
|
61
|
+
end.flatten
|
62
|
+
end
|
63
|
+
|
64
|
+
def node_from_chef(node)
|
65
|
+
Chef::Node.load(node).to_hash
|
66
|
+
rescue Net::HTTPServerException
|
67
|
+
ui.error("Node '#{node}' could not be found on chef server")
|
68
|
+
end
|
69
|
+
|
70
|
+
def node_from_file(node)
|
71
|
+
files = find_node_file(node)
|
72
|
+
if files.empty?
|
73
|
+
ui.error("Node '#{node}' could not be found on disk")
|
74
|
+
elsif files.count > 1
|
75
|
+
ui.error("Duplicate file node for '#{node}'")
|
76
|
+
else
|
77
|
+
loader.object_from_file(files.first).to_hash
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def run
|
82
|
+
nodes = name_args.empty? ? Chef::Node.list.keys : name_args
|
83
|
+
nodes.each do |node|
|
84
|
+
chef_node = node_from_chef(node)
|
85
|
+
local_node = node_from_file(node)
|
86
|
+
next if chef_node.nil? || local_node.nil?
|
87
|
+
|
88
|
+
compare(node, chef_node, local_node)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def show_success(msg)
|
93
|
+
ui.info(msg + ui.color('properly synchronized.', :green))
|
94
|
+
end
|
95
|
+
|
96
|
+
def show_error(msg, diff)
|
97
|
+
ui.info(msg + ui.color('difference(s) found', :yellow))
|
98
|
+
pp(diff) if config[:diff]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
class Knife
|
22
|
+
# RoleSync class
|
23
|
+
class RoleSync < Knife
|
24
|
+
deps do
|
25
|
+
require 'chef/role'
|
26
|
+
require 'chef/knife/core/object_loader'
|
27
|
+
require 'hashdiff'
|
28
|
+
end
|
29
|
+
|
30
|
+
banner 'knife role sync [ROLE] (options)'
|
31
|
+
category 'role'
|
32
|
+
|
33
|
+
option :diff,
|
34
|
+
long: '--diff',
|
35
|
+
description: 'Show differences between items'
|
36
|
+
|
37
|
+
option :abbrev,
|
38
|
+
long: '--abbrev',
|
39
|
+
description: 'Abbrev diff path as string instead of array'
|
40
|
+
|
41
|
+
def loader
|
42
|
+
@loader ||= Knife::Core::ObjectLoader.new(Chef::Role, ui)
|
43
|
+
end
|
44
|
+
|
45
|
+
def compare(role, chef_role, local_role)
|
46
|
+
msg = "--> Checking #{role}".ljust(50)
|
47
|
+
opts = config[:abbrev] ? {} : { array_path: true }
|
48
|
+
diff = ::HashDiff.diff(chef_role, local_role, opts)
|
49
|
+
diff.empty? ? show_success(msg) : show_error(msg, diff)
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_role_file(role)
|
53
|
+
config_path = Chef::Config[:role_path]
|
54
|
+
role_paths = config_path.is_a?(String) ? [config_path] : config_path
|
55
|
+
role_paths.map do |path|
|
56
|
+
path_glob =
|
57
|
+
File.join(Chef::Util::PathHelper.escape_glob_dir(path), '**')
|
58
|
+
path_glob << "/#{role.gsub(/[_-]/, '{-,_}')}.{json,rb}"
|
59
|
+
Dir.glob(path_glob)
|
60
|
+
end.flatten
|
61
|
+
end
|
62
|
+
|
63
|
+
def role_from_chef(role)
|
64
|
+
Chef::Role.load(role).to_hash
|
65
|
+
rescue Net::HTTPServerException
|
66
|
+
ui.error("Role '#{role}' could not be found on chef server")
|
67
|
+
end
|
68
|
+
|
69
|
+
def role_from_file(role)
|
70
|
+
files = find_role_file(role)
|
71
|
+
if files.empty?
|
72
|
+
ui.error("Role '#{role}' could not be found on disk")
|
73
|
+
elsif files.count > 1
|
74
|
+
ui.error("Duplicate file role for '#{role}'")
|
75
|
+
else
|
76
|
+
loader.object_from_file(files.first).to_hash
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def run
|
81
|
+
roles = name_args.empty? ? Chef::Role.list.keys : name_args
|
82
|
+
roles.each do |role|
|
83
|
+
chef_role = role_from_chef(role)
|
84
|
+
local_role = role_from_file(role)
|
85
|
+
next if chef_role.nil? || local_role.nil?
|
86
|
+
|
87
|
+
compare(role, chef_role, local_role)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def show_success(msg)
|
92
|
+
ui.info(msg + ui.color('properly synchronized.', :green))
|
93
|
+
end
|
94
|
+
|
95
|
+
def show_error(msg, diff)
|
96
|
+
ui.info(msg + ui.color('difference(s) found', :yellow))
|
97
|
+
pp(diff) if config[:diff]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 Make.org
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
# Define version
|
19
|
+
module Knife
|
20
|
+
# KnifeSync Plugin
|
21
|
+
module Sync
|
22
|
+
VERSION = '1.0.0-a'
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.a
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sylvain Arrambourg
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashdiff
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chef
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.65'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.65'
|
97
|
+
description: Knife Sync Plugin
|
98
|
+
email:
|
99
|
+
- incoming+sre-gems/knife-sync@incoming.gitlab.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".gitlab-ci.yml"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-version"
|
108
|
+
- CONTRIBUTING.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- knife-sync.gemspec
|
116
|
+
- lib/chef/knife/data_bag_sync.rb
|
117
|
+
- lib/chef/knife/environment_sync.rb
|
118
|
+
- lib/chef/knife/node_sync.rb
|
119
|
+
- lib/chef/knife/role_sync.rb
|
120
|
+
- lib/knife-sync/version.rb
|
121
|
+
homepage: https://gitlab.com/sre-gems/knife-sync
|
122
|
+
licenses:
|
123
|
+
- Apache-2.0
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.3.1
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.7.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Knife Sync Plugin
|
145
|
+
test_files: []
|