serverkit 0.5.0 → 0.5.1
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 +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -2
- data/README.md +44 -276
- data/Vagrantfile +6 -5
- data/doc/action_apply.md +58 -0
- data/doc/action_check.md +36 -0
- data/doc/action_inspect.md +39 -0
- data/doc/action_validate.md +24 -0
- data/doc/install.md +38 -0
- data/doc/plug_in.md +18 -0
- data/doc/recipe.md +75 -0
- data/doc/resource.md +22 -0
- data/doc/resource_command.md +18 -0
- data/doc/resource_directory.md +20 -0
- data/doc/resource_file.md +22 -0
- data/doc/resource_git.md +20 -0
- data/doc/resource_group.md +16 -0
- data/doc/resource_line.md +27 -0
- data/doc/resource_nothing.md +17 -0
- data/doc/resource_package.md +19 -0
- data/doc/resource_recipe.md +20 -0
- data/doc/resource_remote_file.md +22 -0
- data/doc/resource_service.md +15 -0
- data/doc/resource_symlink.md +17 -0
- data/doc/resource_template.md +23 -0
- data/doc/resource_user.md +20 -0
- data/doc/vagrant_integration.md +34 -0
- data/example/recipe.yml +0 -1
- data/images/server-colored.png +0 -0
- data/images/server-small.png +0 -0
- data/images/server.png +0 -0
- data/lib/serverkit/actions/validate.rb +0 -1
- data/lib/serverkit/command.rb +7 -2
- data/lib/serverkit/resources/base.rb +1 -1
- data/lib/serverkit/resources/git.rb +1 -1
- data/lib/serverkit/resources/group.rb +1 -1
- data/lib/serverkit/resources/line.rb +5 -5
- data/lib/serverkit/resources/user.rb +4 -1
- data/lib/serverkit/version.rb +1 -1
- data/serverkit.gemspec +1 -1
- metadata +29 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b5913dfd17ab82dcc688aba30f392c4fb36f02
|
4
|
+
data.tar.gz: b80f8bd60e1a500e5ca7b497d90c0d26144207e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 750ad9c4d49922d310ac45455566c78f98871c10318f751a8dfcbc41b5a7b597759b889df73de3167d0c0ddc94dc851e4ca62f70d24b350d5eb1c0df833dd4c4
|
7
|
+
data.tar.gz: 5054ae0860bfe29c22e489cc5f3efd55273bedc304d172595c7cb8a9c5c1bd0cd5eb5906d61ef3404b3c48fb8fa32babc29e9527cc6afaf2e7123d2dc5c2b2dc
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.5.1
|
2
|
+
- Fix user resource behavior on nil password case
|
3
|
+
|
1
4
|
## 0.5.0
|
2
5
|
- Add validation_script attribute on line resource
|
3
6
|
|
@@ -31,7 +34,7 @@
|
|
31
34
|
- Change some attribue names on user resource
|
32
35
|
|
33
36
|
## 0.4.2
|
34
|
-
- Fix bug on apply action exit
|
37
|
+
- Fix bug on apply action exit status
|
35
38
|
- Support case-insensitive or number log-level
|
36
39
|
|
37
40
|
## 0.4.1
|
@@ -51,7 +54,7 @@
|
|
51
54
|
- Change attributes naming rule: status -> state
|
52
55
|
|
53
56
|
## 0.3.3
|
54
|
-
- Return exit
|
57
|
+
- Return exit status 1 if any resource failed
|
55
58
|
|
56
59
|
## 0.3.2
|
57
60
|
- Fix git resource on git-clone
|
data/README.md
CHANGED
@@ -1,288 +1,56 @@
|
|
1
1
|
# Serverkit [](https://travis-ci.org/r7kamura/serverkit) [](https://codeclimate.com/github/r7kamura/serverkit)
|
2
|
-
|
2
|
+
Assemble servers from your recipe.
|
3
3
|
|
4
|
-
|
5
|
-
- [serverkit validate](#serverkit-validate)
|
6
|
-
- [serverkit inspect](#serverkit-inspect)
|
7
|
-
- [serverkit check](#serverkit-check)
|
8
|
-
- [serverkit apply](#serverkit-apply)
|
9
|
-
- [SSH support](#ssh-support)
|
10
|
-
- [Log](#log)
|
11
|
-
- [Recipe](#recipe)
|
12
|
-
- [Format](#format)
|
13
|
-
- [Variables](#variables)
|
14
|
-
- [Example](#example)
|
15
|
-
- [Resource](#resource)
|
16
|
-
- [Attributes](#attributes)
|
17
|
-
- [Type](#type)
|
18
|
-
- [Example](#example-1)
|
19
|
-
- [Handler](#handler)
|
20
|
-
- [Plug-in](#plug-in)
|
21
|
-
- [Vagrant](#vagrant)
|
4
|
+

|
22
5
|
|
23
6
|
## Usage
|
24
|
-
|
7
|
+
Describe the desired state, then `serverkit apply`.
|
25
8
|
|
26
|
-
|
27
|
-
|
28
|
-
For instance, it shows validation error if `source` attributes is missing in `remote_file` resource.
|
29
|
-
If any validation error is detected, it returns exit status 1.
|
30
|
-
|
31
|
-
```
|
32
|
-
$ serverkit validate recipe.yml
|
33
|
-
Error: source attribute is required in remote_file resource
|
34
|
-
Error: path attribute can't be unreadable path in recipe resource
|
35
|
-
```
|
36
|
-
|
37
|
-
### serverkit inspect
|
38
|
-
Shows fully-expanded recipe data in JSON format.
|
39
|
-
|
40
|
-
```
|
41
|
-
$ serverkit inspect recipe.yml
|
42
|
-
{
|
43
|
-
"resources": [
|
44
|
-
{
|
45
|
-
"type": "homebrew",
|
46
|
-
"name": "mysql"
|
47
|
-
},
|
48
|
-
{
|
49
|
-
"type": "homebrew",
|
50
|
-
"name": "redis"
|
51
|
-
},
|
52
|
-
{
|
53
|
-
"type": "homebrew_cask",
|
54
|
-
"name": "licecap"
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"type": "homebrew_cask",
|
58
|
-
"name": "alfred"
|
59
|
-
},
|
60
|
-
{
|
61
|
-
"type": "git",
|
62
|
-
"repository": "git@github.com:r7kamura/dotfiles.git",
|
63
|
-
"path": "/Users/r7kamura/src/github.com/r7kamura/dotfiles"
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"type": "symlink",
|
67
|
-
"source": "/Users/r7kamura/.zshrc",
|
68
|
-
"destination": "/Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc"
|
69
|
-
}
|
70
|
-
]
|
71
|
-
}
|
72
|
-
```
|
73
|
-
|
74
|
-
### serverkit check
|
75
|
-
Shows the difference between your recipe and the state of the target host.
|
76
|
-
If any difference is detected, it returns exit status 1.
|
77
|
-
|
78
|
-
```
|
79
|
-
$ serverkit check recipe.yml
|
80
|
-
[ OK ] homebrew mysql on localhost
|
81
|
-
[ OK ] homebrew redis on localhost
|
82
|
-
[ OK ] homebrew_cask licecap on localhost
|
83
|
-
[ OK ] homebrew_cask alfred on localhost
|
84
|
-
[ NG ] git git@github.com:r7kamura/dotfiles.git on localhost
|
85
|
-
[ NG ] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
86
|
-
```
|
87
|
-
|
88
|
-
### serverkit apply
|
89
|
-
Executes migration process to fill-in the gaps.
|
90
|
-
If any failure is detected, it returns exit status 1.
|
91
|
-
|
92
|
-
```
|
93
|
-
$ serverkit apply recipe.yml
|
94
|
-
[SKIP] homebrew mysql on localhost
|
95
|
-
[SKIP] homebrew redis on localhost
|
96
|
-
[SKIP] homebrew_cask licecap on localhost
|
97
|
-
[SKIP] homebrew_cask alfred on localhost
|
98
|
-
[DONE] git git@github.com:r7kamura/dotfiles.git on localhost
|
99
|
-
[DONE] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
100
|
-
```
|
101
|
-
|
102
|
-
### SSH support
|
103
|
-
Use `--hosts=` option to execute serverkit over SSH.
|
104
|
-
Serverkit does not require any installation on server-side.
|
105
|
-
If you want to specify SSH configuration, write it into your ~/.ssh/config.
|
106
|
-
|
107
|
-
```
|
108
|
-
$ serverkit apply recipe.yml --hosts=alpha.example.com
|
109
|
-
$ serverkit apply recipe.yml --hosts=alpha.example.com,bravo.example.com
|
110
|
-
```
|
111
|
-
|
112
|
-
### Log
|
113
|
-
You can change serverkit log level by passing `--log-level=` command line option.
|
114
|
-
Available values are `DEBUG`, `ERROR`, `FATAL`, `WARN`, OR `INFO` (default).
|
115
|
-
General result lines like `[SKIP] ...` and `[ OK ] ...` are logged with FATAL level,
|
116
|
-
and all shell commands executed on hosts are logged with DEBUG level.
|
117
|
-
Pass `--no-color` option if you would like to disable colored log outputs.
|
118
|
-
|
119
|
-
```
|
120
|
-
$ serverkit apply recipe.yml --hosts=alpha.example.com --log-level=debug --no-color
|
121
|
-
```
|
122
|
-
|
123
|
-
## Recipe
|
124
|
-
A recipe describes the desired state of your server.
|
125
|
-
It is mostly a collection of resources, defined using certain patterns.
|
126
|
-
|
127
|
-
### Format
|
128
|
-
A recipe can be specified as a path to one of the following patterns:
|
129
|
-
|
130
|
-
- JSON file
|
131
|
-
- YAML file named with \*.yaml or \*.yml
|
132
|
-
- ERB file named with \*.json.erb or \*.yml.erb
|
133
|
-
- Executable to output JSON
|
134
|
-
- Directory including recipe files recursively
|
135
|
-
|
136
|
-
```
|
137
|
-
$ serverkit apply recipe
|
138
|
-
$ serverkit apply recipe.json
|
139
|
-
$ serverkit apply recipe.json.erb
|
140
|
-
$ serverkit apply recipe.json.erb --variables=variables
|
141
|
-
$ serverkit apply recipe.json.erb --variables=variables.json
|
142
|
-
$ serverkit apply recipe.json.erb --variables=variables.json.erb
|
143
|
-
$ serverkit apply recipe.json.erb --variables=variables.yml
|
144
|
-
$ serverkit apply recipe.json.erb --variables=variables.yml.erb
|
145
|
-
$ serverkit apply recipe.json.erb --variables=variables/
|
146
|
-
$ serverkit apply recipe.yml
|
147
|
-
$ serverkit apply recipe.yml.erb
|
148
|
-
$ serverkit apply recipes/
|
149
|
-
```
|
150
|
-
|
151
|
-
### Variables
|
152
|
-
When using ERB recipe, you can also give optional variables file
|
153
|
-
that defines configurations in a Hash object for ERB template.
|
154
|
-
It supports similar format variation with Recipe.
|
155
|
-
In ERB template, you can use given variables via methods named after its keys.
|
156
|
-
|
157
|
-
### Example
|
158
|
-
This is an example recipe to install some packages, clone a git repository, and create a symlink.
|
159
|
-
|
160
|
-
```yml
|
161
|
-
# variables.yml
|
162
|
-
dotfiles_repository: r7kamura/dotfiles
|
163
|
-
user: r7kamura
|
164
|
-
```
|
165
|
-
|
166
|
-
```yml
|
167
|
-
# recipe.yml.erb
|
9
|
+
```sh
|
10
|
+
$ echo '
|
168
11
|
resources:
|
169
12
|
- type: package
|
170
13
|
name: mysql
|
171
14
|
- type: package
|
172
15
|
name: redis
|
173
|
-
|
174
|
-
|
175
|
-
path: /Users/<%= user %>/src/github.com/<%= dotfiles_repository %>
|
176
|
-
- type: symlink
|
177
|
-
source: /Users/<%= user %>/.zshrc
|
178
|
-
destination: /Users/<%= user %>/src/github.com/<%= dotfiles_repository %>/.zshrc
|
179
|
-
```
|
180
|
-
|
181
|
-
## Resource
|
182
|
-
A resource is a statement of configuration policy that describes the desired state for an item.
|
183
|
-
|
184
|
-
### Attributes
|
185
|
-
Each resource has different attributes along with its type.
|
186
|
-
By default, all types of resource can or must have the following attributes:
|
187
|
-
|
188
|
-
- type - what type this resource represents (required)
|
189
|
-
- check_script - pass shell script to override the `#check` phase
|
190
|
-
- recheck_script - pass shell script to override the `#recheck` phase (runned after `#apply`)
|
191
|
-
- id - change resource identifier used in log, and also used for `notify`
|
192
|
-
- notify - specify an Array of handler ids that should be applied after changed
|
193
|
-
|
194
|
-
### Type
|
195
|
-
A resource must have a valid type attribute like:
|
196
|
-
|
197
|
-
- [command](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/command.rb)
|
198
|
-
- [directory](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/directory.rb)
|
199
|
-
- [file](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/file.rb)
|
200
|
-
- [git](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/git.rb)
|
201
|
-
- [group](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/group.rb)
|
202
|
-
- [line](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/line.rb)
|
203
|
-
- [nothing](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/nothing.rb)
|
204
|
-
- [package](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/package.rb)
|
205
|
-
- [recipe](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/recipe.rb)
|
206
|
-
- [remote_file](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/remote_file.rb)
|
207
|
-
- [service](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/service.rb)
|
208
|
-
- [symlink](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/symlink.rb)
|
209
|
-
- [template](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/template.rb)
|
210
|
-
- [user](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/user.rb)
|
211
|
-
|
212
|
-
### Example
|
213
|
-
An example package resource that has type and name attributes.
|
214
|
-
|
215
|
-
```yml
|
216
|
-
resources:
|
217
|
-
- type: package
|
218
|
-
name: mysql
|
219
|
-
```
|
220
|
-
|
221
|
-
## Handler
|
222
|
-
When any changes are successfully applied to a resource and it has notify attribute,
|
223
|
-
it notifies handlers that are referenced by their id.
|
224
|
-
The notified handlers will run only once after all resources finished their applications.
|
225
|
-
Here's an example of restarting Dock on Mac OS X when its preferences change.
|
226
|
-
|
227
|
-
```yml
|
228
|
-
resources:
|
229
|
-
- type: defaults
|
230
|
-
domain: com.apple.dock
|
231
|
-
key: autohide
|
232
|
-
value: 1
|
233
|
-
notify:
|
234
|
-
- restart_dock
|
235
|
-
- type: defaults
|
236
|
-
domain: com.apple.dock
|
237
|
-
key: persistent-apps
|
238
|
-
value: []
|
239
|
-
notify:
|
240
|
-
- restart_dock
|
241
|
-
handlers:
|
242
|
-
- id: restart_dock
|
243
|
-
type: command
|
244
|
-
script: killall Dock
|
245
|
-
```
|
246
|
-
|
247
|
-
## Plug-in
|
248
|
-
A plug-in is provided as a gem.
|
249
|
-
Serverkit calls `Bundler.require(:default)` before running an action,
|
250
|
-
so you can add any behaviors to serverkit via gems defined in Gemfile.
|
251
|
-
For example, [serverkit-rbenv](https://github.com/r7kamura/serverkit-rbenv) gem
|
252
|
-
adds a custom resource type named `rbenv_ruby` by defining `Serverkit::Resources::RbenvRuby` class.
|
253
|
-
Serverkit finds `Serverkit::Resources::FooBar` resource class from `type: "foo_bar"`.
|
254
|
-
|
255
|
-
- [serverkit-atom](https://github.com/r7kamura/serverkit-atom)
|
256
|
-
- [serverkit-defaults](https://github.com/r7kamura/serverkit-defaults)
|
257
|
-
- [serverkit-homebrew](https://github.com/r7kamura/serverkit-homebrew)
|
258
|
-
- [serverkit-karabiner](https://github.com/r7kamura/serverkit-karabiner)
|
259
|
-
- [serverkit-rbenv](https://github.com/r7kamura/serverkit-rbenv)
|
260
|
-
|
261
|
-
```rb
|
262
|
-
# Gemfile
|
263
|
-
gem "serverkit"
|
264
|
-
gem "serverkit-atom"
|
265
|
-
gem "serverkit-defaults"
|
266
|
-
gem "serverkit-homebrew"
|
267
|
-
gem "serverkit-karabiner"
|
268
|
-
gem "serverkit-rbenv"
|
269
|
-
```
|
270
|
-
|
271
|
-
## Vagrant
|
272
|
-
[vagrant-serverkit](https://github.com/r7kamura/vagrant-serverkit)
|
273
|
-
helps you provision your vagrant box with serverkit.
|
274
|
-
|
275
|
-
```rb
|
276
|
-
# Vagrantfile
|
277
|
-
Vagrant.configure("2") do |config|
|
278
|
-
config.vm.box = "ubuntu/trusty64"
|
279
|
-
config.vm.provision :serverkit do |serverkit_config|
|
280
|
-
serverkit_config.recipe_path = "recipe.yml"
|
281
|
-
end
|
282
|
-
end
|
16
|
+
' > recipe.yml
|
17
|
+
$ serverkit apply recipe.yml
|
283
18
|
```
|
284
19
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
20
|
+
## Documentation
|
21
|
+
- [Install](/doc/install.md)
|
22
|
+
- [serverkit apply](/doc/action_apply.md)
|
23
|
+
- [serverkit check](/doc/action_check.md)
|
24
|
+
- [serverkit inspect](/doc/action_inspect.md)
|
25
|
+
- [serverkit validate](/doc/action_validate.md)
|
26
|
+
- [Recipe](/doc/recipe.md)
|
27
|
+
- [Resource](/doc/resource.md)
|
28
|
+
- [command](/doc/resource_command.md)
|
29
|
+
- [directory](/doc/resource_directory.md)
|
30
|
+
- [file](/doc/resource_file.md)
|
31
|
+
- [git](/doc/resource_git.md)
|
32
|
+
- [group](/doc/resource_group.md)
|
33
|
+
- [line](/doc/resource_line.md)
|
34
|
+
- [nothing](/doc/resource_nothing.md)
|
35
|
+
- [package](/doc/resource_package.md)
|
36
|
+
- [recipe](/doc/resource_recipe.md)
|
37
|
+
- [remote_file](/doc/resource_remote_file.md)
|
38
|
+
- [service](/doc/resource_service.md)
|
39
|
+
- [symlink](/doc/resource_symlink.md)
|
40
|
+
- [template](/doc/resource_template.md)
|
41
|
+
- [user](/doc/resource_user.md)
|
42
|
+
- [Plug-in](/doc/plug_in.md)
|
43
|
+
- [serverkit-atom](https://github.com/r7kamura/serverkit-atom)
|
44
|
+
- [serverkit-defaults](https://github.com/r7kamura/serverkit-defaults)
|
45
|
+
- [serverkit-homebrew](https://github.com/r7kamura/serverkit-homebrew)
|
46
|
+
- [serverkit-karabiner](https://github.com/r7kamura/serverkit-karabiner)
|
47
|
+
- [serverkit-rbenv](https://github.com/r7kamura/serverkit-rbenv)
|
48
|
+
- [serverkit-login_items](https://github.com/take/serverkit-login_items)
|
49
|
+
- [Vagrant integration](/doc/vagrant_integration.md)
|
50
|
+
|
51
|
+
## Similar tools
|
52
|
+
- [ansible/ansible](https://github.com/ansible/ansible)
|
53
|
+
- [fabric/fabric](https://github.com/fabric/fabric)
|
54
|
+
- [chef/chef](https://github.com/chef/chef)
|
55
|
+
- [puppetlabs/puppet](https://github.com/puppetlabs/puppet)
|
56
|
+
- [itamae-kitchen/itamae](https://github.com/itamae-kitchen/itamae)
|
data/Vagrantfile
CHANGED
@@ -4,9 +4,10 @@ Vagrant.configure("2") do |config|
|
|
4
4
|
config.plugin.add_dependency "vagrant-multiplug"
|
5
5
|
config.plugin.add_dependency "vagrant-serverkit", "0.0.5"
|
6
6
|
|
7
|
-
config.vm.provision
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
config.vm.provision(
|
8
|
+
:serverkit,
|
9
|
+
log_level: "DEBUG",
|
10
|
+
recipe_path: "example/recipe.yml",
|
11
|
+
variables_path: "example/variables.yml",
|
12
|
+
)
|
12
13
|
end
|
data/doc/action_apply.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# serverkit apply
|
2
|
+
`serverkit apply` is an executable action to execute migration process to fill-in the gaps
|
3
|
+
between the specified recipe and the state of the target host.
|
4
|
+
|
5
|
+
## Successful case
|
6
|
+
If no error was found, it returns exit status 0.
|
7
|
+
|
8
|
+
```
|
9
|
+
$ serverkit apply recipe.yml
|
10
|
+
[SKIP] homebrew mysql on localhost
|
11
|
+
[SKIP] homebrew redis on localhost
|
12
|
+
[SKIP] homebrew_cask licecap on localhost
|
13
|
+
[SKIP] homebrew_cask alfred on localhost
|
14
|
+
[DONE] git git@github.com:r7kamura/dotfiles.git on localhost
|
15
|
+
[DONE] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
16
|
+
$ echo $?
|
17
|
+
0
|
18
|
+
```
|
19
|
+
|
20
|
+
## Failed case
|
21
|
+
If any error was found, it returns exit status 1.
|
22
|
+
|
23
|
+
```
|
24
|
+
$ serverkit apply recipe.yml
|
25
|
+
[SKIP] homebrew mysql on localhost
|
26
|
+
[SKIP] homebrew redis on localhost
|
27
|
+
[SKIP] homebrew_cask licecap on localhost
|
28
|
+
[SKIP] homebrew_cask alfred on localhost
|
29
|
+
[FAIL] git git@github.com:r7kamura/dotfiles.git on localhost
|
30
|
+
[DONE] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
31
|
+
$ echo $?
|
32
|
+
1
|
33
|
+
```
|
34
|
+
|
35
|
+
## --hosts= option
|
36
|
+
Use `--hosts=` option to execute serverkit over SSH.
|
37
|
+
Serverkit does not require any installation on server-side.
|
38
|
+
You can run serverkit on multiple hosts by passing hosts in comma-separated style.
|
39
|
+
If you want to specify SSH configuration, write it into your ~/.ssh/config.
|
40
|
+
This option is also available in `serverkit check` action.
|
41
|
+
|
42
|
+
```
|
43
|
+
$ serverkit apply recipe.yml --hosts=alpha.example.com
|
44
|
+
$ serverkit apply recipe.yml --hosts=alpha.example.com,bravo.example.com
|
45
|
+
$ serverkit apply recipe.yml --hosts=app1,app2,app3
|
46
|
+
```
|
47
|
+
|
48
|
+
## --log-level option
|
49
|
+
You can change serverkit log level by passing `--log-level=` option with
|
50
|
+
`DEBUG`, `ERROR`, `FATAL`, `WARN`, or `INFO` (case-insensitive, and the default is `INFO`).
|
51
|
+
For example, the general result lines like `[SKIP] ...` and `[ OK ] ...` are logged with FATAL level,
|
52
|
+
and all shell commands executed on hosts are logged with DEBUG level.
|
53
|
+
The log output is colored by default.
|
54
|
+
Pass `--no-color` option if you want to disable colored log outputs.
|
55
|
+
|
56
|
+
```
|
57
|
+
$ serverkit apply recipe.yml --hosts=alpha.example.com --log-level=debug --no-color
|
58
|
+
```
|
data/doc/action_check.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# serverkit check
|
2
|
+
`serverkit check` is an executable action to show the difference between the specified recipe and
|
3
|
+
the state of the target host (a.k.a. "dry-run" in other tools).
|
4
|
+
Note that this action might do some destructive behaviors by resource implementations (e.g. `git fetch`).
|
5
|
+
This action takes the same options with `serverkit apply` action.
|
6
|
+
See [/doc/action_apply.md] for more details.
|
7
|
+
|
8
|
+
## Same case
|
9
|
+
If no difference was detected, it returns exit status 0.
|
10
|
+
|
11
|
+
```
|
12
|
+
$ serverkit check recipe.yml
|
13
|
+
[ OK ] homebrew mysql on localhost
|
14
|
+
[ OK ] homebrew redis on localhost
|
15
|
+
[ OK ] homebrew_cask licecap on localhost
|
16
|
+
[ OK ] homebrew_cask alfred on localhost
|
17
|
+
[ OK ] git git@github.com:r7kamura/dotfiles.git on localhost
|
18
|
+
[ OK ] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
19
|
+
$ echo $?
|
20
|
+
0
|
21
|
+
```
|
22
|
+
|
23
|
+
## Different case
|
24
|
+
If any difference was detected, it returns exit status 1.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ serverkit check recipe.yml
|
28
|
+
[ OK ] homebrew mysql on localhost
|
29
|
+
[ OK ] homebrew redis on localhost
|
30
|
+
[ OK ] homebrew_cask licecap on localhost
|
31
|
+
[ OK ] homebrew_cask alfred on localhost
|
32
|
+
[ NG ] git git@github.com:r7kamura/dotfiles.git on localhost
|
33
|
+
[ NG ] symlink /Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc on localhost
|
34
|
+
$ echo $?
|
35
|
+
1
|
36
|
+
```
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# serverkit inspect
|
2
|
+
`serverkit inspect` is an executable action to show fully-expanded recipe content in JSON format.
|
3
|
+
This action is useful as your recipe grows to a large size with using variables, nested recipe, and so on.
|
4
|
+
You can specify your recipe by passing its path in the same way as the other actions.
|
5
|
+
|
6
|
+
## Example
|
7
|
+
```
|
8
|
+
$ serverkit inspect recipe.yml
|
9
|
+
{
|
10
|
+
"resources": [
|
11
|
+
{
|
12
|
+
"type": "homebrew",
|
13
|
+
"name": "mysql"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"type": "homebrew",
|
17
|
+
"name": "redis"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"type": "homebrew_cask",
|
21
|
+
"name": "licecap"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"type": "homebrew_cask",
|
25
|
+
"name": "alfred"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"type": "git",
|
29
|
+
"repository": "git@github.com:r7kamura/dotfiles.git",
|
30
|
+
"path": "/Users/r7kamura/src/github.com/r7kamura/dotfiles"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"type": "symlink",
|
34
|
+
"source": "/Users/r7kamura/.zshrc",
|
35
|
+
"destination": "/Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# serverkit validate
|
2
|
+
`serverkit validate` is an executable action to check if a specified recipe is valid or not.
|
3
|
+
You can specify your recipe by passing its path in the same way as the other actions.
|
4
|
+
Note that the other actions (e.g. `inspect`, `check`, `apply`) also runs validation before its task.
|
5
|
+
|
6
|
+
## Successful case
|
7
|
+
If no error found, it returns exit status 0.
|
8
|
+
|
9
|
+
```
|
10
|
+
$ serverkit validate recipe.yml
|
11
|
+
$ echo $?
|
12
|
+
0
|
13
|
+
```
|
14
|
+
|
15
|
+
## Failed case
|
16
|
+
If any error found, it reports errors and returns exit status 1.
|
17
|
+
|
18
|
+
```
|
19
|
+
$ serverkit validate recipe.yml
|
20
|
+
Error: source attribute is required in remote_file resource
|
21
|
+
Error: path attribute can't be unreadable path in recipe resource
|
22
|
+
$ echo $?
|
23
|
+
1
|
24
|
+
```
|
data/doc/install.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Install
|
2
|
+
## Prerequisites
|
3
|
+
Ruby 2.0.0 or later is required.
|
4
|
+
|
5
|
+
## via Bundler
|
6
|
+
We recommend you to use [bundler](http://bundler.io/) to install serverkit and its plugins,
|
7
|
+
and run serverkit via `bundle exec serverkit`.
|
8
|
+
|
9
|
+
```rb
|
10
|
+
# Gemfile
|
11
|
+
source "https://rubygems.org"
|
12
|
+
gem "serverkit"
|
13
|
+
```
|
14
|
+
|
15
|
+
```
|
16
|
+
$ gem install bundler
|
17
|
+
$ bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
## via Gem
|
21
|
+
Instead you can simply install serverkit by `gem` command,
|
22
|
+
while you cannot use plugins without bundler.
|
23
|
+
|
24
|
+
```
|
25
|
+
$ gem install serverkit
|
26
|
+
```
|
27
|
+
|
28
|
+
## via Source
|
29
|
+
If you want to install serverkit from source code for any reason,
|
30
|
+
you can `git clone` the source code and `rake install` it.
|
31
|
+
bundler and git are both required in this method.
|
32
|
+
|
33
|
+
```
|
34
|
+
$ git clone https://github.com/r7kamura/serverkit.git
|
35
|
+
$ cd serverkit
|
36
|
+
$ bundle install
|
37
|
+
$ bundle exec rake install
|
38
|
+
```
|
data/doc/plug_in.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Plug-in
|
2
|
+
A serverkit plug-in is provided as a gem.
|
3
|
+
Serverkit calls `Bundler.require(:default)` before running an action,
|
4
|
+
so you can add any behaviors to serverkit via gems defined in Gemfile.
|
5
|
+
For example, [serverkit-rbenv](https://github.com/r7kamura/serverkit-rbenv) gem
|
6
|
+
adds a custom resource type named `rbenv_ruby` by defining `Serverkit::Resources::RbenvRuby` class.
|
7
|
+
Serverkit finds `Serverkit::Resources::FooBar` resource class from `type: "foo_bar"`.
|
8
|
+
|
9
|
+
```rb
|
10
|
+
# Gemfile
|
11
|
+
gem "serverkit"
|
12
|
+
gem "serverkit-atom"
|
13
|
+
gem "serverkit-defaults"
|
14
|
+
gem "serverkit-homebrew"
|
15
|
+
gem "serverkit-karabiner"
|
16
|
+
gem "serverkit-rbenv"
|
17
|
+
gem "serverkit-login_items"
|
18
|
+
```
|
data/doc/recipe.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Recipe
|
2
|
+
A recipe describes the desired state of your server.
|
3
|
+
It is mostly a collection of resources, defined using certain patterns.
|
4
|
+
|
5
|
+
## Format
|
6
|
+
A recipe can be specified as a path to one of the following patterns:
|
7
|
+
|
8
|
+
- JSON file
|
9
|
+
- YAML file named with \*.yaml or \*.yml
|
10
|
+
- ERB file named with \*.json.erb or \*.yml.erb
|
11
|
+
- Executable to output JSON
|
12
|
+
- Directory including recipe files recursively
|
13
|
+
|
14
|
+
```
|
15
|
+
$ serverkit apply recipe
|
16
|
+
$ serverkit apply recipe.json
|
17
|
+
$ serverkit apply recipe.json.erb
|
18
|
+
$ serverkit apply recipe.json.erb --variables=variables
|
19
|
+
$ serverkit apply recipe.json.erb --variables=variables.json
|
20
|
+
$ serverkit apply recipe.json.erb --variables=variables.json.erb
|
21
|
+
$ serverkit apply recipe.json.erb --variables=variables.yml
|
22
|
+
$ serverkit apply recipe.json.erb --variables=variables.yml.erb
|
23
|
+
$ serverkit apply recipe.json.erb --variables=variables/
|
24
|
+
$ serverkit apply recipe.yml
|
25
|
+
$ serverkit apply recipe.yml.erb
|
26
|
+
$ serverkit apply recipes/
|
27
|
+
```
|
28
|
+
|
29
|
+
## Variables
|
30
|
+
When using ERB recipe, you can also give optional variables file via `--variables=` option
|
31
|
+
that defines configurations in a Hash object for ERB template.
|
32
|
+
It supports similar format variation with Recipe.
|
33
|
+
In ERB template, you can use given variables via methods named after its keys.
|
34
|
+
|
35
|
+
## Handler
|
36
|
+
When any changes are successfully applied to a resource and it has notify attribute,
|
37
|
+
it notifies handlers that are referenced by their id.
|
38
|
+
The notified handlers will run only once after all resources finished their applications.
|
39
|
+
Here's an example of restarting Dock on Mac OS X when its preferences change.
|
40
|
+
|
41
|
+
## Example
|
42
|
+
```yml
|
43
|
+
# variables.yml
|
44
|
+
dotfiles_repository: r7kamura/dotfiles
|
45
|
+
user: r7kamura
|
46
|
+
```
|
47
|
+
|
48
|
+
```yml
|
49
|
+
# recipe.yml.erb
|
50
|
+
resources:
|
51
|
+
- type: package
|
52
|
+
name: mysql
|
53
|
+
- type: package
|
54
|
+
name: redis
|
55
|
+
- type: git
|
56
|
+
repository: git@github.com:<%= dotfiles_repository %>.git
|
57
|
+
path: /Users/<%= user %>/src/github.com/<%= dotfiles_repository %>
|
58
|
+
- type: symlink
|
59
|
+
source: /Users/<%= user %>/.zshrc
|
60
|
+
destination: /Users/<%= user %>/src/github.com/<%= dotfiles_repository %>/.zshrc
|
61
|
+
- type: defaults
|
62
|
+
domain: com.apple.dock
|
63
|
+
key: autohide
|
64
|
+
value: 1
|
65
|
+
notify:
|
66
|
+
- restart_dock
|
67
|
+
handlers:
|
68
|
+
- id: restart_dock
|
69
|
+
type: command
|
70
|
+
script: killall Dock
|
71
|
+
```
|
72
|
+
|
73
|
+
```
|
74
|
+
$ serverkit apply recipe.yml.erb --variables=variables.yml
|
75
|
+
```
|
data/doc/resource.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Resource
|
2
|
+
A resource is a statement of configuration policy that describes the desired state for an item.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
Each resource has different attributes along with its type.
|
6
|
+
By default, all types of resource can or must have the following attributes:
|
7
|
+
|
8
|
+
- type - what type this resource represents (required)
|
9
|
+
- check_script - pass shell script to override the `#check` phase
|
10
|
+
- recheck_script - pass shell script to override the `#recheck` phase (runned after `#apply`)
|
11
|
+
- id - change resource identifier used in log, and also used for `notify`
|
12
|
+
- notify - specify an Array of handler ids that should be applied after changed
|
13
|
+
|
14
|
+
## Example
|
15
|
+
Here is a tiny example recipe that has only one resource with `type` and `name` attributes.
|
16
|
+
It desceibes that there must be a mysql package in the target machine.
|
17
|
+
|
18
|
+
```yml
|
19
|
+
resources:
|
20
|
+
- type: package
|
21
|
+
name: mysql
|
22
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# command
|
2
|
+
`command` is a resource to execute a command on target hosts.
|
3
|
+
This resource takes a shell script to be executed.
|
4
|
+
|
5
|
+
## Attributes
|
6
|
+
- script - shell script to be executed (required, type: `String`)
|
7
|
+
|
8
|
+
## Example
|
9
|
+
This recipe ensures the login shell to be `/bin/zsh` on Mac OS X.
|
10
|
+
Note that `check_script` attribute (* this attribute is available on all resources)
|
11
|
+
is used to check if the current login shell is configured with `/bin/zsh` by `finger` command.
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
resources:
|
15
|
+
- type: command
|
16
|
+
check_script: "finger -l | grep -E 'Shell: /bin/zsh$'"
|
17
|
+
script: chsh -s /bin/zsh <%= ENV["USER"] %>
|
18
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# directory
|
2
|
+
`directory` is a resource to manage a directory on file system.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- group - directory group (type: `String`)
|
6
|
+
- mode - directory mode (type: `Integer`)
|
7
|
+
- owner - directory owner (type: `String`)
|
8
|
+
- path - directory path (required, type: `String`)
|
9
|
+
|
10
|
+
## Example
|
11
|
+
This recipe ensures a directory exists at `/home/foo/.ssh` on a remote host,
|
12
|
+
and its mode is `700`, and it is owned by user `foo`.
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
resources:
|
16
|
+
- type: directory
|
17
|
+
path: /home/foo/.ssh
|
18
|
+
mode: 700
|
19
|
+
owner: foo
|
20
|
+
```
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# file
|
2
|
+
`file` is a resource to manage a file on file system.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- content - file content (type: `String`). `remote_host` resource is recommended for complex content.
|
6
|
+
- group - file group (type: `String`)
|
7
|
+
- mode - file mode (type: `Integer`)
|
8
|
+
- owner - file owner (type: `String`)
|
9
|
+
- path - file path (required, type: `String`)
|
10
|
+
|
11
|
+
## Example
|
12
|
+
This recipe ensures a file exists at `/home/foo/.ssh/authorized_keys` on a remote host
|
13
|
+
with specified content, and its mode is `600`, and its owner is user `foo`.
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
resources:
|
17
|
+
- type: file
|
18
|
+
path: /home/foo/.ssh/authorized_keys
|
19
|
+
content: ...
|
20
|
+
mode: 600
|
21
|
+
owner: foo
|
22
|
+
```
|
data/doc/resource_git.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# git
|
2
|
+
`git` is a resource to ensure a git repository exists on a remote host.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- path - where repository is cloned (required, type: `String`)
|
6
|
+
- repository - repository URL (required, type: `String`)
|
7
|
+
- state - whether it must be same revision with origin (`"cloned"` or `"updated"`, default: `"cloned"`)
|
8
|
+
|
9
|
+
## Example
|
10
|
+
This recipe ensures a git repository is cloned from
|
11
|
+
`https://github.com/r7kamura/dotfiles.git` at
|
12
|
+
`/Users/r7kamura/src/github.com/r7kamura/dotfiles` on a remote host.
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
resources:
|
16
|
+
- type: git
|
17
|
+
path: /Users/r7kamura/src/github.com/r7kamura/dotfiles
|
18
|
+
repository: https://github.com/r7kamura/dotfiles.git
|
19
|
+
state: updated
|
20
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# group
|
2
|
+
`group` is a resource to ensure a group exists on a remote host.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- gid - group gid (type: `Integer`)
|
6
|
+
- name - group name (required, type: `String`)
|
7
|
+
|
8
|
+
## Example
|
9
|
+
This recipe ensures a group `staff` of gid `20` exists on a remote host.
|
10
|
+
|
11
|
+
```yaml
|
12
|
+
resources:
|
13
|
+
- type: group
|
14
|
+
gid: 20
|
15
|
+
name: staff
|
16
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# line
|
2
|
+
`line` is a resource to ensure a particular line is in a file,
|
3
|
+
or replace an existing line using regexp.
|
4
|
+
|
5
|
+
## Attributes
|
6
|
+
- path - file path on remote host (required, type: `String`)
|
7
|
+
- insert_after - regexp to specify where line will be inserted (type: `String`), prior last match
|
8
|
+
- insert_before - regexp to specify where line will be inserted (type: `String`), prior last match
|
9
|
+
- line - inserted line content (required, type: `String`)
|
10
|
+
- pattern - regexp to check if a line already exists or not (type: `String`)
|
11
|
+
- state - `"absent"` or `"present"` (default)
|
12
|
+
- validation_script - shell script to run before copying into place (type: `String`, Use `%{path}` in the command to indicate the current file to validate)
|
13
|
+
|
14
|
+
## Example
|
15
|
+
This recipe ensures a line `"%wheel ALL=(ALL) ALL"` is in `/etc/sudoers` before a line
|
16
|
+
matched with `Regexp.new("^#includedir")`, if no line matched with
|
17
|
+
`Regexp.new('%wheel +ALL=\(ALL\) ALL')` and `visudo -cf /path/to/tempfile` succeeded.
|
18
|
+
|
19
|
+
```yaml
|
20
|
+
resources:
|
21
|
+
- type: line
|
22
|
+
path: /etc/sudoers
|
23
|
+
pattern: '%wheel +ALL=\(ALL\) ALL'
|
24
|
+
line: "%wheel ALL=(ALL) ALL"
|
25
|
+
insert_before: "^#includedir"
|
26
|
+
validation_script: visudo -cf %{path}
|
27
|
+
```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# nothing
|
2
|
+
`nothing` is a resource to do nothing.
|
3
|
+
This is useful for handlers to run after other resources finished,
|
4
|
+
or useful for some debug use.
|
5
|
+
This resource always fails on check phase and succeeds on recheck phase.
|
6
|
+
|
7
|
+
## Attributes
|
8
|
+
No specific attributes for this resource,
|
9
|
+
but of course the default attributes are available on all resource types.
|
10
|
+
|
11
|
+
## Example
|
12
|
+
This is an example recipe to do nothing...
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
resources:
|
16
|
+
- type: nothing
|
17
|
+
```
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# package
|
2
|
+
`package` is a resource to ensure a specified package is installed
|
3
|
+
using the main package system on the target host OS (e.g. `yum`, `apt`, `homebrew`, ...).
|
4
|
+
|
5
|
+
## Attributes
|
6
|
+
- name - package name (required, type: `String`, e.g. `"nginx"`)
|
7
|
+
- options - additional command lien options (type: `String`, e.g. `"--HEAD"`)
|
8
|
+
- version - package version (type: `String`, some package systems don't support this)
|
9
|
+
|
10
|
+
## Example
|
11
|
+
This is an example recipe to install `mysql` and `nginx`.
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
resources:
|
15
|
+
- type: package
|
16
|
+
name: mysql
|
17
|
+
- type: package
|
18
|
+
name: nginx
|
19
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# recipe
|
2
|
+
`recipe` is a resource to include other resources in a specified recipe.
|
3
|
+
You can use any recipe format the same way as normal recipe,
|
4
|
+
and of course variables are available in included recipes.
|
5
|
+
`serverkit inspect` action, that shows fully-expanded resources,
|
6
|
+
might help you because nested recipes tend to become complex.
|
7
|
+
|
8
|
+
## Attributes
|
9
|
+
- path - path to an included recipe (required, type: `String`)
|
10
|
+
|
11
|
+
## Example
|
12
|
+
This is an example recipe to bundle other recipes
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
resources:
|
16
|
+
- type: recipe
|
17
|
+
path: homebrew.json.erb
|
18
|
+
- type: recipe
|
19
|
+
path: dotfiles.yml
|
20
|
+
```
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# remote_file
|
2
|
+
`remote_file` is a resource to transfer a file from a client machine to a remote machine.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- destination - file path on remote machine (required, type: `String`)
|
6
|
+
- group - file group (type: `String`)
|
7
|
+
- mode - file mode (type: `Integer`)
|
8
|
+
- owner - file owner (type: `String`)
|
9
|
+
- source - file path on client machine (required, type: `String`)
|
10
|
+
|
11
|
+
## Example
|
12
|
+
This recipe ensures a file exists at `/home/foo/.ssh/authorized_keys` on a remote host
|
13
|
+
with same content with `files/authorized_keys` on a client side.
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
resources:
|
17
|
+
- type: remote_file
|
18
|
+
destination: /home/foo/.ssh/authorized_keys
|
19
|
+
source: files/authorized_keys
|
20
|
+
mode: 600
|
21
|
+
owner: foo
|
22
|
+
```
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# service
|
2
|
+
`service` is a resource to manage services on remote hosts
|
3
|
+
by OS specific init systems (e.g. BSD init, systemd, upstart, ...).
|
4
|
+
|
5
|
+
## Attributes
|
6
|
+
- name - service name (required, type: `String`)
|
7
|
+
|
8
|
+
## Example
|
9
|
+
This is an example recipe to ensure `nginx` is running.
|
10
|
+
|
11
|
+
```yaml
|
12
|
+
resources:
|
13
|
+
- type: service
|
14
|
+
name: nginx
|
15
|
+
```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# symlink
|
2
|
+
`symlink` is a resource to ensure a symlink exists with specified source and destination.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- destination - symlink destination path on remote host (required, type: `String`)
|
6
|
+
- source - symlink source path on remote host (required, type: `String`)
|
7
|
+
|
8
|
+
## Example
|
9
|
+
This is an example recipe to ensure a symlink in remote host
|
10
|
+
from `/Users/foo/.bashrc` to `/Users/foo/dotfiles/.bashrc`.
|
11
|
+
|
12
|
+
```yaml
|
13
|
+
resources:
|
14
|
+
- type: symlink
|
15
|
+
destination: /Users/foo/dotfiles/.bashrc
|
16
|
+
source: /Users/foo/.bashrc
|
17
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# template
|
2
|
+
`template` is a resource to transfer a file from client host to remote host
|
3
|
+
with expanding ERB template with given variables.
|
4
|
+
|
5
|
+
## Attributes
|
6
|
+
- destination - file path on remote machine (required, type: `String`)
|
7
|
+
- group - file group (type: `String`)
|
8
|
+
- mode - file mode (type: `Integer`)
|
9
|
+
- owner - file owner (type: `String`)
|
10
|
+
- source - file path on client machine (required, type: `String`)
|
11
|
+
|
12
|
+
## Example
|
13
|
+
This recipe ensures a file exists at `/home/foo/.ssh/authorized_keys` on remote host
|
14
|
+
with same content with a expanded result of `files/authorized_keys.erb`.
|
15
|
+
|
16
|
+
```yaml
|
17
|
+
resources:
|
18
|
+
- type: remote_file
|
19
|
+
destination: /home/foo/.ssh/authorized_keys
|
20
|
+
source: files/authorized_keys.erb
|
21
|
+
mode: 600
|
22
|
+
owner: foo
|
23
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# user
|
2
|
+
`user` is a resource to ensure a user exists on remote host.
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
- gid - group gid (type: `Integer` or `String`)
|
6
|
+
- home - path to home directory (type: `String`)
|
7
|
+
- name - user name (required, type: `String`)
|
8
|
+
- password - user raw password (type: `String`, will be encrypted with SHA512)
|
9
|
+
- shell - log-in shell (type: `String`)
|
10
|
+
- system - pass `true` to make system user (`true` or `false`, default: `false`)
|
11
|
+
- uid - user uid (type: `Integer`)
|
12
|
+
|
13
|
+
## Example
|
14
|
+
This recipe ensures a user `foo` exists on remote host.
|
15
|
+
|
16
|
+
```yaml
|
17
|
+
resources:
|
18
|
+
- type: user
|
19
|
+
name: foo
|
20
|
+
```
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Vagrant integration
|
2
|
+
If you want to use serverkit with [Vagrant](https://www.vagrantup.com/),
|
3
|
+
there are 2 options to do it.
|
4
|
+
|
5
|
+
## --hosts=
|
6
|
+
One is to use pass the machine's host name via `--hosts=` option like below.
|
7
|
+
Note that `vagrant ssh-config` command outputs SSH configuration for the machine on vagrant
|
8
|
+
with `Host default`, and serverkit will use it by `--hosts=default` option.
|
9
|
+
|
10
|
+
```
|
11
|
+
$ vagrant ssh-config >> ~/.ssh/config
|
12
|
+
$ serverkit apply recipe.yml --hosts=default
|
13
|
+
```
|
14
|
+
|
15
|
+
## vagrant-serverkit
|
16
|
+
There is a 3rd party vagrant plugin called
|
17
|
+
[vagrant-serverkit](https://github.com/r7kamura/vagrant-serverkit).
|
18
|
+
It helps you provision your vagrant box with using serverkit.
|
19
|
+
|
20
|
+
```rb
|
21
|
+
# Vagrantfile
|
22
|
+
Vagrant.configure("2") do |config|
|
23
|
+
config.vm.box = "ubuntu/trusty64"
|
24
|
+
config.vm.provision(
|
25
|
+
:serverkit,
|
26
|
+
recipe_path: "recipe.yml",
|
27
|
+
)
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
```
|
32
|
+
$ vagrant plugin install vagrant-serverkit
|
33
|
+
$ vagrant up
|
34
|
+
```
|
data/example/recipe.yml
CHANGED
Binary file
|
Binary file
|
data/images/server.png
ADDED
Binary file
|
data/lib/serverkit/command.rb
CHANGED
@@ -8,8 +8,13 @@ require "serverkit/errors/missing_recipe_path_argument_error"
|
|
8
8
|
require "serverkit/errors/unknown_action_name_error"
|
9
9
|
|
10
10
|
module Serverkit
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# This class is responsible for command line interface.
|
12
|
+
# An instance of this class builds an instance of Actions::Base class,
|
13
|
+
# then calls its `#call` method, and it exits with exit status 0 unless any error found.
|
14
|
+
# This class should be used only from bin/serverkit executable.
|
15
|
+
# If you need to use serverkit's any feature from Ruby code,
|
16
|
+
# use a child of Actions::Base class instead because
|
17
|
+
# this class only focuses on command line interface.
|
13
18
|
class Command
|
14
19
|
LOG_LEVELS_TABLE = {
|
15
20
|
"" => Logger::INFO,
|
@@ -167,7 +167,7 @@ module Serverkit
|
|
167
167
|
run_command("mktemp -u 2>/dev/null || mktemp -u -t tmp").stdout.rstrip
|
168
168
|
end
|
169
169
|
|
170
|
-
# @note "metadata"
|
170
|
+
# @note "metadata" means a set of group, mode, and owner
|
171
171
|
# @param [String] destination
|
172
172
|
# @param [String] source
|
173
173
|
def move_remote_file_keeping_destination_metadata(source, destination)
|
@@ -7,7 +7,7 @@ module Serverkit
|
|
7
7
|
|
8
8
|
attribute :path, required: true, type: String
|
9
9
|
attribute :repository, required: true, type: String
|
10
|
-
attribute :state, default: DEFAULT_STATE, type: String
|
10
|
+
attribute :state, default: DEFAULT_STATE, inclusion: %w[cloned updated], type: String
|
11
11
|
|
12
12
|
# @note Override
|
13
13
|
def apply
|
@@ -44,14 +44,14 @@ module Serverkit
|
|
44
44
|
def applied_remote_file_content
|
45
45
|
case
|
46
46
|
when absent?
|
47
|
-
content.delete(line)
|
47
|
+
content.delete(line)
|
48
48
|
when insert_after
|
49
|
-
content.insert_after(Regexp.new(insert_after), line)
|
49
|
+
content.insert_after(Regexp.new(insert_after), line)
|
50
50
|
when insert_before
|
51
|
-
content.insert_before(Regexp.new(insert_before), line)
|
51
|
+
content.insert_before(Regexp.new(insert_before), line)
|
52
52
|
else
|
53
|
-
content.append(line)
|
54
|
-
end
|
53
|
+
content.append(line)
|
54
|
+
end.to_s
|
55
55
|
end
|
56
56
|
|
57
57
|
# @return [Serverkit::Resources::Line::Content]
|
@@ -60,8 +60,11 @@ module Serverkit
|
|
60
60
|
)
|
61
61
|
end
|
62
62
|
|
63
|
+
# @return [String, nil]
|
63
64
|
def encrypted_password
|
64
|
-
|
65
|
+
unless password.nil?
|
66
|
+
@encrypted_password ||= UnixCrypt::SHA512.build(password)
|
67
|
+
end
|
65
68
|
end
|
66
69
|
|
67
70
|
def get_remote_encrypted_password
|
data/lib/serverkit/version.rb
CHANGED
data/serverkit.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Serverkit::VERSION
|
8
8
|
spec.authors = ["Ryo Nakamura"]
|
9
9
|
spec.email = ["r7kamura@gmail.com"]
|
10
|
-
spec.summary = "
|
10
|
+
spec.summary = "Assemble servers from your recipe."
|
11
11
|
spec.homepage = "https://github.com/r7kamura/serverkit"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -211,9 +211,35 @@ files:
|
|
211
211
|
- Rakefile
|
212
212
|
- Vagrantfile
|
213
213
|
- bin/serverkit
|
214
|
+
- doc/action_apply.md
|
215
|
+
- doc/action_check.md
|
216
|
+
- doc/action_inspect.md
|
217
|
+
- doc/action_validate.md
|
218
|
+
- doc/install.md
|
219
|
+
- doc/plug_in.md
|
220
|
+
- doc/recipe.md
|
221
|
+
- doc/resource.md
|
222
|
+
- doc/resource_command.md
|
223
|
+
- doc/resource_directory.md
|
224
|
+
- doc/resource_file.md
|
225
|
+
- doc/resource_git.md
|
226
|
+
- doc/resource_group.md
|
227
|
+
- doc/resource_line.md
|
228
|
+
- doc/resource_nothing.md
|
229
|
+
- doc/resource_package.md
|
230
|
+
- doc/resource_recipe.md
|
231
|
+
- doc/resource_remote_file.md
|
232
|
+
- doc/resource_service.md
|
233
|
+
- doc/resource_symlink.md
|
234
|
+
- doc/resource_template.md
|
235
|
+
- doc/resource_user.md
|
236
|
+
- doc/vagrant_integration.md
|
214
237
|
- example/recipe.yml
|
215
238
|
- example/template.erb
|
216
239
|
- example/variables.yml
|
240
|
+
- images/server-colored.png
|
241
|
+
- images/server-small.png
|
242
|
+
- images/server.png
|
217
243
|
- lib/readable_validator.rb
|
218
244
|
- lib/regexp_validator.rb
|
219
245
|
- lib/required_validator.rb
|
@@ -288,6 +314,6 @@ rubyforge_project:
|
|
288
314
|
rubygems_version: 2.4.5
|
289
315
|
signing_key:
|
290
316
|
specification_version: 4
|
291
|
-
summary:
|
317
|
+
summary: Assemble servers from your recipe.
|
292
318
|
test_files: []
|
293
319
|
has_rdoc:
|