Skip to content
This repository has been archived by the owner on Jul 11, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubygems/rubygems-chef
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4dd6ce540f8d
Choose a base ref
...
head repository: rubygems/rubygems-chef
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8d0063c2ce8f
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Dec 2, 2014

  1. Copy the full SHA
    2bd2357 View commit details
  2. Copy the full SHA
    8d0063c View commit details
Showing with 67 additions and 60 deletions.
  1. +2 −2 Berksfile.lock
  2. +1 −1 cookbooks/dnsimple/metadata.rb
  3. +62 −55 cookbooks/dnsimple/providers/record.rb
  4. +1 −1 cookbooks/rubygems-hosts/metadata.rb
  5. +1 −1 cookbooks/rubygems-hosts/templates/default/hosts.erb
4 changes: 2 additions & 2 deletions Berksfile.lock
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ GRAPH
postgresql (>= 1.0.0)
xfs (>= 0.0.0)
dmg (2.2.0)
dnsimple (0.5.5)
dnsimple (0.5.7)
duo-security (0.1.1)
build-essential (>= 0.0.0)
openssh (>= 0.0.0)
@@ -268,7 +268,7 @@ GRAPH
chef-vault (>= 0.0.0)
dnsimple (>= 0.0.0)
hostname (>= 0.0.0)
rubygems-hosts (0.0.8)
rubygems-hosts (0.0.10)
rubygems-logging (0.0.6)
chef-vault (>= 0.0.0)
rsyslog (>= 0.0.0)
2 changes: 1 addition & 1 deletion cookbooks/dnsimple/metadata.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

license 'Apache 2.0'

version '0.5.5'
version '0.5.7'

recipe 'dnsimple', 'Installs dnsimple-ruby gem to use w/ the dnsimple_record'

117 changes: 62 additions & 55 deletions cookbooks/dnsimple/providers/record.rb
Original file line number Diff line number Diff line change
@@ -17,69 +17,76 @@
#

action :create do
begin
require 'rubygems'
require 'dnsimple'
rescue LoadError
Chef::Log.error('Missing gem "dnsimple"')
end

domain = new_resource.domain
name = new_resource.name
content = new_resource.content
type = new_resource.type
ttl = new_resource.ttl
prio = new_resource.priority

if domain.nil?
parsed = name.match(/^(.*?)\.?([^\.]+\.[^\.]+)$/)
name = parsed[1]
domain = parsed[2]
end
if node['skip_dnsimple']
Chef::Log.info 'Skipping DNSimple because of node attribute!'
new_resource.updated_by_last_action(false)
else

prio = nil if prio == ''
begin
require 'rubygems'
require 'dnsimple'
rescue LoadError
Chef::Log.error('Missing gem "dnsimple"')
end

if new_resource.domain_api_token.nil?
::DNSimple::Client.username = new_resource.username || node['dnsimple']['username']
::DNSimple::Client.password = new_resource.password || node['dnsimple']['password']
else
::DNSimple::Client.domain_api_token = new_resource.domain_api_token
end
domain = new_resource.domain
name = new_resource.name
content = new_resource.content
type = new_resource.type
ttl = new_resource.ttl
prio = new_resource.priority

zone = ::DNSimple::Domain.find(domain)
records = ::DNSimple::Record.all(zone)
if domain.nil?
parsed = name.match(/^(.*?)\.?([^\.]+\.[^\.]+)$/)
name = parsed[1]
domain = parsed[2]
end

exists = false
records.each do |r|
Chef::Log.debug "Checking if #{name} exists as #{content} and #{ttl}"
r.prio = nil if r.prio == ''

# do nothing if the record already exists
exists = ((r.name == name) and
(r.record_type == type) and
(r.content == content) and
(r.ttl == ttl) and
(r.prio == prio))
break if exists

# delete any record with the name we're trying to create
if r.name == name and r.record_type == type and r.prio == prio
Chef::Log.debug "Cannot modify a record, must destroy #{name} first"
r.destroy
prio = nil if prio == ''

if new_resource.domain_api_token.nil?
::DNSimple::Client.username = new_resource.username || node['dnsimple']['username']
::DNSimple::Client.password = new_resource.password || node['dnsimple']['password']
else
::DNSimple::Client.domain_api_token = new_resource.domain_api_token
end
end

unless exists
begin
Chef::Log.info "Attempting to create record type #{type} for #{name} as #{content}"
::DNSimple::Record.create(zone, name, type, content, ttl: ttl, prio: prio)
zone = ::DNSimple::Domain.find(domain)
records = ::DNSimple::Record.all(zone)

new_resource.updated_by_last_action(true)
Chef::Log.info "DNSimple: created #{type} record for #{name}.#{domain}"
rescue DNSimple::RecordExists
Chef::Log.debug "DNSimple: #{name}.#{domain} already exists, moving on"
rescue ::DNSimple::Error => err
Chef::Log.error "DNSimple: #{name}.#{domain} could not be created: #{err}"
exists = false
records.each do |r|
Chef::Log.debug "Checking if #{name} exists as #{content} and #{ttl}"
r.prio = nil if r.prio == ''

# do nothing if the record already exists
exists = ((r.name == name) and
(r.record_type == type) and
(r.content == content) and
(r.ttl == ttl) and
(r.prio == prio))
break if exists

# delete any record with the name we're trying to create
if r.name == name and r.record_type == type and r.prio == prio
Chef::Log.debug "Cannot modify a record, must destroy #{name} first"
r.destroy
end
end

unless exists
begin
Chef::Log.info "Attempting to create record type #{type} for #{name} as #{content}"
::DNSimple::Record.create(zone, name, type, content, ttl: ttl, prio: prio)

new_resource.updated_by_last_action(true)
Chef::Log.info "DNSimple: created #{type} record for #{name}.#{domain}"
rescue DNSimple::RecordExists
Chef::Log.debug "DNSimple: #{name}.#{domain} already exists, moving on"
rescue ::DNSimple::Error => err
Chef::Log.error "DNSimple: #{name}.#{domain} could not be created: #{err}"
end
end
end
end
2 changes: 1 addition & 1 deletion cookbooks/rubygems-hosts/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name 'rubygems-hosts'
maintainer 'RubyGems.org ops team'
description 'Configures /etc/hosts with all nodes in the current environment'
version '0.0.8'
version '0.0.10'
2 changes: 1 addition & 1 deletion cookbooks/rubygems-hosts/templates/default/hosts.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
127.0.0.1 localhost

<% @hosts.sort.each do |node| %>
<%= node['ipaddress'] %> <%= node['machinename'] %> <%= node['hostname'] %>
<%= node['ipaddress'] %> <%= node['machinename'] %> <%= node['hostname'] %><% if node['hostname'] == 'chef' %> chef.rubygems.org<% end %>
<% end %>

# The following lines are desirable for IPv6 capable hosts