Showing with 139 additions and 41 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 Modulefile
  3. +6 −0 README.md
  4. +24 −13 manifests/init.pp
  5. +13 −26 metadata.json
  6. +93 −0 spec/classes/init_spec.rb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec/reports
test/tmp
test/version_tmp
tmp
Gemfile.lock

# YARD artifacts
.yardoc
Expand Down
4 changes: 2 additions & 2 deletions Modulefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name 'ghoneycutt-hosts'
version '2.1.0'
version '2.2.0'
source 'git://github.com/ghoneycutt/puppet-module-hosts.git'
author 'ghoneycutt'
license 'Apache License, Version 2.0'
license 'Apache-2.0'
summary 'Manages host entries'
description "Can ensure entries for localhost, localhost6, and $::fqdn,
including aliases and optionally purge unmanaged entries."
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Boolean to enable entry for fqdn

- *Default*: true

use_fqdn
--------
When enabled use the ${::fqdn} fact to determine the hosts entry for the local node.

- *Default*: true

fqdn_host_aliases
-----------------
String or Array of aliases for fqdn
Expand Down
37 changes: 24 additions & 13 deletions manifests/init.pp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$enable_ipv4_localhost = true,
$enable_ipv6_localhost = true,
$enable_fqdn_entry = true,
$use_fqdn = true,
$fqdn_host_aliases = $::hostname,
$localhost_aliases = ['localhost',
'localhost4',
Expand Down Expand Up @@ -51,6 +52,14 @@
$fqdn_entry_enabled = $enable_fqdn_entry
}

# validate type and convert string to boolean if necessary
$use_fqdn_type = type($use_fqdn)
if $use_fqdn_type == 'string' {
$use_fqdn_real = str2bool($use_fqdn)
} else {
$use_fqdn_real = $use_fqdn
}

# validate type and convert string to boolean if necessary
$purge_hosts_type = type($purge_hosts)
if $purge_hosts_type == 'string' {
Expand Down Expand Up @@ -119,20 +128,22 @@
ip => $localhost6_ip,
}

@@host { $::fqdn:
ensure => $fqdn_ensure,
host_aliases => $my_fqdn_host_aliases,
ip => $fqdn_ip,
}

case $collect_all_real {
# collect all the exported Host resources
true: {
Host <<| |>>
if $use_fqdn_real == true {
@@host { $::fqdn:
ensure => $fqdn_ensure,
host_aliases => $my_fqdn_host_aliases,
ip => $fqdn_ip,
}
# only collect the exported entry above
default: {
Host <<| title == $::fqdn |>>

case $collect_all_real {
# collect all the exported Host resources
true: {
Host <<| |>>
}
# only collect the exported entry above
default: {
Host <<| title == $::fqdn |>>
}
}
}

Expand Down
39 changes: 13 additions & 26 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"name": "ghoneycutt-hosts",
"version": "2.2.0",
"author": "ghoneycutt",
"summary": "Manages host entries",
"license": "Apache-2.0",
"source": "git://github.com/ghoneycutt/puppet-module-hosts.git",
"project_page": "https://github.com/ghoneycutt/puppet-module-hosts",
"issues_url": "https://github.com/ghoneycutt/puppet-module-hosts/issues",
"requirements": [
{
"name": "pe",
Expand Down Expand Up @@ -38,32 +46,11 @@
"operatingsystem": "Ubuntu"
}
],
"name": "ghoneycutt-hosts",
"version": "2.1.0",
"source": "git://github.com/ghoneycutt/puppet-module-hosts.git",
"author": "ghoneycutt",
"license": "Apache License, Version 2.0",
"summary": "Manages host entries",
"description": "Can ensure entries for localhost, localhost6, and $::fqdn,\nincluding aliases and optionally purge unmanaged entries.",
"project_page": "https://github.com/ghoneycutt/puppet-module-hosts",
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 3.2.0"
}
],
"types": [

],
"checksums": {
"Gemfile": "f184c7cca73bc8169572ab8c48e223bc",
"LICENSE": "567e6cc3941d464d60c74d1f4abd5f46",
"Modulefile": "23e22dfce928f3b4d78974af79d64c4a",
"README.md": "409911c21322853063ba3e9e75aed2bb",
"Rakefile": "1cb426d5b98cd8d27b9147563a78ab7c",
"manifests/init.pp": "d86f62e2f3f7ba129fb411862046221d",
"spec/classes/init_spec.rb": "ef5fc5741cef2e5289fa8397e1d13e89",
"spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
"tests/init.pp": "669ed02ca7363697bf7491d75e9ceac3"
}
}
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0"}
]
}
93 changes: 93 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,99 @@
end
end

describe 'with \'use_fqdn\' parameter set to' do
[false, 'false'].each do |use_fqdn_value|
context "#{use_fqdn_value}" do
let(:params) { { :use_fqdn => use_fqdn_value } }
let(:facts) {
{ :hostname => 'monkey',
:ipaddress => '10.1.2.3',
:fqdn => 'monkey.example.com',
}
}

it {
should contain_host('localhost').with({
'ensure' => 'absent',
'target' => '/etc/hosts',
})
}

it {
should contain_host('localhost.localdomain').with({
'ensure' => 'present',
'host_aliases' => ['localhost', 'localhost4', 'localhost4.localdomain4'],
'ip' => '127.0.0.1',
'target' => '/etc/hosts',
})
}

it {
should contain_host('localhost6.localdomain6').with({
'ensure' => 'present',
'host_aliases' => ['localhost6', 'localhost6.localdomain6'],
'ip' => '::1',
'target' => '/etc/hosts',
})
}

it { should_not contain_host('monkey.example.com') }

it { should contain_resources('host').with({'purge' => 'false'}) }
end
end
end

describe 'with \'use_fqdn\' parameter set to' do
[true,'true'].each do |use_fqdn_value|
context "#{use_fqdn_value}" do
let(:params) { { :use_fqdn => use_fqdn_value } }
let(:facts) {
{ :hostname => 'monkey',
:ipaddress => '10.1.2.3',
:fqdn => 'monkey.example.com',
}
}

it {
should contain_host('localhost').with({
'ensure' => 'absent',
'target' => '/etc/hosts',
})
}

it {
should contain_host('localhost.localdomain').with({
'ensure' => 'present',
'host_aliases' => ['localhost', 'localhost4', 'localhost4.localdomain4'],
'ip' => '127.0.0.1',
'target' => '/etc/hosts',
})
}

it {
should contain_host('localhost6.localdomain6').with({
'ensure' => 'present',
'host_aliases' => ['localhost6', 'localhost6.localdomain6'],
'ip' => '::1',
'target' => '/etc/hosts',
})
}

# # GH: rspec-puppet does not yet support checking for exported resources
# it {
# should contain_host('monkey.example.com').with({
# 'ensure' => 'present',
# 'host_aliases' => ['monkey'],
# 'ip' => '10.1.2.3',
# })
# }

it { should contain_resources('host').with({'purge' => 'false'}) }
end
end
end

describe 'with \'localhost_aliases\' parameter set to' do
context 'single value' do
let(:params) { { :localhost_aliases => 'home' } }
Expand Down