Why integrate Chef and DNSimple?

Chef automates infrastructure, and DNSimple automates domain management. By combining forces, you can use Chef-Infra’s consistency guarantees to ensure system naming is done properly across your entire infrastructure, even if you are running it across a heterogeneous collection of hosts.

At DNSimple, we use Chef Infra to automate our global infrastructure of DNS servers. We have been using Chef Infra to automate and maintain all of our software configurations since our inception. Our software stack comes with its own unique needs and challenges, and Chef Infra’s flexibility makes it an excellent tool for the job.

We not only maintain a set of internal cookbooks, but several open source cookbooks you can find on the Chef Supermarket.

One of the cookbooks we maintain in the Chef Supermarket is our own DNSimple cookbook. This cookbook provides basic functionality of our API via Chef Infra LWRPs. Currently the cookbook allows Chef Infra to create or remove any of our supported DNS records. This can be really useful in cases when provisioning servers and services, automatically assigning them hostnames via recipes in conjunction with databags. Here’s how it works:

Automatically set up the hostnames

When bootstrapping a new server, we set the node-name to the hostname of the machine and let the chef hostname cookbook configure the host name in the operating system. The DNSimple cookbook then sets up the domain name in DNSimple’s public authoritative name servers, making the new server name available within a few seconds of provisioning.

include_recipe 'chef-vault::default'

credentials = chef_vault_item('secrets', 'dnsimple')

my_fqdn      = node.name

my_apexname  = my_fqdn.split('.')[-2..-1].join('.')
my_subdomain = my_fqdn.split('.')[0..-3].join('.')
my_shortname = my_fqdn.split('.').first

hostname my_fqdn do

  aliases [my_shortname]
end

include_recipe 'dnsimple::default'

dnsimple_record 'main_hostname_setup' do
  name     my_subdomain
  content  node['ipaddress']
  type     'A'
  domain   my_apexname
  username credentials['user']
  token    credentials['token']
  action   :create
end

Going past the hostname

Having consistently named machines that are easily accessible is a good starting point. The next step is to handle provisioning of additional records.

There are several approaches to managing records beyond the hostname; the bigger your setup, the more complex this is going to be since you don’t want to set the same domain name to the same box or they will battle for it.

While there is no one-size-fits-all solution, here is one example: first set the node attributes in a wrapper:

default['dnsimple']['cnames'] = %w( www )

Once this is in place, provision your hostname setting like this:

my_aliases = node['dnsimple']['cnames'].map{ |x| x + '.' + my_apexname }

hostname my_fqdn do

 aliases [my_shortname] + my_aliases
end
node['dnsimple']['cnames'].each do |cname|
 dnsimple_record "#{cname}_cname_setup" do
   name     cname
   content  my_fqdn
   type     'CNAME'
   domain   my_apexname
   username credentials['user']
   token    credentials['token']
   action   :create
 end
end

Enjoy your hands off DNS with machine converges

DNSimple cookbook and the services we offer can simplify and automate your domain name management.

The post Why integrate Chef and DNSimple? appeared first on Chef Blog.

Source: Chef