knife-runlist-compare 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2Q2YTIyZGIyZjMzNzI4ZDkyYmZhZGQ0Nzg1YWJhMTlkMDJiZGI3MQ==
5
+ data.tar.gz: !binary |-
6
+ MWM1NTBhNGEwOTBkZTc0ZWMxYzZhYzkwZWRkZTJjOTI4ZGM3NDE1NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MmM2OWVlZDY1MDE3NzhhNjkxOWJjNzAyZTZmMzNmZGE2OTM4NTBhZDY2MWNl
10
+ YjIzZGQ5MTM1OGI5MTQ1ZGQxMTkyNWQ5NmI1MzY5YjI2N2NjZDNmMDAzNzRi
11
+ MDQ4MTM3ZTliZDdiNDhjYjI4NGM5NGI1YzhiYjI2MjRlNDUzZTM=
12
+ data.tar.gz: !binary |-
13
+ NjQwYzA0MDEzMTk4M2QxZWI1YmVlZTFkM2FhNDdiOGE4YzNmZTc1ZjRiMTcz
14
+ ZGQxNDk3OTM1ZTYyZWE5Zjk0NzUyNDUyNTlhMDNkZTRlMDk3NjNlYzM3ZWYy
15
+ ZTk0MTI2NzIxNzExOWY4NjhlODU5MWE2YWU1YTU1NDdjZjcyNWQ=
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.gem
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 (July 18th, 2014)
2
+
3
+ Initial version.
@@ -0,0 +1,25 @@
1
+ Knife Runlist Compare
2
+ ----------
3
+ * Author:: Jon Cowie (<jonlives@gmail.com>)
4
+ * Copyright:: Copyright (c) 2014 Jon Cowie
5
+ * License:: MIT
6
+
7
+ The MIT License
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ Knife Runlist Compare
2
+ ===========
3
+ Knife Runlist Compare is is a Knife plugin which allows you, as the name suggests, to compare two Chef run_lists. It takes each run_list it is given, expands them into the list of recipes which would be executed on a node, and produces a diff of the differences between those recipe lists.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/knife-runlist-compare.png)](http://badge.fury.io/rb/knife-runlist-compare)
6
+
7
+ Installation
8
+ ------------
9
+
10
+ ### Gem Install
11
+ `knife-runlist-compare` is available on rubygems. Add the following to your `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'knife-runlist-compare'
15
+ ```
16
+
17
+ or install the gem manually:
18
+
19
+ ```bash
20
+ gem install knife-runlist-compare
21
+ ```
22
+
23
+ ### Usage
24
+ ```bash
25
+ knife runlist compare RUNLIST_1 RUNLIST_2 (options)
26
+ ```
27
+
28
+ ### Supported Options
29
+
30
+ #### Environment
31
+ The `environment` option allows you to specify the Chef environment to be used in the run_list expansion process (defaults to `production`)
32
+
33
+ ```bash
34
+ -e ENV_NAME
35
+ --environment ENV_NAME
36
+ ```
37
+
38
+ #### Data Source
39
+ The `datasource` option allows you to specify whether to use the Chef Server (`server`) or local disk (`disk`) to load roles and recipes for run_list expansion
40
+
41
+ ```bash
42
+ -d DATA_SOURCE
43
+ --data-source DATA_SOURCE
44
+ ```
45
+
46
+ #### Context Lines
47
+ The `context_lines` option allows you to specify the number of lines of context to be shown around each item in the diff output (defaults to 10000)
48
+
49
+ ```bash
50
+ -U CONTEXT_LINES
51
+ --context-lines CONTEXT_LINES
52
+ ```
53
+
54
+ ### Usage Example
55
+
56
+ ```text
57
+ $ knife runlist compare 'role[Base]' 'role[NewBase]' -U 3
58
+ run_list role[Base] expands to the following recipes:
59
+ ["foo", "bar::baz"]
60
+
61
+ run_list role[NewBase] expands to the following recipes:
62
+ ["foo"]
63
+
64
+ The following is the diff of these run_lists:
65
+ foo
66
+ -bar::baz
67
+ ```
@@ -0,0 +1,122 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :validate
47
+
48
+ desc "Open an irb session preloaded with this library"
49
+ task :console do
50
+ sh "irb -rubygems -r ./lib/#{name}.rb"
51
+ end
52
+
53
+ #############################################################################
54
+ #
55
+ # Custom tasks (add your own tasks here)
56
+ #
57
+ #############################################################################
58
+
59
+
60
+
61
+ #############################################################################
62
+ #
63
+ # Packaging tasks
64
+ #
65
+ #############################################################################
66
+
67
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
68
+ task :release => :build do
69
+ unless `git branch` =~ /^\* master$/
70
+ puts "You must be on the master branch to release!"
71
+ exit!
72
+ end
73
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
74
+ sh "git tag v#{version}"
75
+ sh "git push origin master"
76
+ sh "git push origin v#{version}"
77
+ sh "gem push pkg/#{name}-#{version}.gem"
78
+ end
79
+
80
+ desc "Build #{gem_file} into the pkg directory"
81
+ task :build => :gemspec do
82
+ sh "mkdir -p pkg"
83
+ sh "gem build #{gemspec_file}"
84
+ sh "mv #{gem_file} pkg"
85
+ end
86
+
87
+ desc "Generate #{gemspec_file}"
88
+ task :gemspec => :validate do
89
+ # read spec file and split out manifest section
90
+ spec = File.read(gemspec_file)
91
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
92
+
93
+ # replace name version and date
94
+ replace_header(head, :name)
95
+ replace_header(head, :version)
96
+ replace_header(head, :date)
97
+ #comment this out if your rubyforge_project has a different name
98
+ replace_header(head, :rubyforge_project)
99
+
100
+ # determine file list from git ls-files
101
+ files = `git ls-files`.
102
+ split("\n").
103
+ sort.
104
+ reject { |file| file =~ /^\./ }.
105
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
106
+ map { |file| " #{file}" }.
107
+ join("\n")
108
+
109
+ # piece file back together and write
110
+ manifest = " s.files = %w[\n#{files}\n ]\n"
111
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
112
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
113
+ puts "Updated #{gemspec_file}"
114
+ end
115
+
116
+ desc "Validate #{gemspec_file}"
117
+ task :validate do
118
+ unless Dir['VERSION*'].empty?
119
+ puts "A `VERSION` file at root level violates Gem best practices."
120
+ exit!
121
+ end
122
+ end
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'knife-runlist-compare'
5
+ gem.version = '0.0.1'
6
+ gem.authors = ["Jon Cowie"]
7
+ gem.email = 'jonlives@gmail.com'
8
+ gem.homepage = 'https://github.com/jonlives/knife-runlist-compare'
9
+ gem.licenses = ['MIT']
10
+ gem.summary = "A knife plugin to compare two runlists, expand them to lists of recipes and display the diff"
11
+ gem.description = "A knife plugin to compare two runlists, expand them to lists of recipes and display the diff"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "knife-runlist-compare"
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_runtime_dependency 'chef', '>= 11.0.0'
20
+ gem.add_runtime_dependency 'diffy', '~> 3.0.5'
21
+ end
@@ -0,0 +1,66 @@
1
+ ## Based on https://gist.github.com/961827 by nstielau
2
+
3
+
4
+ require 'chef/knife'
5
+
6
+ module KnifeRunlistCompare
7
+ class RunlistCompare < Chef::Knife
8
+
9
+ deps do
10
+ require 'chef/run_list'
11
+ require 'diffy'
12
+ end
13
+
14
+ banner "knife runlist compare RUN_LIST1 RUN_LIST2 (options)"
15
+
16
+ option :environment,
17
+ :short => "-e ENVIRONMENT",
18
+ :long => "--environment ENVIRONMENT",
19
+ :description => "The environemnt to use for run_list expansion",
20
+ :default => "production"
21
+
22
+ option :data_source,
23
+ :short => "-d DATA_SOURCE",
24
+ :long => "--data-source DATA_SOURCE",
25
+ :description => "The data source to use (server/disk)",
26
+ :default => "server"
27
+
28
+ option :context_lines,
29
+ :short => "-U CONTEXT_LINES",
30
+ :long => "--context-lines CONTEXT_LINES",
31
+ :description => "The number of lines of context to give around a diff (default 10000)",
32
+ :default => 10000
33
+
34
+ def run
35
+
36
+ if @name_args.length != 2
37
+ ui.error "You must specify two run_lists to compare"
38
+ ui.msg opt_parser
39
+ exit 1
40
+ end
41
+
42
+
43
+ runlist1 = Chef::RunList.new
44
+ @name_args.first.split(",").each{|r|runlist1.add(r)}
45
+
46
+ runlist2 = Chef::RunList.new
47
+ @name_args.last.split(",").each{|r|runlist2.add(r)}
48
+
49
+ exp_runlist_1 = runlist1.expand(config[:environment],config[:data_source]).recipes
50
+ exp_runlist_2 = runlist2.expand(config[:environment],config[:data_source]).recipes
51
+
52
+ ui.info "run_list #{@name_args.first} expands to the following recipes:"
53
+ ui.info exp_runlist_1.inspect
54
+
55
+ ui.info "\nrun_list #{@name_args.last} expands to the following recipes:"
56
+ ui.info exp_runlist_2.inspect
57
+
58
+ ui.info "\nThe following is the diff of the expanded recipe lists:"
59
+ Diffy::Diff.default_format = :color
60
+
61
+ runlist_diff = Diffy::Diff.new(exp_runlist_1.join("\n"), exp_runlist_2.join("\n"),:diff=>"-U #{config[:context_lines]}")
62
+ puts runlist_diff
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module KnifeRunlistCompare
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-runlist-compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Cowie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chef
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 11.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 11.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: diffy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.5
41
+ description: A knife plugin to compare two runlists, expand them to lists of recipes
42
+ and display the diff
43
+ email: jonlives@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - CHANGELOG.md
50
+ - LICENSE.md
51
+ - README.md
52
+ - Rakefile
53
+ - knife-runlist-compare.gemspec
54
+ - lib/chef/knife/runlist-compare.rb
55
+ - lib/knife-runlist-compare.rb
56
+ homepage: https://github.com/jonlives/knife-runlist-compare
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A knife plugin to compare two runlists, expand them to lists of recipes and
80
+ display the diff
81
+ test_files: []
82
+ has_rdoc: