Skip to content

Instantly share code, notes, and snippets.

@reidmv
Created April 20, 2017 17:35
Show Gist options
  • Save reidmv/c66b0aaec8112f06f1beb648cb8f8ced to your computer and use it in GitHub Desktop.
Save reidmv/c66b0aaec8112f06f1beb648cb8f8ced to your computer and use it in GitHub Desktop.
Augeas defined type example using DNS Zone
# This defined type provides a clean interface that allows users to specify DNS
# zone attributes they're familiar with - origin, ttl, etc - to manage a zone
# file. It then uses an Augeas resource to implement the configuration
# specified by the user.
#
# The Augeas type is difficult to use so it's not great to actually write a lot
# of Augeas resources. By creating ausing a defined type, we can do the
# difficult work of creating an Augeas resource once. We build ourselves a
# simple, easy-to-use repeatable resource type that we can then use multiple
# times in our Puppet code.
define dns_zone (
Enum['present', 'absent'] $ensure = 'present',
String $zonefile = $title,
String $origin,
Integer $ttl,
# other attributes that matter can be passed in as parameters here
) {
file { $zonefile:
ensure => $ensure,
}
if $ensure == 'present' {
augeas { "zone_file:${zonefile}":
lens => 'dns_zone.lns',
incl => $zonefile,
context => "/files/${zonefile}",
require => File[$zonefile],
changes => [
"set \\\$ORIGIN ${origin}",
"set \\\$TTL ${ttl}",
# other attributes passed in can be configured here
],
}
}
}
# This is an example of how we can easily and simply create a DNS zone file now
# that we have the defined type for it. There is no need to use or understand
# Augeas again just to create another zone.
dns_zone { 'example.com':
ensure => present,
zonefile => '/Users/reidmv/example.com',
origin => 'example.com.',
ttl => 85000,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment