knifer_sutherland 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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTFiMzlhODEwOTU4MjEyNGJjMzg5NjZjZmE4MzhjMzcyMjI0YmY4YQ==
5
+ data.tar.gz: !binary |-
6
+ MTVhYzk2N2JkZTkxMTRjYzZjNzlhNzhkOWMyMGIxYzVhZDgwYTRlYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDIzMDBkOTk4YTJkZTRkMmE1OWU5YWRhODc0ZTk0MTkzYzU0YTcwN2IxMzE1
10
+ Mzg1ZTJiNjkzMGMzZjYyMDc3MjZjMWFhMDYxMjJhOTMwMTUwM2JmZjM3YTBl
11
+ NjQ0NTZmZmNkYWM3N2YwMmJjNDgyZTkwY2M5ODYzZGZkMzhhMmQ=
12
+ data.tar.gz: !binary |-
13
+ MDY5NjZiNDY3Nzc0OWYyY2I4ZGJhMTY0NWJkMzdiMjc1Yzc4NjYwODVkODY1
14
+ OTkzYzEzNGI3ODViMGMwMDBiYjViZGIwMDIzY2ZiMGVkYzMyN2ZlZTA5YTcx
15
+ NjBlODk3NTE2ODc1Y2FhMDgzNjhlOTM5Zjk4YWZjMzg4Y2IyZjY=
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ ._*
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ pkg
7
+ pkg/*
8
+ rdoc
9
+ spec/reports
10
+ tmp
11
+ .DS_Store
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'chef'
4
+ gem 'ghost', '1.0.0.pre.2' #this has been out for awhile, works good with the lib'
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Will Wilimek
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ Knifer Sutherland
2
+ ========
3
+
4
+
5
+ This is a little knife plugin that should help you when connecting to your chef
6
+ nodes. If you constantly have to do knife status or some other way to get the
7
+ addresses of your servers. Then this gem is just for you! BUY NOW! for only $9.99
8
+ or wait and GET IT FOR FREEEE!
9
+
10
+ Wait why does the name remind me of Keither Sutherland? Well it's simple, every
11
+ time I run knife commands I think of the show 24 which starred Keither
12
+ Sutherland and I think about him kicking terroists asses! It's a weird memory map.
13
+
14
+
15
+ ###Installing It
16
+
17
+ It's really easy and works with ruby-2.0 and ruby-1.9.3
18
+
19
+ ```
20
+ $ gem install knife_sutherland
21
+ ```
22
+
23
+ ###Using It
24
+
25
+ Navigate to your chef server directory, where you keep all your files for chef
26
+ and execute it like this. Make sure to use sudo so it can have permission to
27
+ write to the /etc/hosts file.
28
+
29
+ ```
30
+ $ sudo knife hosts_file
31
+ ```
32
+
33
+ You should see some ip addresses and hosts flash by and when you go look at your
34
+ hosts file it should be populated with the nodes of your chef servers.
35
+
36
+ ```
37
+ Adding prodweb 12.21.0.1
38
+ Adding prodweb2 12.21.0.2
39
+ Adding stagweb 12.21.0.3
40
+ Adding stagweb2 12.21.0.4
41
+ Adding qaweb 12.21.0.5
42
+ Adding qaweb2 12.21.0.6
43
+ ```
44
+
45
+ ```
46
+ # /etc/hosts
47
+ 127.0.0.1 localhost
48
+ # ghost start
49
+ 12.21.0.1 prodweb
50
+ 12.21.0.2 prodweb2
51
+ 12.21.0.3 stagweb
52
+ 12.21.0.4 stagweb2
53
+ 12.21.0.5 qaweb
54
+ 12.21.0.6 qaweb2
55
+ # ghost end
56
+
57
+ ```
58
+
59
+ Your existing hosts file should still be ok and any new hosts that are added are
60
+ going to be between the #ghost start and #ghost end so.
61
+
62
+
63
+
64
+ Contributing
65
+ ----------
66
+
67
+ 1. Fork
68
+ 2. Create a topic branch - git checkout -b my_branch
69
+ 3. Push to your branch - git push origin my_branch
70
+ 4. Create a Pull Request from your branch
71
+ 5. That's it!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :spec
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "knifer_sutherland/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "knifer_sutherland"
8
+ spec.version = KniferSutherland::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["willywos"]
11
+ spec.email = ["wwilimek@gmail.com"]
12
+ spec.homepage = "https://github.com/willywos/knifer_sutherland"
13
+ spec.summary = %q{A really great tool to write your chef nodes to your hosts file.
14
+ If you ever get sick of writing knife status to see the ip address
15
+ of the node you want to connect to then this gem is made just for you :)}
16
+ spec.description = %q{Knife plugin that writes nodes to your local hosts file.}
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ spec.license = "MIT"
22
+ spec.extra_rdoc_files = ["README.md", "LICENSE.md" ]
23
+
24
+ spec.add_dependency "ghost", ">= 1.0.0.pre.2"
25
+ spec.add_dependency "chef"
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'knifer_sutherland/host'
2
+
3
+ class Chef
4
+ class Knife
5
+ class HostsFile < Knife
6
+ deps do
7
+ require 'chef/knife/bootstrap'
8
+ Chef::Knife::Bootstrap.load_deps
9
+ end
10
+
11
+ banner "knife hosts_file (options)"
12
+
13
+ def run
14
+ nodes = query_nodes(@name_args[0] || "*:*")
15
+ KniferSutherland::Host.new.write_nodes_to_host_file(nodes)
16
+ end
17
+
18
+ def query_nodes(search)
19
+ nodes = Hash.new
20
+ Chef::Search::Query.new.search(:node, search) do |node|
21
+ nodes[ip_address(node)] = node.name
22
+ end
23
+ nodes
24
+ end
25
+
26
+ def ip_address(node)
27
+ node.has_key?("ec2") ? node['ec2']['public_ipv4'] : node['ipaddress']
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'ghost'
2
+
3
+ module KniferSutherland
4
+ class Host
5
+ def write_nodes_to_host_file(nodes)
6
+ nodes.each do |node|
7
+ write_node(node)
8
+ end
9
+ end
10
+
11
+ def write_node(node)
12
+ begin
13
+ host = Ghost::Host.new(*[node[1], node[0]].compact)
14
+ puts "Adding #{host.name} #{host.ip}"
15
+ Ghost.store.add(host)
16
+ rescue Ghost::Host::NotResolvable
17
+ puts "Not able to resolve for #{node[0]} #{node[1]}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module KniferSutherland
2
+ VERSION = "0.0.1"
3
+ MAJOR, MINOR, TINY = VERSION.split('.')
4
+ end
@@ -0,0 +1,8 @@
1
+ $: << File.dirname(__FILE__)
2
+
3
+ module KniferSutherland
4
+ end
5
+
6
+ require 'knifer_sutherland/version'
7
+ require 'knifer_sutherland/host'
8
+ require 'chef/knife/hosts_file'
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), "support", "*")].each { |f|
8
+ require(f)
9
+ }
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knifer_sutherland
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - willywos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ghost
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0.pre.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0.pre.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Knife plugin that writes nodes to your local hosts file.
42
+ email:
43
+ - wwilimek@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ - LICENSE.md
49
+ files:
50
+ - .gitignore
51
+ - .rspec
52
+ - Gemfile
53
+ - LICENSE.md
54
+ - README.md
55
+ - Rakefile
56
+ - knifer_sutherland.gemspec
57
+ - lib/chef/knife/hosts_file.rb
58
+ - lib/knifer_sutherland.rb
59
+ - lib/knifer_sutherland/host.rb
60
+ - lib/knifer_sutherland/version.rb
61
+ - spec/spec_helper.rb
62
+ homepage: https://github.com/willywos/knifer_sutherland
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A really great tool to write your chef nodes to your hosts file. If you ever
86
+ get sick of writing knife status to see the ip address of the node you want to connect
87
+ to then this gem is made just for you :)
88
+ test_files:
89
+ - spec/spec_helper.rb