-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff7a331
Showing
8 changed files
with
132 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,2 @@ | ||
# v0.0.1 | ||
* Initial commit |
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,3 @@ | ||
# DNS | ||
|
||
Automatically create DNS records for your nodes |
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,8 @@ | ||
default[:dns][:provider] = node[:cloud][:provider] | ||
default[:dns][:domain] = node[:domain] | ||
default[:dns][:credentials] = {} | ||
default[:dns][:disable] = !node[:cloud] | ||
default[:dns][:entry][:name] = node[:fqdn] | ||
default[:dns][:entry][:type] = 'A' | ||
default[:dns][:entry][:value] = node[:ipaddress] | ||
default[:dns][:chef_client_config] = false |
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,9 @@ | ||
name 'dns' | ||
maintainer 'Chris Roberts' | ||
maintainer_email '[email protected]' | ||
license 'Apache 2.0' | ||
description 'Create DNS entries for nodes' | ||
|
||
version '0.0.1' | ||
|
||
depends 'build-essential', '>= 1.1.0' # set minimum so we get compile time support |
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,9 @@ | ||
include_recipe 'chef-client::config' | ||
|
||
# Force chef-client config to use node name | ||
begin | ||
client_config = node.run_context.resource_collection.lookup("template[#{node["chef_client"]["conf_dir"]}/client.rb]") | ||
client_config.variables.update(:chef_node_name => Chef::Config[:node_name]) | ||
rescue => e | ||
Chef::Log.warn "Failed to locate chef client.rb template resource. If client.rb is managed, please check why it cannot be found: #{e}" | ||
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,53 @@ | ||
require 'resolv' | ||
|
||
include_recipe 'dns::fog' | ||
|
||
ruby_block 'Apply DNS information' do | ||
block do | ||
require 'fog' | ||
|
||
node.default[:dns][:entry][:name] = [node.name, node[:dns][:domain]].join('.') | ||
|
||
con = Fog::DNS.new( | ||
node[:dns][:credentials].merge( | ||
:provider => node[:dns][:provider] | ||
) | ||
) | ||
domain = con.list_domains.body['domains'].detect do |domain_hash| | ||
domain_hash['name'] == node[:dns][:domain] | ||
end | ||
raise "Failed to locate registered domain in account for configured domain: #{node[:dns][:domain]}" unless domain | ||
zone = con.zones.get(domain['id']) | ||
raise "Failed to locate zone for configured domain: #{node[:dns][:domain]}" unless zone | ||
record = zone.records.detect do |r| | ||
r.name == node[:dns][:entry][:name] | ||
end | ||
if(record) | ||
Chef::Log.info "DNS - Found existing record for: #{node[:dns][:entry][:name]}. Updating." | ||
Chef::Log.info "DNS - Existing type: #{record.type} Existing value: #{record.value}" | ||
record.value = node[:dns][:entry][:value] | ||
record.type = node[:dns][:entry][:type].upcase | ||
record.save | ||
else | ||
Chef::Log.info "DNS - No existing record found for #{node[:dns][:entry][:name]}. Creating." | ||
zone.records.create( | ||
:value => node[:dns][:entry][:value], | ||
:name => node[:dns][:entry][:name], | ||
:type => node[:dns][:entry][:type].upcase | ||
) | ||
end | ||
Chef::Log.info "DNS - Record saved: name: #{node[:dns][:entry][:name]} type: #{node[:dns][:entry][:type]} value: #{node[:dns][:entry][:value]}" | ||
end | ||
not_if do | ||
node[:dns][:disable] || | ||
begin | ||
Resolv.getaddress(node[:dns][:entry][:name]) == node[:dns][:entry][:value] | ||
rescue Resolv::ResolvError | ||
false | ||
end | ||
end | ||
end | ||
|
||
if(node[:dns][:chef_client_config]) | ||
include_recipe 'dns::chef-client' | ||
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,15 @@ | ||
node.set[:build_essential][:compiletime] = true | ||
include_recipe 'build-essential' | ||
|
||
# Dependencies required by nokogiri (for fog) | ||
%w(libxslt-dev libxml2-dev).each do |pkg| | ||
c_pkg = package(pkg) | ||
c_pkg.run_action(:install) | ||
end | ||
|
||
|
||
# TODO: Remove this once the gem_hell cookbook is ready to roll | ||
chef_gem "fog" do | ||
version '1.10.1' | ||
action :install | ||
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,33 @@ | ||
# Ensure we have our entry name defaulted | ||
node.default[:dns][:entry][:name] = [node.name, node[:dns][:domain]].join('.') | ||
|
||
# Set desired hostname and fqdn based on entry name | ||
node.set[:hosts_file][:hostname] = node[:dns][:entry][:name].split('.').first | ||
node.set[:hosts_file][:fqdn] = node[:dns][:entry][:name] | ||
|
||
include_recipe 'hosts_file' | ||
|
||
template 'fqdn_set_hosts_file' do | ||
source 'hosts.erb' | ||
path node[:hosts_file][:path] | ||
mode 0644 | ||
action :nothing | ||
not_if do | ||
node[:fqdn] == node[:dns][:entry][:name] | ||
end | ||
end.run_action(:create) | ||
|
||
file '/etc/hostname' do | ||
content "#{node[:hosts_file][:hostname]}\n" | ||
end | ||
|
||
execute "Set hostname to #{node[:hosts_file][:hostname]}" do | ||
action :nothing | ||
command "hostname #{node[:hosts_file][:hostname]}" | ||
not_if "hostname | grep #{node[:hosts_file][:hostname]}" | ||
end.run_action(:run) | ||
|
||
ohai 'fqdn' do | ||
action :nothing | ||
end.run_action(:reload) | ||
|