diff --git a/Gemfile.lock b/Gemfile.lock
index d34a186..67a17ff 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
- addressable (2.3.5)
+ CFPropertyList (2.2.8)
+ addressable (2.3.6)
ansi (1.4.3)
boxen (1.5.2)
ansi (~> 1.4)
@@ -16,26 +17,30 @@ GEM
puppet-lint (~> 0.3)
puppetlabs_spec_helper (~> 0.4)
rspec-puppet (~> 0.1)
- diff-lcs (1.2.4)
- facter (1.7.2)
- faraday (0.8.7)
- multipart-post (~> 1.1)
- faraday_middleware (0.9.0)
- faraday (>= 0.7.4, < 0.9)
- hashie (2.0.5)
- hiera (1.2.1)
+ diff-lcs (1.2.5)
+ facter (2.2.0)
+ CFPropertyList (~> 2.2.6)
+ faraday (0.9.0)
+ multipart-post (>= 1.2, < 3)
+ faraday_middleware (0.9.1)
+ faraday (>= 0.7.4, < 0.10)
+ hashie (2.1.2)
+ hiera (1.3.4)
json_pure
- highline (1.6.19)
- json (1.8.0)
- json_pure (1.8.0)
- librarian-puppet (0.9.9)
- json
+ highline (1.6.21)
+ json (1.8.1)
+ json_pure (1.8.1)
+ librarian (0.1.2)
+ highline
thor (~> 0.15)
- metaclass (0.0.1)
- mocha (0.14.0)
+ librarian-puppet (0.9.17)
+ json
+ librarian (>= 0.1.2)
+ metaclass (0.0.4)
+ mocha (1.1.0)
metaclass (~> 0.0.1)
- multi_json (1.7.7)
- multipart-post (1.2.0)
+ multi_json (1.10.1)
+ multipart-post (2.0.0)
netrc (0.7.7)
octokit (1.25.0)
addressable (~> 2.2)
@@ -44,29 +49,36 @@ GEM
hashie (~> 2.0)
multi_json (~> 1.3)
netrc (~> 0.7.7)
- puppet (3.2.3)
- facter (~> 1.6)
+ puppet (3.7.0)
+ facter (> 1.6, < 3)
hiera (~> 1.0)
- rgen (~> 0.6.5)
+ json_pure
puppet-lint (0.3.2)
- puppetlabs_spec_helper (0.4.1)
- mocha (>= 0.10.5)
+ puppet-syntax (1.3.0)
rake
- rspec (>= 2.9.0)
- rspec-puppet (>= 0.1.1)
- rake (10.1.0)
- rgen (0.6.5)
- rspec (2.14.1)
- rspec-core (~> 2.14.0)
- rspec-expectations (~> 2.14.0)
- rspec-mocks (~> 2.14.0)
- rspec-core (2.14.4)
- rspec-expectations (2.14.0)
- diff-lcs (>= 1.1.3, < 2.0)
- rspec-mocks (2.14.1)
+ puppetlabs_spec_helper (0.8.1)
+ mocha
+ puppet-lint
+ puppet-syntax
+ rake
+ rspec
+ rspec-puppet
+ rake (10.3.2)
+ rspec (3.1.0)
+ rspec-core (~> 3.1.0)
+ rspec-expectations (~> 3.1.0)
+ rspec-mocks (~> 3.1.0)
+ rspec-core (3.1.2)
+ rspec-support (~> 3.1.0)
+ rspec-expectations (3.1.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.1.0)
+ rspec-mocks (3.1.0)
+ rspec-support (~> 3.1.0)
rspec-puppet (0.1.6)
rspec
- thor (0.18.1)
+ rspec-support (3.1.0)
+ thor (0.19.1)
PLATFORMS
ruby
diff --git a/data/Darwin.yaml b/data/Darwin.yaml
new file mode 100644
index 0000000..d11fd34
--- /dev/null
+++ b/data/Darwin.yaml
@@ -0,0 +1,7 @@
+---
+dnsmasq::configdir: "%{boxen::config::configdir}/dnsmasq"
+dnsmasq::configfile: "%{boxen::config::configdir}/dnsmasq/dnsmasq.conf"
+dnsmasq::datadir: "%{boxen::config::datadir}/dnsmasq"
+dnsmasq::executable: "%{boxen::config::homebrewdir}/sbin/dnsmasq"
+dnsmasq::logdir: "%{boxen::config::logdir}/dnsmasq"
+dnsmasq::logfile: "%{boxen::config::logdir}/dnsmasq/console.log"
diff --git a/data/common.yaml b/data/common.yaml
new file mode 100644
index 0000000..ed365e4
--- /dev/null
+++ b/data/common.yaml
@@ -0,0 +1,3 @@
+---
+dnsmasq::host: 127.0.0.1
+dnsmasq::tld: dev
diff --git a/data/hiera.yaml b/data/hiera.yaml
new file mode 100644
index 0000000..876f4d3
--- /dev/null
+++ b/data/hiera.yaml
@@ -0,0 +1,4 @@
+---
+:hierarchy:
+ - "%{::osfamily}"
+ - common
diff --git a/manifests/config.pp b/manifests/config.pp
deleted file mode 100644
index 64f54d8..0000000
--- a/manifests/config.pp
+++ /dev/null
@@ -1,24 +0,0 @@
-# Internal: Configure dnsmasq.
-#
-# Examples
-#
-# include dnsmasq::config
-class dnsmasq::config {
- require boxen::config
-
- $configdir = "${boxen::config::configdir}/dnsmasq"
- $configfile = "${configdir}/dnsmasq.conf"
- $datadir = "${boxen::config::datadir}/dnsmasq"
- $executable = "${boxen::config::homebrewdir}/sbin/dnsmasq"
- $logdir = "${boxen::config::logdir}/dnsmasq"
- $logfile = "${logdir}/console.log"
-
- anchor { [
- $configdir,
- $configfile,
- $datadir,
- $executable,
- $logdir,
- $logfile,
- ]: }
-}
diff --git a/manifests/init.pp b/manifests/init.pp
index 5b86174..467fcb2 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -3,39 +3,49 @@
# Examples
#
# include dnsmasq
-class dnsmasq {
+class dnsmasq(
+ $host = undef,
+ $tld = undef,
+
+ $configdir = undef,
+ $configfile = undef,
+ $datadir = undef,
+ $executable = undef,
+ $logdir = undef,
+ $logfile = undef,
+) {
require homebrew
- require dnsmasq::config
+ $servicename = 'dev.dnsmasq'
- file { [$dnsmasq::config::configdir, $dnsmasq::config::logdir, $dnsmasq::config::datadir]:
- ensure => directory
+ file { [$configdir, $logdir, $datadir]:
+ ensure => directory,
}
- file { "${dnsmasq::config::configdir}/dnsmasq.conf":
- notify => Service['dev.dnsmasq'],
- require => File[$dnsmasq::config::configdir],
- source => 'puppet:///modules/dnsmasq/dnsmasq.conf'
+ file { "${configdir}/dnsmasq.conf":
+ content => template('dnsmasq/dnsmasq.conf.erb'),
+ notify => Service[$servicename],
+ require => File[$configdir],
}
- file { '/Library/LaunchDaemons/dev.dnsmasq.plist':
- content => template('dnsmasq/dev.dnsmasq.plist.erb'),
+ file { "/Library/LaunchDaemons/${tld}.dnsmasq.plist":
+ content => template("dnsmasq/${tld}.dnsmasq.plist.erb"),
group => 'wheel',
- notify => Service['dev.dnsmasq'],
- owner => 'root'
+ notify => Service[$servicename],
+ owner => 'root',
}
file { '/etc/resolver':
ensure => directory,
group => 'wheel',
- owner => 'root'
+ owner => 'root',
}
- file { '/etc/resolver/dev':
+ file { "/etc/resolver/${tld}":
content => 'nameserver 127.0.0.1',
group => 'wheel',
owner => 'root',
require => File['/etc/resolver'],
- notify => Service['dev.dnsmasq'],
+ notify => Service[$servicename],
}
homebrew::formula { 'dnsmasq':
@@ -44,16 +54,16 @@
package { 'boxen/brews/dnsmasq':
ensure => '2.71-boxen1',
- notify => Service['dev.dnsmasq']
+ notify => Service[$servicename],
}
- service { 'dev.dnsmasq':
+ service { $servicename:
ensure => running,
- require => Package['boxen/brews/dnsmasq']
+ require => Package['boxen/brews/dnsmasq'],
}
service { 'com.boxen.dnsmasq': # replaced by dev.dnsmasq
- before => Service['dev.dnsmasq'],
- enable => false
+ before => Service[$servicename],
+ enable => false,
}
}
diff --git a/spec/classes/dnsmasq_config_spec.rb b/spec/classes/dnsmasq_config_spec.rb
deleted file mode 100644
index 76e8e44..0000000
--- a/spec/classes/dnsmasq_config_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-describe 'dnsmasq::config' do
-
- let(:facts) do
- {
- :boxen_home => '/opt/boxen',
- :boxen_user => 'testuser',
- :boxen_srcdir => '/tmp/src',
- :github_login => 'testuser',
- }
- end
-
- it do
- should include_class('boxen::config')
-
- should contain_anchor('/opt/boxen/config/dnsmasq')
- should contain_anchor('/opt/boxen/config/dnsmasq/dnsmasq.conf')
- should contain_anchor('/opt/boxen/data/dnsmasq')
- should contain_anchor('/opt/boxen/homebrew/sbin/dnsmasq')
- should contain_anchor('/opt/boxen/log/dnsmasq')
- should contain_anchor('/opt/boxen/log/dnsmasq/console.log')
- end
-end
diff --git a/spec/classes/dnsmasq_spec.rb b/spec/classes/dnsmasq_spec.rb
index eb651d3..bb15799 100644
--- a/spec/classes/dnsmasq_spec.rb
+++ b/spec/classes/dnsmasq_spec.rb
@@ -1,36 +1,45 @@
require 'spec_helper'
describe 'dnsmasq' do
- let(:boxen_home) { '/opt/boxen' }
- let(:logdir) { "#{boxen_home}/log" }
- let(:confdir) { "#{boxen_home}/config" }
-
- let(:facts) do
- {
- :boxen_home => '/opt/boxen',
- :boxen_user => 'testuser',
- :boxen_srcdir => '/tmp/src',
- :github_login => 'testuser',
- }
- end
+
+ let(:facts) { default_test_facts }
+ let(:boxen_home) { "/test/boxen" }
+ let(:configdir) { "#{boxen_home}/config/dnsmasq" }
+ let(:configfile) { "#{configdir}/dnsmasq.conf" }
+ let(:datadir) { "#{boxen_home}/data/dnsmasq" }
+ let(:logdir) { "#{boxen_home}/log/dnsmasq" }
+ let(:logfile) { "#{logdir}/console.log" }
+ let(:executable) { "#{boxen_home}/homebrew/sbin/dnsmasq" }
+ let(:tld) { "dev" }
+ let(:servicename) { "#{tld}.dnsmasq" }
+ let(:params) {{
+ 'host' => "127.0.0.1",
+ 'tld' => tld,
+ 'configdir' => configdir,
+ 'datadir' => datadir,
+ 'logdir' => logdir,
+ 'configfile' => configfile,
+ 'logfile' => logfile,
+ 'executable' => executable,
+ }}
it do
should include_class('homebrew')
- should include_class('dnsmasq::config')
- should contain_file("#{confdir}/dnsmasq").with_ensure('directory')
- should contain_file("#{logdir}/dnsmasq").with_ensure('directory')
+ should contain_file(configdir).with_ensure('directory')
+ should contain_file(datadir).with_ensure('directory')
+ should contain_file(logdir).with_ensure('directory')
- should contain_file("#{confdir}/dnsmasq/dnsmasq.conf").with({
- :notify => 'Service[dev.dnsmasq]',
- :require => "File[#{confdir}/dnsmasq]",
- :source => 'puppet:///modules/dnsmasq/dnsmasq.conf',
+ should contain_file(configfile).with({
+ :content => File.read('spec/fixtures/dnsmasq.conf'),
+ :notify => "Service[#{servicename}]",
+ :require => "File[#{configdir}]",
})
should contain_file('/Library/LaunchDaemons/dev.dnsmasq.plist').with({
:content => File.read('spec/fixtures/dev.dnsmasq.plist'),
:group => 'wheel',
- :notify => 'Service[dev.dnsmasq]',
+ :notify => "Service[#{servicename}]",
:owner => 'root',
})
@@ -51,10 +60,10 @@
should contain_package('boxen/brews/dnsmasq').with({
:ensure => '2.71-boxen1',
- :notify => 'Service[dev.dnsmasq]',
+ :notify => "Service[#{servicename}]",
})
- should contain_service('dev.dnsmasq').with({
+ should contain_service(servicename).with({
:ensure => 'running',
:require => 'Package[boxen/brews/dnsmasq]',
})
diff --git a/spec/fixtures/dev.dnsmasq.plist b/spec/fixtures/dev.dnsmasq.plist
index 733e6d1..852b995 100644
--- a/spec/fixtures/dev.dnsmasq.plist
+++ b/spec/fixtures/dev.dnsmasq.plist
@@ -13,8 +13,8 @@
ProgramArguments
- /opt/boxen/homebrew/sbin/dnsmasq
- --conf-file=/opt/boxen/config/dnsmasq/dnsmasq.conf
+ /test/boxen/homebrew/sbin/dnsmasq
+ --conf-file=/test/boxen/config/dnsmasq/dnsmasq.conf
--keep-in-foreground
@@ -28,12 +28,12 @@
WorkingDirectory
- /opt/boxen/data/dnsmasq
+ /test/boxen/data/dnsmasq
StandardErrorPath
- /opt/boxen/log/dnsmasq/console.log
+ /test/boxen/log/dnsmasq/console.log
StandardOutPath
- /opt/boxen/log/dnsmasq/console.log
+ /test/boxen/log/dnsmasq/console.log
diff --git a/files/dnsmasq.conf b/spec/fixtures/dnsmasq.conf
similarity index 100%
rename from files/dnsmasq.conf
rename to spec/fixtures/dnsmasq.conf
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d3923f8..97dff6e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -6,3 +6,13 @@
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
end
+
+def default_test_facts
+ @default_test_facts ||= {
+ :boxen_home => "/test/boxen",
+ :boxen_user => "testuser",
+ :operatingsystem => "Debian",
+ :osfamily => "Debian",
+ :ipaddress => "127.0.0.1",
+ }
+end
diff --git a/templates/dev.dnsmasq.plist.erb b/templates/dev.dnsmasq.plist.erb
index 14a8339..3cf27fa 100644
--- a/templates/dev.dnsmasq.plist.erb
+++ b/templates/dev.dnsmasq.plist.erb
@@ -8,13 +8,13 @@
Boxen
Description
- Redirects *.dev DNS requests to localhost.
+ Redirects *.<%= @tld %> DNS requests to localhost.
ProgramArguments
- <%= scope.lookupvar "dnsmasq::config::executable" %>
- --conf-file=<%= scope.lookupvar "dnsmasq::config::configfile" %>
+ <%= @executable %>
+ --conf-file=<%= @configfile %>
--keep-in-foreground
@@ -28,12 +28,12 @@
WorkingDirectory
- <%= scope.lookupvar "dnsmasq::config::datadir" %>
+ <%= @datadir %>
StandardErrorPath
- <%= scope.lookupvar "dnsmasq::config::logfile" %>
+ <%= @logfile %>
StandardOutPath
- <%= scope.lookupvar "dnsmasq::config::logfile" %>
+ <%= @logfile %>
diff --git a/templates/dnsmasq.conf.erb b/templates/dnsmasq.conf.erb
new file mode 100644
index 0000000..2858b6b
--- /dev/null
+++ b/templates/dnsmasq.conf.erb
@@ -0,0 +1,6 @@
+bind-interfaces
+keep-in-foreground
+no-resolv
+
+address=/<%= @tld %>/<%= @host %>
+listen-address=127.0.0.1