Skip to content

Commit

Permalink
[RACKSPACE] Added a ghetto-dns setup for Rackspace Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
hosh committed May 3, 2010
1 parent 937af82 commit 87c9b36
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
19 changes: 19 additions & 0 deletions rackspace/README.rdoc
@@ -1,5 +1,24 @@
= DESCRIPTION:

Rackspace Cloud Server recipes

== hosts
This recipe sets up Ghetto DNS. It queries the server index and builds up a list of nodes that
have a 172.* address on eth1. From there, it generates a /etc/hosts file. The reason to do this
is to be able to route all requests through the private IP addresses. This recipe was written
to assume your FQDN points to the private IP addresses, and you are using DNS aliases to refer
to the public IP address.

Additionally, you can specify site-wide IP addresses using the databag "cloud-hosts". For example,
to specify a global "chef-server":

databag: "cloud-hosts"
id: "chef-server"
ip: 172.172.172.172

The name for the data-bag is subject to change in future releases of this cookbook. Future
versions may also include aliases

= REQUIREMENTS:

= ATTRIBUTES:
Expand Down
6 changes: 3 additions & 3 deletions rackspace/metadata.rb
@@ -1,6 +1,6 @@
maintainer "Example Com"
maintainer_email "ops@example.com"
maintainer "Ho-Sheng Hsiao"
maintainer_email "hosh@sparkfly.com"
license "Apache 2.0"
description "Installs/Configures rackspace"
description "Installs/Configures Rackspace Cloud-specific stuff"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.1"
54 changes: 54 additions & 0 deletions rackspace/recipes/hosts.rb
@@ -0,0 +1,54 @@
#
# Cookbook Name:: rackspace
# Recipe:: hosts
#
# Copyright 2010, Sparkfly
# Modified from: http://blog.bitfluent.com/post/196658820/using-chef-server-indexes-as-a-simple-dns
# Copyright 2009, Bitfluent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

global_hosts = {}
hosts = {}

data_bag('cloud-hosts').each do |host|
n = data_bag_item('cloud-hosts', host)
global_hosts[n['ip']] = host
end

# NOTE: According to the 0.8 source code, there is a default row limit of 20. If the interface (via Couchdb) is what
# I think it is, then this will turn into a sleeping defect. We should be using djdns or PowerDNS by that point

# Structure:
# network
# interfaces
# eth1
# addresses
# locallink
# ipv4 addr
# addr
# netmask
# ...
# ipv6 addr
search(:node, "network_interfaces_eth1_addresses:172.*") do |n|
addresses = n['network']['interfaces']['eth1']['addresses'].map { |addr| addr[0] }
ip = addresses.select { |addr| addr.to_s =~ /172.*/ }.first
hosts[ip] = n
end

template "/etc/hosts" do
source "hosts.erb"
mode 0644
variables(:global_hosts => global_hosts, :hosts => hosts)
end
15 changes: 15 additions & 0 deletions rackspace/templates/default/hosts.erb
@@ -0,0 +1,15 @@
# Ghetto DNS
# Auto-generated by chef for <%= @node[:fqdn] %>

127.0.0.1 localhost
::1 localhost

# Site-wide hosts
<% @global_hosts.keys.sort.each do |ip| %>
<%= ip %> <%= @global_hosts[ip] %>
<% end %>

# Private IP nodes
<% @hosts.keys.sort.each do |ip| %>
<%= ip %> <%= @hosts[ip]["fqdn"] %> <%= (@hosts[ip]["dns_aliases"] || []).sort.join(" ") %>
<% end %>

0 comments on commit 87c9b36

Please sign in to comment.