File: README.md

package info (click to toggle)
serverspec-runner 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 192 kB
  • ctags: 18
  • sloc: ruby: 268; makefile: 6
file content (188 lines) | stat: -rw-r--r-- 6,304 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
serverspec-runner [![Gem Version](https://badge.fury.io/rb/serverspec-runner.svg)](http://badge.fury.io/rb/serverspec-runner)  [![BuildStatus](https://secure.travis-ci.org/hiracy/serverspec-runner.png)](http://travis-ci.org/hiracy/serverspec-runner)
======================

Simple execution framework for [serverspec](http://serverspec.org/).

----

## Installation

    $ gem install serverspec-runner

----

## Usage

initialize spec direcotries and create skeleton-specfiles.

    $ serverspec-runner -r /path/to/your_serverspec_root

Edit your [spec-files](http://serverspec.org/resource_types.html).

    $ vim  /path/to/your_serverspec_root/test_top_dir/.../your_serverspec_test.rb

Edit your infrastructure or middleware tests scenario to "scenario.yml".

```
test_top_dir:                # test directory top
    :                        # test hierarchy directories
  test_bottom_dir:           # test directory bottom
    - servername             # ssh-accessible ip address or fqdn. or alias
    - :
  - :
:
---
servername:                  # alias name(not required)
  host: 192.168.0.11         # ssh-accessible ip address or fqdn(required if alias exist)
  ssh_opts:                  # ssh options(not required)
    port: 22                 # ssh port option(not required)
    user: "anyone"           # ssh user option(not required)
    keys: ["~/.ssh/id_rsa"]  # ssh private keys option(not required)
      :                      # any other Net::SSH Options(not required)
  any_attribute: "aaa"       # host attributes. this example available to get "property[:any_attribute]" from your codes(not required)
  :
:
```

do tests.

    $ serverspec-runner -r /path/to/your_serverspec_root -s /path/to/your_scenario.yml

or

    $ cd /path/to/your_serverspec_root && serverspec-runner

You can also specify [ssh_options.yml](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html)(Net::SSH options) file by "-o" option for default ssh options.

    $ serverspec-runner -s /path/to/your_scenario.yml -o /path/to/your_ssh_options.yml

For example. You write serverspec code like this.

```
require 'spec_helper'

describe "nginx" do

  describe "check running" do
    describe process('nginx') do
      it { should be_running }
    end
  end

  describe file('/etc/logrotate.d/nginx') do
    it { should be_file }
    it { should contain "rotate 14" }
  end
end
```

You can get the following outputs.

* serverspec-runner -t aa  : asci-art table(default)

```
+-------------------------------------------+
|description                       | result |
+-------------------------------------------+
|example@anyhost-01(192.168.11.1)  |        |
|  nginx                           |        |
|    check running                 |        |
|      Process "nginx"             |        |
|        should be running         |   OK   |
|    File "/etc/logrotate.d/nginx" |        |
|      should be file              |   OK   |
|      should contain "rotate 14"  |   OK   |
|example@anyhost-02(192.168.11.2)  |        |
|  nginx                           |        |
|    check running                 |        |
|      Process "nginx"             |        |
|        should be running         |   OK   |
|    File "/etc/logrotate.d/nginx" |        |
|      should be file              |   OK   |
|      should contain "rotate 14"  |   NG   |
+-------------------------------------------+
```

* serverspec-runner -t mkd : markdown table format

```
|description                       | result |
|:---------------------------------|:------:|
|example@anyhost-01(192.168.11.1)  |        |
|  nginx                           |        |
|    check running                 |        |
|      Process "nginx"             |        |
|        should be running         |   OK   |
|    File "/etc/logrotate.d/nginx" |        |
|      should be file              |   OK   |
|      should contain "rotate 14"  |   OK   |
|example@anyhost-02(192.168.11.2)  |        |
|  nginx                           |        |
|    check running                 |        |
|      Process "nginx"             |        |
|        should be running         |   OK   |
|    File "/etc/logrotate.d/nginx" |        |
|      should be file              |   OK   |
|      should contain "rotate 14"  |   NG   |
```

this example parsed for markdown to that(use -e long option)

|description                                                      | result |
|:----------------------------------------------------------------|:------:|
|example@anyhost-01(192.168.11.1)                                 |        |
|  nginx check running Process "nginx" should be running          |   OK   |
|  nginx File "/etc/logrotate.d/nginx" should be file             |   OK   |
|  nginx File "/etc/logrotate.d/nginx" should contain "rotate 14" |   OK   |
|example@anyhost-01(192.168.11.2)                                 |        |
|  nginx check running Process "nginx" should be running          |   OK   |
|  nginx File "/etc/logrotate.d/nginx" should be file             |   OK   |
|  nginx File "/etc/logrotate.d/nginx" should contain "rotate 14" |   NG   |

* serverspec-runner -t bool : only 'ok' or 'ng' string

You can use for cluster monitoring system health.

```
ok
```

```
ng
```

* serverspec-runner -t csv : CSV file format

You can get result CSV format output and can use redirect to file.

```
description,,,,,result
example@anyhost-01(192.168.11.1),,,,,
,nginx,,,,
,,check running,,,
,,,Process "nginx",,
,,,,should be running,OK
,,File "/etc/logrotate.d/nginx",,,
,,,should be file,,OK
,,,should contain "rotate 14",,OK
example@anyhost-02(192.168.11.2),,,,,
,nginx,,,,
,,check running,,,
,,,Process "nginx",,
,,,,should be running,OK
,,File "/etc/logrotate.d/nginx",,,
,,,should be file,,OK
,,,should contain "rotate 14",,NG
```

For more detail. You can see from `serverspec-runner -h` command.

----

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request