knife-ghost 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@ghost --create
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-ghost.gemspec
4
+ gemspec
5
+
6
+ gem 'ghost', :git => 'https://github.com/bjeanes/ghost.git'
7
+
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Anthony Goddard <anthony@anthonygoddard.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ knife-ghost
2
+ ========
3
+ A knife plugin for populating your local /etc/hosts file with hostname and IP data from chef.
4
+ Useful if DNS is unavailable.
5
+
6
+
7
+ Installing knife-ghost
8
+ -------------------
9
+
10
+ #### Gem install
11
+
12
+ add `knife-ghost` to your Gemfile, or simply
13
+
14
+ gem install knife-ghost
15
+
16
+ Usage
17
+ ---------------
18
+
19
+ sudo knife ghost hosts
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-ghost/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "knife-ghost"
7
+ s.version = Knife::Ghost::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["README.md", "LICENSE" ]
11
+ s.authors = ["Anthony Goddard"]
12
+ s.email = ["anthony@anthonygoddard.com"]
13
+ s.homepage = "https://github.com/agoddard/knife-ghost"
14
+ s.summary = %q{Chef Knife plugin to automatically populate local hosts file}
15
+ s.description = %q{Automatically populates /etc/hosts with node domain names and IP addresses from Chef, requires sudo privileges to edit /etc/hosts}
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "ghost", ">= 1.0.0.pre.2"
23
+
24
+ end
@@ -0,0 +1,39 @@
1
+ class Chef
2
+ class Knife
3
+ class GhostHosts < Knife
4
+ deps do
5
+ require 'chef/knife/bootstrap'
6
+ require 'ghost'
7
+ Chef::Knife::Bootstrap.load_deps
8
+ end
9
+
10
+ banner "sudo knife ghost hosts"
11
+
12
+ def run
13
+ all_nodes = []
14
+ q = Chef::Search::Query.new
15
+ query = @name_args[0] || "*:*"
16
+ q.search(:node, query) do |node|
17
+ all_nodes << node
18
+ end
19
+ all_nodes.each do |node|
20
+ if node.has_key?("ec2")
21
+ fqdn = node['ec2']['public_hostname']
22
+ ipaddress = node['ec2']['public_ipv4']
23
+ else
24
+ fqdn = node['fqdn']
25
+ ipaddress = node['ipaddress']
26
+ end
27
+
28
+ host = Ghost::Host.new(*[fqdn, ipaddress].compact)
29
+ begin
30
+ Ghost.store.add(host)
31
+ ui.msg "[Adding] #{host.name} -> #{host.ip}"
32
+ rescue Ghost::Host::NotResolvable
33
+ ui.fatal "Unable to resolve IP address for target host #{ip.inspect}."
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module Ghost
3
+ VERSION = "0.1.0"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-ghost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony Goddard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ghost
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0.pre.2
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: 1.0.0.pre.2
30
+ description: Automatically populates /etc/hosts with node domain names and IP addresses
31
+ from Chef, requires sudo privileges to edit /etc/hosts
32
+ email:
33
+ - anthony@anthonygoddard.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - README.md
38
+ - LICENSE
39
+ files:
40
+ - .rvmrc
41
+ - Gemfile
42
+ - LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - knife-ghost.gemspec
46
+ - lib/chef/knife/ghost_hosts.rb
47
+ - lib/knife-ghost/version.rb
48
+ homepage: https://github.com/agoddard/knife-ghost
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Chef Knife plugin to automatically populate local hosts file
72
+ test_files: []