summaryrefslogtreecommitdiff
path: root/manifests/init.pp
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-05-05 00:31:37 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-05-05 00:31:37 +0200
commiteb38e6252b3c52a44d0d33679b3bc3178674c7f8 (patch)
treeb7958e38f9893c347af4c04a53f65a103cef3292 /manifests/init.pp
parentInitial commit (diff)
downloaddns-eb38e6252b3c52a44d0d33679b3bc3178674c7f8.tar.gz
dns-eb38e6252b3c52a44d0d33679b3bc3178674c7f8.tar.xz
Everything
Diffstat (limited to 'manifests/init.pp')
-rw-r--r--manifests/init.pp94
1 files changed, 94 insertions, 0 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..ebb161b
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,94 @@
+# @param config_file
+# Bind9 configuration file
+# @param directory
+# Maps to bind9 directory. Base for all relative paths.
+# @param checkzone
+# Absolute path to named-checkzone binary
+# @param checkconf
+# Absolute path to named-checkconf binary
+# @param packagename
+# Name of the bind9 system package
+# @param manage_package
+# Should the bind9 system package be managed by this module.
+# @param rndc
+# Absolute path to rndc binary
+# @param keys
+# Dns::Key resources to create
+# @param zones
+# Dns::Zones resources to create
+# @param rndc_key_file
+# Location of rndc key. Note that this doesn't change where it ends up, but rather were we expect it to end up.
+# Key will be generated through `rndc-confgen -a`.
+# @param servicename
+# Name of the system service to manage
+# @param rndc_confgen
+# Path to rndc-confgen binary
+class dns (
+ String $config_file = '/etc/named.conf',
+ # String $config_dir = '/etc/named.d',
+ String $rndc_key_file = '/etc/rndc.key',
+ String $directory = '/var/named',
+ String $checkzone = '/usr/bin/named-checkzone',
+ String $checkconf = '/usr/bin/named-checkconf',
+ Array[Dns::Keyentry] $keys = [],
+ Array[Dns::Zoneentry] $zones = [],
+ String $packagename = 'bind9',
+ Boolean $manage_package = true,
+ String $servicename = 'named',
+ String $rndc = '/usr/bin/rndc',
+ String $rndc_confgen = '/usr/bin/rndc-confgen',
+) {
+ $zone_directory = "${directory}/zones"
+ $jnl_directory = "${directory}/journal"
+
+ file { $zone_directory:
+ ensure => directory,
+ recurse => true,
+ purge => true,
+ }
+
+ file { $jnl_directory:
+ ensure => directory,
+ }
+
+ if $manage_package {
+ package { $packagename:
+ ensure => installed,
+ }
+ }
+
+ service { $servicename:
+ ensure => running,
+ enable => true,
+ }
+
+ create_resources(dns::key, $keys)
+ create_resources(dns::zone, $zones)
+
+ # file { $config_dir:
+ # ensure => directory,
+ # recurse => true,
+ # }
+
+ exec { 'Setup rndc key':
+ cmd => [$rndc_confgen, '-a'],
+ creates => $rndc_key_file,
+ }
+
+ concat { $config_file:
+ ensure_newline => true,
+ warn => '; File managed by Puppet. Local changes WILL be overwritter',
+ validate_cmd => "${checkconf} %",
+ notify => Service[$servicename],
+ }
+
+ concat::fragment { 'named.conf main configuration':
+ target => $config_file,
+ content => epp("${module_name}/named.conf.epp"),
+ }
+
+ concat::fragment { 'named.conf rndc configuration':
+ target => $config_file,
+ content => epp("${module_name}/named-rndc.conf.epp"),
+ }
+}