knife-check 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.
- data/README.md +6 -0
- data/Rakefile +1 -0
- data/knife-check.gemspec +23 -0
- data/lib/chef/knife/knife-check.rb +109 -0
- data/lib/knife-check/version.rb +5 -0
- metadata +67 -0
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/knife-check.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require 'knife-check/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "knife-check"
|
|
7
|
+
s.version = Knife::Check::VERSION
|
|
8
|
+
s.authors = ["Vasiliev D.V."]
|
|
9
|
+
s.email = %w(vadv.mkn@gmail.com)
|
|
10
|
+
s.homepage = "https://github.com/vadv/knife-check"
|
|
11
|
+
s.summary = %q{Setup chef on machine.}
|
|
12
|
+
s.description = %q{Allows you to bootsrap machine and set role and env.}
|
|
13
|
+
s.licenses = %w(MIT)
|
|
14
|
+
|
|
15
|
+
s.add_dependency('chef')
|
|
16
|
+
|
|
17
|
+
s.rubyforge_project = "knife-check"
|
|
18
|
+
|
|
19
|
+
s.files = `git ls-files`.split("\n")
|
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
22
|
+
s.require_paths = %w(lib)
|
|
23
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require 'chef/knife'
|
|
2
|
+
|
|
3
|
+
module KnifePlugin
|
|
4
|
+
class Check < Chef::Knife
|
|
5
|
+
|
|
6
|
+
banner "knife check"
|
|
7
|
+
|
|
8
|
+
option :environments,
|
|
9
|
+
:short => '-e',
|
|
10
|
+
:long => '--environments',
|
|
11
|
+
:boolean => true,
|
|
12
|
+
:description => "Test only environment syntax"
|
|
13
|
+
option :roles,
|
|
14
|
+
:short => '-r',
|
|
15
|
+
:long => '--roles',
|
|
16
|
+
:boolean => true,
|
|
17
|
+
:description => "Test only role syntax"
|
|
18
|
+
option :nodes,
|
|
19
|
+
:short => '-n',
|
|
20
|
+
:long => '--nodes',
|
|
21
|
+
:boolean => true,
|
|
22
|
+
:description => "Test only node syntax"
|
|
23
|
+
option :databags,
|
|
24
|
+
:short => '-D',
|
|
25
|
+
:long => '--databags',
|
|
26
|
+
:boolean => true,
|
|
27
|
+
:description => "Test only databag syntax"
|
|
28
|
+
option :cookbooks,
|
|
29
|
+
:short => '-c',
|
|
30
|
+
:long => '--cookbooks',
|
|
31
|
+
:boolean => true,
|
|
32
|
+
:description => "Test only cookbook syntax"
|
|
33
|
+
option :all,
|
|
34
|
+
:short => '-a',
|
|
35
|
+
:long => '--all',
|
|
36
|
+
:boolean => true,
|
|
37
|
+
:default => true,
|
|
38
|
+
:description => "Test syntax of all roles, environments, nodes, databags and cookbooks"
|
|
39
|
+
|
|
40
|
+
deps do
|
|
41
|
+
require 'yajl'
|
|
42
|
+
require 'pathname'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run
|
|
46
|
+
if config[:roles]
|
|
47
|
+
test_object("roles/*", "role")
|
|
48
|
+
elsif config[:environments]
|
|
49
|
+
test_object("environments/*", "environment")
|
|
50
|
+
elsif config[:nodes]
|
|
51
|
+
test_object("nodes/*", "node")
|
|
52
|
+
elsif config[:databags]
|
|
53
|
+
test_databag("data_bags/*", "data bag")
|
|
54
|
+
elsif config[:cookbooks]
|
|
55
|
+
test_cookbooks("cookbooks")
|
|
56
|
+
elsif config[:all]
|
|
57
|
+
test_object("roles/*", "role")
|
|
58
|
+
test_object("environments/*", "environment")
|
|
59
|
+
test_object("nodes/*", "node")
|
|
60
|
+
test_databag("data_bags/*", "data bag")
|
|
61
|
+
test_cookbooks("cookbooks")
|
|
62
|
+
else
|
|
63
|
+
ui.msg("Usage: knife check --help")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Test all cookbooks
|
|
68
|
+
def test_cookbooks(path)
|
|
69
|
+
ui.msg("Testing all cookbooks...")
|
|
70
|
+
result = `knife cookbook test -a -o #{path}`
|
|
71
|
+
ui.msg(result)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Test object syntax
|
|
75
|
+
def test_object(dirname,type)
|
|
76
|
+
ui.msg("Finding type #{type} to test from #{dirname}")
|
|
77
|
+
check_syntax(dirname,nil,type)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Test databag syntax
|
|
81
|
+
def test_databag(dirname, type)
|
|
82
|
+
ui.msg("Finding type #{type} to test from #{dirname}")
|
|
83
|
+
dirs = Dir.glob(dirname).select { |d| File.directory?(d) }
|
|
84
|
+
dirs.each do |directory|
|
|
85
|
+
dir = Pathname.new(directory).basename
|
|
86
|
+
check_syntax("#{directory}/*", dir, type)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Common method to test file syntax
|
|
91
|
+
def check_syntax(dirpath, dir = nil, type)
|
|
92
|
+
files = Dir.glob("#{dirpath}").select { |f| File.file?(f) }
|
|
93
|
+
files.each do |file|
|
|
94
|
+
fname = Pathname.new(file).basename
|
|
95
|
+
if ("#{fname}".end_with?('.json'))
|
|
96
|
+
ui.msg("Testing file #{file}")
|
|
97
|
+
json = File.new(file, 'r')
|
|
98
|
+
parser = Yajl::Parser.new
|
|
99
|
+
hash = parser.parse(json)
|
|
100
|
+
elsif("#{fname}".end_with?('.rb'))
|
|
101
|
+
ui.msg("Testing file #{file}")
|
|
102
|
+
result = `ruby -wc #{file}`
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: knife-check
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Vasiliev D.V.
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: chef
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: Allows you to bootsrap machine and set role and env.
|
|
31
|
+
email:
|
|
32
|
+
- vadv.mkn@gmail.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- README.md
|
|
38
|
+
- Rakefile
|
|
39
|
+
- knife-check.gemspec
|
|
40
|
+
- lib/chef/knife/knife-check.rb
|
|
41
|
+
- lib/knife-check/version.rb
|
|
42
|
+
homepage: https://github.com/vadv/knife-check
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
57
|
+
requirements:
|
|
58
|
+
- - ! '>='
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubyforge_project: knife-check
|
|
63
|
+
rubygems_version: 1.8.25
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 3
|
|
66
|
+
summary: Setup chef on machine.
|
|
67
|
+
test_files: []
|