knife-sharp 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +91 -39
- data/ext/sharp-config.yml +3 -1
- data/lib/chef/knife/sharp-align.rb +9 -0
- data/lib/knife-sharp.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
knife-sharp adds several handy features to knife, adapted to our workflow @ Fotolia.
|
4
4
|
Features:
|
5
|
-
* align : sync data bags, roles and cookbook versions between a local git
|
5
|
+
* align : sync data bags, roles and cookbook versions between a local git branch and a chef server
|
6
6
|
* backup : dump environments, roles and data bags to local json files
|
7
7
|
* server : switch between chef servers using multiple knife.rb config files
|
8
8
|
|
9
9
|
# Tell me more
|
10
10
|
|
11
|
-
When you want an environment to reflect a given branch you have to check by hand (or using our consistency plugin), and some mistakes can be made.
|
11
|
+
When you want an environment to reflect a given branch you have to check by hand (or using our consistency plugin), and some mistakes can be made.
|
12
|
+
This plugin aims to help to push the right version into an environment.
|
12
13
|
|
13
14
|
It also allows to adopt a review workflow for main chef components :
|
14
15
|
* Track data bags, roles (as JSON files) and cookbooks in your Chef git repository
|
@@ -21,48 +22,91 @@ It also allows to adopt a review workflow for main chef components :
|
|
21
22
|
|
22
23
|
<pre>
|
23
24
|
$ git branch
|
24
|
-
...
|
25
|
+
[...]
|
26
|
+
* ldap
|
25
27
|
master
|
26
|
-
|
27
|
-
|
28
|
-
$ knife environment show
|
28
|
+
[...]
|
29
|
+
|
30
|
+
$ knife environment show production
|
29
31
|
chef_type: environment
|
30
32
|
cookbook_versions:
|
31
|
-
...
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
* infrastructure/
|
44
|
-
|
45
|
-
*
|
46
|
-
|
47
|
-
*
|
48
|
-
|
49
|
-
*
|
33
|
+
[...]
|
34
|
+
apache: 0.0.6
|
35
|
+
ldap: 0.0.3
|
36
|
+
[...]
|
37
|
+
|
38
|
+
$ knife sharp align ldap production
|
39
|
+
== Cookbooks ==
|
40
|
+
* ldap is not up-to-date (local: 0.0.4/remote: 0.0.3)
|
41
|
+
* apache is not up-to-date (local: 0.0.7/remote: 0.0.6)
|
42
|
+
> Update ldap cookbook to 0.0.4 on server ? Y/N/(A)ll/(Q)uit [N] y
|
43
|
+
> Update apache cookbook to 0.0.4 on server ? Y/N/(A)ll/(Q)uit [N] y
|
44
|
+
== Data bags ==
|
45
|
+
* infrastructure/services data bag item is not up-to-date
|
46
|
+
* Skipping infrastructure/services data bag (ignore list)
|
47
|
+
* Data bags are up-to-date.
|
48
|
+
== Roles ==
|
49
|
+
* Roles are up-to-date.
|
50
|
+
> Proceed ? (Y/N) y
|
51
|
+
* Uploading cookbook(s) ldap, apache
|
52
|
+
* Bumping ldap to 0.0.4 for environment production
|
53
|
+
* Bumping apache to 0.0.7 for environment production
|
50
54
|
</pre>
|
51
55
|
|
52
56
|
Then we can check environment :
|
53
57
|
|
54
58
|
<pre>
|
55
|
-
$ knife environment show
|
59
|
+
$ knife environment show production
|
56
60
|
chef_type: environment
|
57
61
|
cookbook_versions:
|
58
|
-
...
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
[...]
|
63
|
+
apache: 0.0.7
|
64
|
+
ldap: 0.0.4
|
65
|
+
[...]
|
66
|
+
|
67
|
+
$ knife sharp align ldap production
|
68
|
+
== Cookbooks ==
|
69
|
+
* Environment production is up-to-date.
|
70
|
+
[...]
|
63
71
|
</pre>
|
64
72
|
|
65
|
-
|
73
|
+
Cookbooks, data_bags and roles are uploaded, and cookbook versions updated in given environment.
|
74
|
+
|
75
|
+
To use all of these features, your knife.rb(s) must provide paths for cookbooks, data bags and roles (see [configuration](#Configuration))
|
76
|
+
|
77
|
+
### Ignore list
|
78
|
+
|
79
|
+
In a "multi chef server" environment (e.g development/production), you might want to ignore some updates on a given chef server, for instance:
|
80
|
+
* not uploading a test cookbook on your production server
|
81
|
+
* not updating DNS domain with production's one on your dev server
|
82
|
+
* avoid overriding data you are currently working on
|
83
|
+
|
84
|
+
Those items can be specified in sharp config file:
|
85
|
+
```yaml
|
86
|
+
prod: # chef server name, knife-prod.rb client config
|
87
|
+
ignore_cookbooks: [ tests ]
|
88
|
+
|
89
|
+
dev:
|
90
|
+
ignore_databags: [ infrastructure/dns ]
|
91
|
+
ignore_roles: [ webserver ]
|
92
|
+
```
|
93
|
+
|
94
|
+
(more in [sharp-config](ext/sharp-config.yml))
|
95
|
+
|
96
|
+
### Downgrading cookbook versions
|
97
|
+
|
98
|
+
By default, `knife sharp align` will only try to upgrade cookbook (e.g local version > server version)
|
99
|
+
It is possible to allow downgrading using `--force-align` (`-f`) command line switch.
|
100
|
+
|
101
|
+
Example:
|
102
|
+
<pre>
|
103
|
+
knife sharp align master production -f
|
104
|
+
On server dev
|
105
|
+
== Cookbooks ==
|
106
|
+
* syslog is to be downgraded (local: 0.0.44/remote: 0.0.45)
|
107
|
+
* sudo is to be downgraded (local: 0.0.8/remote: 0.0.9)
|
108
|
+
[...]
|
109
|
+
</pre>
|
66
110
|
|
67
111
|
## Backup
|
68
112
|
|
@@ -137,25 +181,33 @@ The plugin will search in 2 places for its config file :
|
|
137
181
|
|
138
182
|
An example config file is provided in ext/.
|
139
183
|
|
140
|
-
A working knife setup is also required (cookbook/role/data bag paths depending on the desired features)
|
184
|
+
A working knife setup is also required (cookbook/role/data bag paths depending on the desired features).
|
185
|
+
|
186
|
+
Fully enabled Sharp needs:
|
187
|
+
```ruby
|
188
|
+
cookbook_path '/home/jamiez/chef/cookbooks'
|
189
|
+
data_bag_path '/home/jamiez/chef/data_bags'
|
190
|
+
role_path '/home/jamiez/chef/roles'
|
191
|
+
```
|
192
|
+
in knife.rb
|
141
193
|
|
142
194
|
## Cookbooks path & git
|
143
195
|
If your cookbook_path is not the root of your git directory then the grit gem will produce an error. This can be circumvented by adding the following directive in your config file :
|
144
196
|
|
145
|
-
|
197
|
+
```yaml
|
146
198
|
global:
|
147
199
|
git_cookbook_path: "/home/nico/sysadmin/chef/"
|
148
|
-
|
200
|
+
```
|
149
201
|
|
150
202
|
As we version more than the cookbooks in the repo.
|
151
203
|
|
152
204
|
## Logging
|
153
205
|
It's good to have things logged. The plugin can do it for you. Add this to your config file
|
154
|
-
|
206
|
+
```yaml
|
155
207
|
logging:
|
156
208
|
enabled: true
|
157
209
|
destination: "~/.chef/sharp.log"
|
158
|
-
|
210
|
+
```
|
159
211
|
|
160
212
|
It will log uploads, bumps and databags to the standard logger format.
|
161
213
|
|
@@ -163,12 +215,12 @@ It will log uploads, bumps and databags to the standard logger format.
|
|
163
215
|
|
164
216
|
want a completion on changing servers ?
|
165
217
|
|
166
|
-
|
218
|
+
```sh
|
167
219
|
alias kss="knife sharp server"
|
168
220
|
|
169
221
|
function knife_servers { reply=($(ls .chef/knife-*.rb | sed -r 's/.*knife-([a-zA-Z0-9]+)\.rb/\1/' )); }
|
170
222
|
compctl -K knife_servers kss
|
171
|
-
|
223
|
+
```
|
172
224
|
|
173
225
|
# Credits
|
174
226
|
|
data/ext/sharp-config.yml
CHANGED
@@ -20,8 +20,10 @@ notification:
|
|
20
20
|
|
21
21
|
# ignore cookbooks/data bags/roles depending on chef server
|
22
22
|
# key is the name of your server (in a knife sharp server sense)
|
23
|
-
|
23
|
+
production:
|
24
24
|
ignore_cookbooks: [ tests ]
|
25
|
+
|
26
|
+
sandboxnico:
|
25
27
|
ignore_databags: [ staff/admin, infrastructure/mail ]
|
26
28
|
ignore_roles: [ webserver ]
|
27
29
|
|
@@ -14,6 +14,12 @@ module KnifeSharp
|
|
14
14
|
:default => false
|
15
15
|
end
|
16
16
|
|
17
|
+
option :force_align,
|
18
|
+
:short => "-f",
|
19
|
+
:long => "--force-align",
|
20
|
+
:description => "force local cookbook versions, allow downgrade",
|
21
|
+
:default => false
|
22
|
+
|
17
23
|
option :dump_remote_only,
|
18
24
|
:short => "-B",
|
19
25
|
:long => "--dump-remote-only",
|
@@ -149,6 +155,9 @@ module KnifeSharp
|
|
149
155
|
if Chef::VersionConstraint.new("> #{remote_versions[cb]}").include?(local_versions[cb])
|
150
156
|
updated_versions[cb] = local_versions[cb]
|
151
157
|
ui.msg "* #{cb} is not up-to-date (local: #{local_versions[cb]}/remote: #{remote_versions[cb]})"
|
158
|
+
elsif Chef::VersionConstraint.new("> #{local_versions[cb]}").include?(remote_versions[cb]) and config[:force_align]
|
159
|
+
updated_versions[cb] = local_versions[cb]
|
160
|
+
ui.msg "* #{cb} is to be downgraded (local: #{local_versions[cb]}/remote: #{remote_versions[cb]})"
|
152
161
|
end
|
153
162
|
end
|
154
163
|
|
data/lib/knife-sharp.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-sharp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: chef
|