inspec-multi-server 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 233ae43391270727bcb530a2550ae009d73e727d
4
+ data.tar.gz: e364983590bd38301cc9060980681e09a78a385d
5
+ SHA512:
6
+ metadata.gz: 176636fe4a72743f0fa578be46c744e439db0ad4bb6b203135a0ccf4845c79db3fe954bb3cb9acc4e588049178d2d941c4b7bcfb7ddd5c2e3bc43b27f3af142a
7
+ data.tar.gz: 380c634b1a31926eafedd8374d4e0919215b79d894e0936db8a1b9a42dd05782aadc5b283781170e09e74b542cddc95bbdecddf22c032d7962e9c0d5a326dbb6
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inSpecMultiServer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Kaddu Patrick
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,113 @@
1
+ # InSpecMultiServer
2
+
3
+ Command line tool to run chef inspec tests on multiple unix servers. This gem writes a config to the home directory with support for multiple projects, stages and servers per project.
4
+
5
+ **Note**: There is currently no support for windows. The current version only works via ssh protocol.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'inspec-multi-server'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install inspec-multi-server
22
+
23
+ ## Example Config
24
+
25
+ Example config:
26
+
27
+ ```json
28
+ {
29
+ "cookbook-name": {
30
+ "development": {
31
+ "path": "/path/to/cookbook",
32
+ "servers": [
33
+ {
34
+ "user": "username",
35
+ "publickey": "~/.ssh/id_rsa",
36
+ "host": "localhost"
37
+
38
+ },
39
+ {
40
+ "user": "username",
41
+ "publickey": "~/.ssh/id_rsa",
42
+ "host": "localhost1"
43
+ }
44
+ ]
45
+ }
46
+ }
47
+ }
48
+
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ **Note**: You may need to run rbenv rehash to make the command available. Check your path if the command is not available.
54
+
55
+ To run the inspec-multi-server command line tool do the following:
56
+
57
+ Run inspec-multi-server to create example config:
58
+ ```ruby
59
+ $ inspec-multi-server
60
+ ```
61
+
62
+ Update ~/.inspec-multi-server with your settings:
63
+ ```bash
64
+ $ vim ~/.inspec-multi-server
65
+ ```
66
+
67
+ Run help:
68
+ ```ruby
69
+ $ inspec-multi-server --help
70
+ NAME
71
+ inspec-multi-server - command line tool for inspec to run inspec tests on multiple servers.
72
+
73
+ SYNOPSIS
74
+ inspec-multi-server [global options] command [command options] [arguments...]
75
+
76
+ VERSION
77
+ 0.0.4
78
+
79
+ GLOBAL OPTIONS
80
+ --help - Show this message
81
+ -v, --[no-]verbose - Show additional output.
82
+ --version - Display the program version
83
+
84
+ COMMANDS
85
+ help - Shows a list of commands or help for one command
86
+ run - Run inspec
87
+ ```
88
+
89
+ Run help on run command:
90
+ ```ruby
91
+ $ inspec-multi-server run --help
92
+ NAME
93
+ run - Run inspec
94
+
95
+ SYNOPSIS
96
+ inspec-multi-server [global options] run [command options]
97
+
98
+ DESCRIPTION
99
+ Run inspec on multiple servers.
100
+
101
+ COMMAND OPTIONS
102
+ --project=arg - project (default: cme-eventhub-core)
103
+ --stage=arg - stage (default: development)
104
+ --test=arg - test (default: all)
105
+ ```
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork it ( https://github.com/[my-github-username]/inSpecMultiServer/fork )
110
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
111
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
112
+ 4. Push to the branch (`git push origin my-new-feature`)
113
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'fileutils'
4
+ require 'json'
5
+ require 'colorize'
6
+ require 'open3'
7
+ require_relative '../lib/inspec-multi-server'
8
+ require 'bundler'
9
+ include GLI::App
10
+
11
+ require_relative '../lib/inspec-multi-server-commands'
12
+
13
+ program_desc 'command line tool for inspec to run inspec tests on multiple servers.'
14
+
15
+ version InSpecMultiServer::VERSION
16
+ config_file = File.expand_path(File.join('~', '.inspec-multi-server'))
17
+ if File.readable?(config_file)
18
+ settings = InSpecMultiServer::Config::Settings.load(config_file)
19
+ InSpecMultiServer::Config::Settings.current = settings
20
+ else
21
+ File.open(config_file, 'w') do |file|
22
+ file.write(File.read(File.join('lib','inSpecMultiServer','config','example_config.json')))
23
+ end
24
+ puts "No config File found. Created example config file in your home directory."
25
+ exit
26
+ end
27
+
28
+ # Use argument validation
29
+ arguments :strict
30
+
31
+ accept Array do |value|
32
+ value.split(/,/).map(&:strip)
33
+ end
34
+
35
+ switch([:v, :verbose], :desc => "Show additional output.")
36
+ exit run(ARGV)
37
+
38
+ on_error do |ex|
39
+ # evaluate to true or false
40
+ puts "Sorry, there was an issue! #{ex}".colorize(:red)
41
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inspec-multi-server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "inspec-multi-server"
8
+ spec.version = InSpecMultiServer::VERSION
9
+ spec.authors = ["Kaddu Patrick"]
10
+ spec.email = ["patrick.kaddu@novartis.com"]
11
+ spec.summary = %q{command line tool to run chef inspec tests on multiple servers.}
12
+ spec.description = %q{command line tool to run chef inspec tests on multiple servers.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "inspec", "~> 0.9.8"
24
+ spec.add_development_dependency('aruba', '~> 0.5')
25
+ spec.add_runtime_dependency('gli','2.12.0')
26
+ spec.add_runtime_dependency('net-ssh', '~> 2.9')
27
+ spec.add_runtime_dependency('colorize', '~> 0.7')
28
+ spec.add_runtime_dependency('highline')
29
+ spec.add_runtime_dependency('parseconfig')
30
+ end
@@ -0,0 +1 @@
1
+ require_relative 'inspec-multi-server/commands/run'
@@ -0,0 +1,5 @@
1
+ require_relative "inspec-multi-server/version"
2
+ require_relative "inspec-multi-server/config/config"
3
+
4
+ module InSpecMultiServer
5
+ end
@@ -0,0 +1,73 @@
1
+ desc 'Run inspec'
2
+ long_desc 'Run inspec tests on multiple servers.'
3
+
4
+ command :run do |c|
5
+ c.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage that InSpec is executed.', default_value: InSpecMultiServer::Config::Settings.default_stage)
6
+ c.flag([:project], desc: 'project', type: String, long_desc: 'What project to run the InSpec tests.', default_value: InSpecMultiServer::Config::Settings.default_project)
7
+ c.flag([:test], desc: 'test', type: String, long_desc: 'Which test you want to run.', default_value: 'all')
8
+
9
+ c.action do |global_options,options,args|
10
+ puts "Running InSpec...".colorize(:green)
11
+
12
+ @show = options[:all] ? :all : :first
13
+ @stage = options[:stage]
14
+ @project = options[:project]
15
+ @test = options[:test]
16
+ @cookbook_directory = InSpecMultiServer::Config::Settings.current.data[@project][@stage]['path']
17
+
18
+ validate
19
+
20
+ puts "Current cookbook directory is: #{@cookbook_directory}".colorize(:light_blue)
21
+ @settings = InSpecMultiServer::Config::Settings.current
22
+
23
+ run_inspec_test
24
+
25
+ puts "Done executing InSpec on #{@settings.data[@project][@stage]['servers'].size} servers. Check output above.".colorize(:yellow)
26
+ end
27
+ end
28
+
29
+ def run_inspec_test
30
+ @settings.data[@project][@stage]['servers'].each do |server|
31
+ if @test.eql?('all')
32
+ puts "Running all inspec tests on #{server['host']}".colorize(:yellow)
33
+ command = "bundle exec inspec exec test/ -i #{server['publickey']} -t ssh://#{server['user']}@#{server['host']}"
34
+ else
35
+ puts "Running inspec test #{@test} on #{server['host']}".colorize(:yellow)
36
+ command = "bundle exec inspec exec test/#{@test} -i #{server['publickey']} -t ssh://#{server['user']}@#{server['host']}"
37
+ end
38
+ puts "command: #{command}".colorize(:light_blue)
39
+ output, error, status = Open3.capture3(command, :chdir=>@cookbook_directory)
40
+
41
+ if error
42
+ error = "Server #{server['host']} not found. Do you have access to the server #{server['host']}?" if error.include?('SocketError')
43
+ if error.include?('zlib(finalizer): the stream was freed prematurely.')
44
+ # needed because of bug in zlib
45
+ puts error.colorize(:green)
46
+ puts output.colorize(:green)
47
+ else
48
+ raise error
49
+ end
50
+ else
51
+ # no error
52
+ puts output.colorize(:green)
53
+ end
54
+
55
+ unless status.success?
56
+ raise "Process did not complete succesfully, please check output."
57
+ end
58
+ end
59
+ end
60
+
61
+ def validate
62
+ raise "Stage not found. Did you specify the right stage on the command line? " if @stage.nil?
63
+ raise "Project not found. Did you specify the right project on the command line? " if @project.nil?
64
+ raise "Test spec not found. Did you specify the right test on the command line" if @test.nil?
65
+ raise "Test spec not found. Does the file actually exist? " unless @test == 'all' || File.exists?("#{cookbook_directory}/test/#{@test}")
66
+ raise "Cookbook directory not found. Did you configure the json config ~/.inspec-multi-server?" if @cookbook_directory.nil?
67
+ end
68
+
69
+ # error handler
70
+ on_error do |ex|
71
+ # evaluate to true or false
72
+ puts "Sorry, there was an issue! #{ex}".colorize(:red)
73
+ end
@@ -0,0 +1,40 @@
1
+ module InSpecMultiServer
2
+ module Config
3
+
4
+ class Settings
5
+ attr_reader :data, :file
6
+ def initialize(file)
7
+ @file = file
8
+ @data = JSON.parse(File.read(file))
9
+ end
10
+
11
+ def self.default_stage
12
+ 'development'
13
+ end
14
+
15
+ def self.default_project
16
+ 'cme-eventhub-core'
17
+ end
18
+
19
+ def self.current=(value)
20
+ Thread.current[:inspec_settings] = value
21
+ end
22
+
23
+ def self.current
24
+ Thread.current[:inspec_settings]
25
+ end
26
+
27
+ def self.cookbook_directory(path)
28
+ File.join(path)
29
+ end
30
+
31
+ def server(server)
32
+ servers[server]
33
+ end
34
+
35
+ def self.load(config)
36
+ InSpecMultiServer::Config::Settings.new(config)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ {
2
+ "cookbook-name": {
3
+ "development": {
4
+ "path": "/path/to/cookbook",
5
+ "servers": [
6
+ {
7
+ "user": "username",
8
+ "publickey": "~/.ssh/id_rsa",
9
+ "host": "localhost"
10
+
11
+ },
12
+ {
13
+ "user": "username",
14
+ "publickey": "~/.ssh/id_rsa",
15
+ "host": "localhost1"
16
+ }
17
+ ]
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ module InSpecMultiServer
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspec-multi-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kaddu Patrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: inspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gli
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.12.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: net-ssh
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: highline
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: parseconfig
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: command line tool to run chef inspec tests on multiple servers.
140
+ email:
141
+ - patrick.kaddu@novartis.com
142
+ executables:
143
+ - inspec-multi-server
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - bin/inspec-multi-server
153
+ - inspec-multi-server.gemspec
154
+ - lib/inspec-multi-server-commands.rb
155
+ - lib/inspec-multi-server.rb
156
+ - lib/inspec-multi-server/commands/run.rb
157
+ - lib/inspec-multi-server/config/config.rb
158
+ - lib/inspec-multi-server/config/example_config.json
159
+ - lib/inspec-multi-server/version.rb
160
+ homepage: ''
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.2.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: command line tool to run chef inspec tests on multiple servers.
184
+ test_files: []