Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from denmat/tld
Browse files Browse the repository at this point in the history
Adding ability to have different tld's
  • Loading branch information
jacobbednarz authored Sep 18, 2017
2 parents 26ae5a1 + f18af6e commit 4435da1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/spec/fixtures/Puppetfile.lock
/spec/fixtures/modules
/spec/fixtures/vendor
/vendor
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ consistently resolve to `127.0.0.1`.
include dnsmasq
```

### Using a domain other than .dev
If you wish to use something other than ```.dev``` you can set call your class with the following:

```puppet
class { 'dnsmasq': tld => 'docker' }
```

## Required Puppet Modules

* `boxen`
Expand Down
39 changes: 21 additions & 18 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,36 @@
#
# include dnsmasq
class dnsmasq(
$host = undef,
$tld = undef,

$configdir = undef,
$configfile = undef,
$datadir = undef,
$executable = undef,
$logdir = undef,
$logfile = undef,
$host = undef,
$tld = 'dev',
$service_name = undef,
$configdir = undef,
$configfile = undef,
$datadir = undef,
$executable = undef,
$logdir = undef,
$logfile = undef,
) {
require homebrew
$servicename = 'dev.dnsmasq'

if ! $service_name {
$service = "${tld}.dnsmasq"
}

file { [$configdir, $logdir, $datadir]:
ensure => directory,
}

file { "${configdir}/dnsmasq.conf":
content => template('dnsmasq/dnsmasq.conf.erb'),
notify => Service[$servicename],
notify => Service[$service],
require => File[$configdir],
}

file { '/Library/LaunchDaemons/dev.dnsmasq.plist':
content => template('dnsmasq/dev.dnsmasq.plist.erb'),
file { "/Library/LaunchDaemons/${service}.plist":
content => template('dnsmasq/dnsmasq.plist.erb'),
group => 'wheel',
notify => Service[$servicename],
notify => Service[$service],
owner => 'root',
}

Expand All @@ -45,7 +48,7 @@
group => 'wheel',
owner => 'root',
require => File['/etc/resolver'],
notify => Service[$servicename],
notify => Service[$service],
}

homebrew::formula { 'dnsmasq':
Expand All @@ -54,16 +57,16 @@

package { 'boxen/brews/dnsmasq':
ensure => '2.76-boxen2',
notify => Service[$servicename],
notify => Service[$service],
}

service { $servicename:
service { $service:
ensure => running,
require => Package['boxen/brews/dnsmasq'],
}

service { 'com.boxen.dnsmasq': # replaced by dev.dnsmasq
before => Service[$servicename],
before => Service[$service],
enable => false,
}
}
52 changes: 41 additions & 11 deletions spec/classes/dnsmasq_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'

describe 'dnsmasq' do

let(:facts) { default_test_facts }
let(:boxen_home) { "/test/boxen" }
let(:configdir) { "#{boxen_home}/config/dnsmasq" }
Expand All @@ -11,7 +10,7 @@
let(:logfile) { "#{logdir}/console.log" }
let(:executable) { "#{boxen_home}/homebrew/sbin/dnsmasq" }
let(:tld) { "dev" }
let(:servicename) { "#{tld}.dnsmasq" }
let(:service_name) { "#{tld}.dnsmasq" }
let(:params) {{
'host' => "127.0.0.1",
'tld' => tld,
Expand All @@ -25,23 +24,20 @@

it do
should contain_class('homebrew')

should contain_file(configdir).with_ensure('directory')
should contain_file(datadir).with_ensure('directory')
should contain_file(logdir).with_ensure('directory')

should contain_file(configfile).with({
:content => File.read('spec/fixtures/dnsmasq.conf'),
:notify => "Service[#{servicename}]",
:notify => "Service[#{service_name}]",
:require => "File[#{configdir}]",
})
}).with_content(%r{\naddress=/dev/127.0.0.1\nlisten-address=127.0.0.1\n})

should contain_file('/Library/LaunchDaemons/dev.dnsmasq.plist').with({
:content => File.read('spec/fixtures/dev.dnsmasq.plist'),
:group => 'wheel',
:notify => "Service[#{servicename}]",
:notify => "Service[#{service_name}]",
:owner => 'root',
})
}).with_content(%r{<string>#{tld}.dnsmasq</string>})

should contain_file('/etc/resolver').with({
:ensure => 'directory',
Expand All @@ -60,12 +56,46 @@

should contain_package('boxen/brews/dnsmasq').with({
:ensure => '2.76-boxen2',
:notify => "Service[#{servicename}]",
:notify => "Service[#{service_name}]",
})

should contain_service(servicename).with({
should contain_service(service_name).with({
:ensure => 'running',
:require => 'Package[boxen/brews/dnsmasq]',
})
end

context 'given a different tld' do
let(:tld) { "vagrant" }
let(:service_name) { "#{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 contain_file(configfile).with({
:notify => "Service[#{service_name}]",
:require => "File[#{configdir}]",
}).with_content(%r{\naddress=/vagrant/127.0.0.1\nlisten-address=127.0.0.1\n})

should contain_file('/Library/LaunchDaemons/vagrant.dnsmasq.plist').with({
:group => 'wheel',
:notify => "Service[#{service_name}]",
:owner => 'root',
}).with_content(%r{<string>#{tld}.dnsmasq</string>})

should contain_file('/etc/resolver/vagrant').with({
:content => 'nameserver 127.0.0.1',
:group => 'wheel',
:owner => 'root',
:require => 'File[/etc/resolver]',
})
end
end
end
39 changes: 0 additions & 39 deletions spec/fixtures/dev.dnsmasq.plist

This file was deleted.

6 changes: 0 additions & 6 deletions spec/fixtures/dnsmasq.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.dnsmasq</string>
<string><%= @tld %>.dnsmasq</string>

<key>Boxen</key>
<dict>
Expand Down

0 comments on commit 4435da1

Please sign in to comment.