├── lib ├── knife-env-diff │ └── version.rb └── chef │ └── knife │ └── env-diff.rb ├── README.md └── knife-env-diff.gemspec /lib/knife-env-diff/version.rb: -------------------------------------------------------------------------------- 1 | module Knife 2 | module EnvironmentDiff 3 | VERSION = "0.0.4" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # knife-env-diff 2 | 3 | A plugin for Chef::Knife which will diff the cookbook versions of two or more environments. 4 | 5 | ## Usage 6 | 7 | Supply two or more environments to get a diff of their cookbook versions 8 | 9 | ``` 10 | % knife environment diff development production 11 | 12 | diffing environment development against production 13 | 14 | cookbook: hadoop 15 | development version: = 0.1.0 16 | production version: = 0.1.8 17 | 18 | cookbook: mysql 19 | development version: = 0.2.4 20 | production version: = 0.2.5 21 | ``` 22 | 23 | ## Installation 24 | 25 | #### Script install 26 | 27 | Copy the knife-env-diff script from lib/chef/knife/env-diff.rb to your ~/.chef/plugins/knife directory. 28 | 29 | #### Gem install 30 | 31 | knife-env-diff is available on rubygems.org - if you have that source in your gemrc, you can simply use: 32 | 33 | gem install knife-env-diff 34 | -------------------------------------------------------------------------------- /knife-env-diff.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "knife-env-diff/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'knife-env-diff' 7 | s.version = Knife::EnvironmentDiff::VERSION 8 | s.date = '2012-01-02' 9 | s.summary = "A plugin for Chef::Knife which displays the roles that are included recursively within a role and optionally displays all the roles that include it." 10 | s.description = s.summary 11 | s.authors = ["John Goulah"] 12 | s.email = ["jgoulah@gmail.com"] 13 | s.homepage = "https://github.com/jgoulah/knife-env-diff" 14 | s.files = `git ls-files`.split("\n") 15 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 16 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 17 | s.require_paths = ["lib"] 18 | end 19 | -------------------------------------------------------------------------------- /lib/chef/knife/env-diff.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: John Goulah () 3 | # Copyright:: Copyright (c) 2011 John Goulah 4 | # 5 | ## Licensed under the Apache License, Version 2.0 (the "License"); 6 | ## you may not use this file except in compliance with the License. 7 | ## You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## 17 | # 18 | 19 | module GoulahKnifePlugins 20 | class EnvironmentDiff < Chef::Knife 21 | 22 | banner "knife environment diff [ENVIRONMENTS...]" 23 | 24 | def run 25 | if name_args.size < 2 26 | ui.error("You need to supply at least two environments") 27 | show_usage 28 | exit 1 29 | end 30 | 31 | firstenv = name_args.first 32 | otherenvs = name_args.slice(1, name_args.length - 1) 33 | 34 | from_env = {} 35 | from_env[firstenv] = get_env_cookbooks(firstenv) 36 | 37 | to_env = {} 38 | otherenvs.each do |env_name| 39 | to_env[env_name] = get_env_cookbooks(env_name) 40 | end 41 | 42 | ui.msg "diffing environment " + firstenv + " against " + otherenvs.join(', ') + "\n\n" 43 | 44 | from_env.each_value do |from_cookbooks| 45 | from_cookbooks.each do |from_cookbook, from_data| 46 | diff_versions = {} 47 | 48 | from_version = get_cookbook_version(from_data) 49 | 50 | to_env.each do |env, to_cookbooks| 51 | to_version = get_cookbook_version(to_cookbooks[from_cookbook]) 52 | 53 | if from_version != to_version || from_version.nil? 54 | diff_versions[env] = to_version 55 | end 56 | end 57 | 58 | unless diff_versions.empty? 59 | ui.msg "cookbook: "+ from_cookbook 60 | ui.msg " #{firstenv} version: #{from_version}" 61 | diff_versions.each do |env, version| 62 | ui.msg " #{env} version: "+ version 63 | end 64 | ui.msg "\n" 65 | end 66 | end 67 | end 68 | end 69 | 70 | def get_env_cookbooks(env) 71 | rest.get_rest("environments/#{env}/cookbooks") 72 | end 73 | 74 | def get_cookbook_version(data) 75 | if data['versions'].empty? 76 | 'none' 77 | else 78 | data['versions'].first['version'] 79 | end 80 | end 81 | end 82 | end 83 | --------------------------------------------------------------------------------