forked from chef-boneyard/cookbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cookbook for managing DNS resource records with dynect
- Loading branch information
jtimberman
committed
Jun 11, 2010
1 parent
c8f157e
commit 653f9eb
Showing
8 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
DESCRIPTION | ||
=========== | ||
|
||
Automatically configures system DNS using Dyn's API. | ||
|
||
REQUIREMENTS | ||
============ | ||
|
||
Chef 0.8+. | ||
|
||
A Dynect account. | ||
|
||
The `dynect_rest` gem. The `dynect::default` recipe installs this gem from gemcutter. | ||
|
||
Works on any platform Chef runs on that can install gems from Rubygems.org. | ||
|
||
ATTRIBUTES | ||
========== | ||
|
||
The following attributes need to be set either in a role or on a node directly, they are not set at the cookbook level: | ||
|
||
* dynect.customer - Customer ID | ||
* dynect.username - Username | ||
* dynect.password - Password | ||
* dynect.zone - Zone | ||
* dynect.domain - Domain | ||
|
||
Example JSON: | ||
|
||
{ | ||
"dynect": { | ||
"customer": "CUSTOMER", | ||
"username": "USERNAME", | ||
"password": "PASSWORD", | ||
"zone": "ZONE", | ||
"domain": "DOMAIN" | ||
} | ||
} | ||
|
||
EC2 specific attributes: | ||
|
||
* dynect.ec2.type - type of system, web, db, etc. Default is 'ec2'. | ||
* dynect.ec2.env - logical application environment the system is in. Default is 'prod'. | ||
|
||
RESOURCES | ||
========= | ||
|
||
rr | ||
-- | ||
|
||
DNS Resource Record. | ||
|
||
Actions: | ||
|
||
Applies to the DNS record being managed. | ||
|
||
* `:create` | ||
* `:replace` | ||
* `:update` | ||
* `:delete` | ||
|
||
Attribute Parameters: | ||
|
||
* `record_type` - DNS record type (CNAME, A, etc) | ||
* `rdata` - record data, see the Dyn API documentation. | ||
* `ttl` - time to live in seconds | ||
* `fqdn` - fully qualified domain name | ||
* `username` - dyn username | ||
* `password` - dyn password | ||
* `customer` - dyn customer id | ||
* `zone` - DNS zone | ||
|
||
None of the parameters have default values. | ||
|
||
Example: | ||
|
||
dynect_rr "webprod" do | ||
record_type "A" | ||
rdata({"address" => "10.1.1.10"}) | ||
fqdn "webprod.#{node.dynect.domain}" | ||
customer node[:dynect][:customer] | ||
username node[:dynect][:username] | ||
password node[:dynect][:password] | ||
zone node[:dynect][:zone] | ||
end | ||
|
||
RECIPES | ||
======= | ||
|
||
This cookbook provides the following recipes. | ||
|
||
default | ||
------- | ||
|
||
The default recipe installs Adam Jacob's `dynect_rest` gem during the Chef run's compile time to ensure it is available in the same run as utilizing the `dynect_rr` resource/provider. | ||
|
||
ec2 | ||
--- | ||
|
||
**Only use this recipe on Amazon AWS EC2 hosts!** | ||
|
||
The `dynect::ec2` recipe provides an example of working with the Dyn API with EC2 instances. It creates CNAME records based on the EC2 instance ID (`node.ec2.instance_id`), and a constructed hostname from the dynect.ec2 attributes. | ||
|
||
The recipe also edits resolv.conf to search compute-1.internal and the dynect.domain and use dynect.domain as the default domain, and it will set the nodes hostname per the DNS settings. | ||
|
||
a_record | ||
-------- | ||
|
||
The `dynect::a_record` recipe will create an `A` record for the node using the detected hostname and IP address from `ohai`. | ||
|
||
FURTHER READING | ||
=============== | ||
|
||
Information on the Dynect API: | ||
|
||
* [PDF](http://cdn.dyndns.com/pdf/Dynect-API.pdf) | ||
|
||
Dynect REST Ruby Library: | ||
|
||
* [Gem](http://rubygems.org/gems/dynect_rest) | ||
* [Code](http://github.com/adamhjk/dynect_rest) | ||
|
||
LICENSE AND AUTHOR | ||
================== | ||
|
||
- Author: Adam Jacob (<[email protected]>) | ||
- Copyright: 2010, Opscode, Inc. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# Cookbook Name:: dynect | ||
# Attribute:: default | ||
# | ||
# Copyright:: 2010, Opscode, Inc <[email protected]> | ||
# | ||
# 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. | ||
# | ||
# | ||
|
||
# Set these attributes in your role or node. | ||
# set[:dynect][:customer] = "" | ||
# set[:dynect][:username] = "" | ||
# set[:dynect][:password] = "" | ||
# set[:dynect][:zone] = "" | ||
# set[:dynect][:domain] = "" | ||
# | ||
# set[:dynect][:ec2][:type] = "ec2" | ||
# set[:dynect][:ec2][:env] = "prod" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"maintainer_email": "[email protected]", | ||
"attributes": { | ||
}, | ||
"conflicting": { | ||
}, | ||
"dependencies": { | ||
}, | ||
"providing": { | ||
}, | ||
"recipes": { | ||
}, | ||
"replacing": { | ||
}, | ||
"platforms": { | ||
}, | ||
"license": "Apache 2.0", | ||
"version": "0.2.0", | ||
"groupings": { | ||
}, | ||
"long_description": "DESCRIPTION\n===========\n\nAutomatically configures system DNS using Dyn's API.\n\nREQUIREMENTS\n============\n\nChef 0.8+.\n\nA Dynect account.\n\nThe `dynect_rest` gem. The `dynect::default` recipe installs this gem from gemcutter.\n\nWorks on any platform Chef runs on that can install gems from Rubygems.org.\n\nATTRIBUTES\n==========\n\nThe following attributes need to be set either in a role or on a node directly, they are not set at the cookbook level:\n\n* dynect.customer - Customer ID\n* dynect.username - Username\n* dynect.password - Password\n* dynect.zone - Zone\n* dynect.domain - Domain\n\nExample JSON:\n\n {\n \"dynect\": {\n \"customer\": \"CUSTOMER\",\n \"username\": \"USERNAME\",\n \"password\": \"PASSWORD\",\n \"zone\": \"ZONE\",\n \"domain\": \"DOMAIN\"\n }\n }\n\nEC2 specific attributes:\n\n* dynect.ec2.type - type of system, web, db, etc. Default is 'ec2'.\n* dynect.ec2.env - logical application environment the system is in. Default is 'prod'.\n\nRESOURCES\n=========\n\nrr\n--\n\nDNS Resource Record.\n\nActions:\n\nApplies to the DNS record being managed.\n\n* `:create`\n* `:replace`\n* `:update`\n* `:delete`\n\nAttribute Parameters:\n\n* `record_type` - DNS record type (CNAME, A, etc)\n* `rdata` - record data, see the Dyn API documentation.\n* `ttl` - time to live in seconds\n* `fqdn` - fully qualified domain name\n* `username` - dyn username\n* `password` - dyn password\n* `customer` - dyn customer id\n* `zone` - DNS zone\n\nNone of the parameters have default values.\n\nExample:\n\n dynect_rr \"webprod\" do\n record_type \"A\"\n rdata({\"address\" => \"10.1.1.10\"})\n fqdn \"webprod.#{node.dynect.domain}\"\n customer node[:dynect][:customer]\n username node[:dynect][:username]\n password node[:dynect][:password]\n zone node[:dynect][:zone]\n end\n\nRECIPES\n=======\n\nThis cookbook provides the following recipes.\n\ndefault\n-------\n\nThe default recipe installs Adam Jacob's `dynect_rest` gem during the Chef run's compile time to ensure it is available in the same run as utilizing the `dynect_rr` resource/provider.\n\nec2\n---\n\n**Only use this recipe on Amazon AWS EC2 hosts!**\n\nThe `dynect::ec2` recipe provides an example of working with the Dyn API with EC2 instances. It creates CNAME records based on the EC2 instance ID (`node.ec2.instance_id`), and a constructed hostname from the dynect.ec2 attributes.\n\nThe recipe also edits resolv.conf to search compute-1.internal and the dynect.domain and use dynect.domain as the default domain, and it will set the nodes hostname per the DNS settings.\n\na_record\n--------\n\nThe `dynect::a_record` recipe will create an `A` record for the node using the detected hostname and IP address from `ohai`.\n\nFURTHER READING\n===============\n\nInformation on the Dynect API:\n\n* [PDF](http://cdn.dyndns.com/pdf/Dynect-API.pdf)\n\nDynect REST Ruby Library:\n\n* [Gem](http://rubygems.org/gems/dynect_rest)\n* [Code](http://github.com/adamhjk/dynect_rest)\n\nLICENSE AND AUTHOR\n==================\n\n- Author: Adam Jacob (<[email protected]>)\n- Copyright: 2010, Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", | ||
"recommendations": { | ||
}, | ||
"name": "dynect", | ||
"maintainer": "Opscode, Inc.", | ||
"description": "Installs/Configures dynect", | ||
"suggestions": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
maintainer "Opscode, Inc." | ||
maintainer_email "[email protected]" | ||
license "Apache 2.0" | ||
description "Installs/Configures dynect" | ||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) | ||
version "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# | ||
# Cookbook Name:: dynect | ||
# Provider:: rr | ||
# | ||
# Copyright:: 2010, Opscode, Inc <[email protected]> | ||
# | ||
# 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. | ||
# | ||
|
||
def load_current_resource | ||
require 'dynect_rest' | ||
|
||
@dyn = DynectRest.new(@new_resource.customer, @new_resource.username, @new_resource.password, @new_resource.zone) | ||
|
||
@current_resource = Chef::Resource::DynectRr.new(@new_resource.name) | ||
@current_resource.record_type(@new_resource.record_type) | ||
@current_resource.customer(@new_resource.customer) | ||
@current_resource.username(@new_resource.username) | ||
@current_resource.password(@new_resource.password) | ||
@current_resource.zone(@new_resource.zone) | ||
|
||
@rr = nil | ||
|
||
begin | ||
@rr = DynectRest::Resource.new(@dyn, @new_resource.record_type, @new_resource.zone).get(@new_resource.fqdn) | ||
@current_resource.fqdn(@rr.fqdn) | ||
@current_resource.ttl(@rr.ttl) | ||
@current_resource.zone(@rr.zone) | ||
@current_resource.rdata(@rr.rdata) | ||
rescue DynectRest::Exceptions::RequestFailed => e | ||
Chef::Log.debug("Cannot find resource #{@new_resource} at Dynect") | ||
end | ||
end | ||
|
||
def action_create | ||
unless @rr | ||
rr = DynectRest::Resource.new(@dyn, @new_resource.record_type, @new_resource.zone) | ||
rr.fqdn(@new_resource.fqdn) | ||
rr.ttl(@new_resource.ttl) if @new_resource.ttl | ||
rr.rdata = @new_resource.rdata | ||
rr.save | ||
@dyn.publish | ||
Chef::Log.info("Added #{@new_resource} to dynect") | ||
@updated = true | ||
end | ||
end | ||
|
||
def action_update | ||
if @rr | ||
changed = false | ||
if (@new_resource.ttl && @rr.ttl != @new_resource.ttl) | ||
@rr.ttl(@new_resource.ttl) | ||
Chef::Log.info("Changing #{@new_resource} ttl from #{@rr.ttl} to #{@new_resource.ttl}") | ||
changed = true | ||
end | ||
if @rr.rdata != @new_resource.rdata | ||
Chef::Log.info("Changing #{@new_resource} rdata from #{@rr.rdata.inspect} to #{@new_resource.rdata.inspect}") | ||
@rr.rdata = @new_resource.rdata | ||
changed = true | ||
end | ||
if changed | ||
@rr.save | ||
@dyn.publish | ||
Chef::Log.info("Updated #{@new_resource} at dynect") | ||
@updated = true | ||
end | ||
else | ||
action_create | ||
end | ||
end | ||
|
||
def action_replace | ||
rr = DynectRest::Resource.new(@dyn, @new_resource.record_type, @new_resource.zone) | ||
rr.fqdn(@new_resource.fqdn) | ||
rr.ttl(@new_resource.ttl) if @new_resource.ttl | ||
rr.rdata = @new_resource.rdata | ||
rr.save(true) | ||
@dyn.publish | ||
Chef::Log.info("Replaced #{@new_resource} at dynect") | ||
@updated = true | ||
end | ||
|
||
def action_delete | ||
if @rr | ||
@rr.delete | ||
Chef::Log.info("Deleted #{@new_resource} from dynect") | ||
@updated = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# Cookbook Name:: dynect | ||
# Recipe:: a_record | ||
# | ||
# Copyright:: 2010, Opscode, Inc <[email protected]> | ||
# | ||
# 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. | ||
# | ||
|
||
include_recipe 'dynect' | ||
|
||
dynect_rr node[:hostname] do | ||
record_type "A" | ||
rdata({ "address" => node[:ipaddress] }) | ||
fqdn "#{node[:hostname]}.#{node[:dynect][:domain]}" | ||
customer node[:dynect][:customer] | ||
username node[:dynect][:username] | ||
password node[:dynect][:password] | ||
zone node[:dynect][:zone] | ||
action :update | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# | ||
# Cookbook Name:: dynect | ||
# Recipe:: default | ||
# | ||
# Copyright:: 2010, Opscode, Inc <[email protected]> | ||
# | ||
# 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. | ||
# | ||
|
||
# Install dynect in advance | ||
r = gem_package "dynect_rest" do | ||
action :nothing | ||
end | ||
r.run_action(:upgrade) | ||
Gem.clear_paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# Cookbook Name:: dynect | ||
# Resource:: rr | ||
# | ||
# Author:: Adam Jacob <[email protected]> | ||
# Copyright:: 2010, Opscode, Inc <[email protected]> | ||
# | ||
# 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. | ||
# | ||
|
||
actions :delete, :create, :update, :replace | ||
|
||
attribute :record_type, :kind_of => String | ||
attribute :rdata, :kind_of => Hash | ||
attribute :ttl, :kind_of => Integer | ||
attribute :fqdn, :kind_of => String | ||
attribute :username, :kind_of => String | ||
attribute :password, :kind_of => String | ||
attribute :customer, :kind_of => String | ||
attribute :zone, :kind_of => String |