Skip to content

Commit

Permalink
Support the dns_powerdns plugin
Browse files Browse the repository at this point in the history
closes GH-189
  • Loading branch information
ekohl authored and mmoll committed Oct 9, 2015
1 parent 50dfd1d commit caf8f91
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fixtures:
dhcp: 'git://github.com/theforeman/puppet-dhcp'
dns: 'git://github.com/theforeman/puppet-dns'
foreman: 'git://github.com/theforeman/puppet-foreman'
mysql: 'git://github.com/puppetlabs/puppetlabs-mysql.git'
puppet: 'git://github.com/theforeman/puppet-puppet'
stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
tftp: 'git://github.com/theforeman/puppet-tftp'
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ interact with, e.g. DNS, DHCP and Puppet and TFTP.

Part of the Foreman installer: http://github.com/theforeman/foreman-installer

## PowerDNS support

To use the PowerDNS plugin, the following variables need to be set on the main
`foreman_proxy` class.

$dns => true
$dns_managed => false
$dns_provider => 'dns_powerdns'

Then you also need to include `foreman_proxy::plugin::dns::powerdns`.

The powerdns plugin can optionally manage the database. If that's used, then
the puppetlabs-mysql module must be added to the modulepath, otherwise it's not
required.

## Compatibility

This module only supports Smart Proxy 1.6 or higher as of version 2.0, as the
Expand Down
46 changes: 46 additions & 0 deletions manifests/plugin/dns/powerdns.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# = Foreman Proxy PowerDNS DNS plugin
#
# This class installs the PowerDNS DNS plugin for Foreman proxy
#
# === Parameters:
#
# $mysql_hostname:: MySQL server hostname
#
# $mysql_username:: MySQL server username
#
# $mysql_password:: MySQL server password
#
# $mysql_database:: MySQL server database
#
# $manage_database:: Whether to manage the mysql database. Also includes the mysql server.
#
# $pdnssec:: pdnssec command to run rectify-zone with. Can be an empty string.
#
class foreman_proxy::plugin::dns::powerdns (
$mysql_hostname = $::foreman_proxy::plugin::dns::powerdns::params::mysql_hostname,
$mysql_username = $::foreman_proxy::plugin::dns::powerdns::params::mysql_username,
$mysql_password = $::foreman_proxy::plugin::dns::powerdns::params::mysql_password,
$mysql_database = $::foreman_proxy::plugin::dns::powerdns::params::mysql_database,
$manage_database = $::foreman_proxy::plugin::dns::powerdns::params::manage_database,
$pdnssec = $::foreman_proxy::plugin::dns::powerdns::params::pdnssec,
) inherits foreman_proxy::plugin::dns::powerdns::params {
validate_bool($manage_database)
validate_string($mysql_hostname, $mysql_username, $mysql_password, $mysql_database, $pdnssec)

if $manage_database {
include ::mysql::server
mysql::db { $mysql_database:
user => $mysql_username,
password => $mysql_password,
host => $mysql_hostname,
grant => ['ALL'],
}
}

foreman_proxy::plugin { 'dns_powerdns':
} ->
foreman_proxy::settings_file { 'dns_powerdns':
module => false,
template_path => 'foreman_proxy/plugin/dns_powerdns.yml.erb',
}
}
8 changes: 8 additions & 0 deletions manifests/plugin/dns/powerdns/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class foreman_proxy::plugin::dns::powerdns::params {
$mysql_hostname = 'localhost'
$mysql_username = 'pdns'
$mysql_password = cache_data('smart_proxy_dns_powerdns_password', random_password(16))
$mysql_database = 'pdns'
$manage_database = false
$pdnssec = 'pdnssec'
}
72 changes: 72 additions & 0 deletions spec/classes/foreman_proxy__plugin__dns__powerdns_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'spec_helper'

describe 'foreman_proxy::plugin::dns::powerdns' do
let :facts do
on_supported_os['redhat-7-x86_64']
end

let :pre_condition do
'include ::foreman_proxy'
end

context 'default parameters' do
let :params do
{
:mysql_password => 'password',
}
end

it { should compile.with_all_deps }

it 'should install the correct plugin' do
should contain_foreman_proxy__plugin('dns_powerdns')
end

it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
':powerdns_mysql_database: "pdns"',
':powerdns_pdnssec: "pdnssec"',
])
end
end

context 'with manage_database => true' do
let :params do
{
:mysql_password => 'password',
:manage_database => true,
}
end

it { should compile.with_all_deps }

it 'should install the correct plugin' do
should contain_foreman_proxy__plugin('dns_powerdns')
end

it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
':powerdns_mysql_database: "pdns"',
':powerdns_pdnssec: "pdnssec"',
])
end

it 'should manage the database' do
should contain_class('mysql::server')

should contain_mysql__db('pdns') \
.with_user('pdns') \
.with_password('password') \
.with_host('localhost') \
.with_grant(['ALL'])
end
end
end
6 changes: 6 additions & 0 deletions templates/plugin/dns_powerdns.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:powerdns_mysql_hostname: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_hostname') %>"
:powerdns_mysql_username: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_username') %>"
:powerdns_mysql_password: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_password') %>"
:powerdns_mysql_database: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_database') %>"
:powerdns_pdnssec: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::pdnssec') %>"

0 comments on commit caf8f91

Please sign in to comment.