aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBranan Purvine-Riley <branan@puppetlabs.com>2012-06-25 14:35:29 -0700
committerBranan Purvine-Riley <branan@puppetlabs.com>2012-06-25 14:35:29 -0700
commita2263208cd6e5007b28ef3859f2699b4b9580e25 (patch)
tree3ae144a5eaba9b35376c81d802a918f16c2b689f
parent6500ac722b939b86c32559508be3c7f224ba5cfe (diff)
parent600754c8d841646c73df3e0fe5d4290e8ddfd37d (diff)
downloadpuppet-tftp-a2263208cd6e5007b28ef3859f2699b4b9580e25.tar.gz
puppet-tftp-a2263208cd6e5007b28ef3859f2699b4b9580e25.tar.bz2
Merge pull request #8 from nanliu/tb/defaults
Add default module path for tftp::file
-rw-r--r--README.md24
-rw-r--r--manifests/file.pp38
-rw-r--r--manifests/init.pp2
-rw-r--r--manifests/params.pp9
-rw-r--r--spec/defines/tftp_file_spec.rb75
5 files changed, 113 insertions, 35 deletions
diff --git a/README.md b/README.md
index 9bd2000..d1c41c7 100644
--- a/README.md
+++ b/README.md
@@ -32,13 +32,16 @@ Example:
Parameters:
-* ensure: file type, default file.
-* recurse: file recurse, default false.
-* owner: file owner, default tftp.
-* group: file group. default tftp.
-* mode: file mode, default 0644 (puppet will change to 0755 for directories).
-* content: file content.
-* source: file source.
+* ensure: file type, default file.
+* owner: file owner, default tftp.
+* group: file group. default tftp.
+* mode: file mode, default 0644 (puppet will change to 0755 for directories).
+* content: file content.
+* source: file source, defaults to puppet:///module/${caller_module_name}/${name} for files without content.
+* recurse: directory recurse, default false.
+* purge: directory recurse and purge.
+* replace: replace directory with file or symlink, default undef,
+* recurselimit: directory recurse limit, default undef,
Example:
@@ -51,9 +54,14 @@ Example:
}
tftp::file { 'pxelinux.cfg/default':
- source => 'puppet:///modules/acme/default',
+ ensure => file,
+ source => 'puppet:///modules/acme/pxelinux.cfg/default',
}
+The last example can be abbreviated to the following if it's in the acme module:
+
+ tftp::file { 'pxelinux.cfg/default': }
+
## Example
1. tftp directories not in the OS package defaults should be managed as file resources.
diff --git a/manifests/file.pp b/manifests/file.pp
index ec67f2c..3628188 100644
--- a/manifests/file.pp
+++ b/manifests/file.pp
@@ -2,18 +2,37 @@
#
# Parameters:
#
+# [*ensure*]: file type, default file.
+# [*owner*]: file owner, default tftp.
+# [*group*]: file group. default tftp.
+# [*mode*]: file mode, default 0644 (puppet will change to 0755 for directories).
+# [*content*]: file content.
+# [*source*]: file source, defaults to puppet*]:///module/${caller_module_name}/${name} for files without content.
+# [*recurse*]: directory recurse, default false.
+# [*purge*]: directory recurse and purge.
+# [*replace*]: replace directory with file or symlink, default undef,
+# [*recurselimit*]: directory recurse limit, default undef,
+#
# Actions:
#
-# Requires:
+# Deploy files into the tftp directory.
#
# Usage:
#
+# tftp::file { 'pxelinux.0':
+# source => 'puppet:///modules/acme/pxelinux.0',
+# }
+#
+# tftp::file { 'pxelinux.cfg':
+# ensure => directory,
+# }
+#
define tftp::file (
$ensure = file,
- $recurse = false,
$owner = 'tftp',
$group = 'tftp',
$mode = '0644',
+ $recurse = false,
$purge = undef,
$replace = undef,
$recurselimit = undef,
@@ -22,17 +41,28 @@ define tftp::file (
) {
include 'tftp'
+ if $source {
+ $source_real = $source
+ } elsif $ensure != 'directory' and ! $content {
+ if $caller_module_name {
+ $mod = $caller_module_name
+ } else {
+ $mod = $module_name
+ }
+ $source_real = "puppet:///modules/${mod}/${name}"
+ }
+
file { "${tftp::directory}/${name}":
ensure => $ensure,
- recurse => $recurse,
owner => $owner,
group => $group,
mode => $mode,
+ recurse => $recurse,
purge => $purge,
replace => $replace,
recurselimit => $recurselimit,
content => $content,
- source => $source,
+ source => $source_real,
require => Class['tftp'],
}
}
diff --git a/manifests/init.pp b/manifests/init.pp
index 13954b5..9dfab37 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -18,7 +18,7 @@
#
# Usage:
#
-# class tftp {
+# class { 'tftp':
# directory => '/opt/tftp',
# address => $::ipaddress,
# options => '--ipv6 --timeout 60',
diff --git a/manifests/params.pp b/manifests/params.pp
index 564e0f2..e658184 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,13 +1,6 @@
# Class: tftp::params
#
-# Parameters:
-#
-# Actions:
-#
-# Requires:
-#
-# Usage:
-#
+# TFTP class parameters.
class tftp::params {
$address = '0.0.0.0'
$port = '69'
diff --git a/spec/defines/tftp_file_spec.rb b/spec/defines/tftp_file_spec.rb
index 6a032c0..0de1b6f 100644
--- a/spec/defines/tftp_file_spec.rb
+++ b/spec/defines/tftp_file_spec.rb
@@ -11,10 +11,10 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'file',
- 'recurse' => false,
'owner' => 'tftp',
'group' => 'tftp',
- 'mode' => '0644'
+ 'mode' => '0644',
+ 'recurse' => false,
}) }
end
@@ -25,29 +25,29 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/var/lib/tftpboot/sample').with({
'ensure' => 'file',
- 'recurse' => false,
'owner' => 'tftp',
'group' => 'tftp',
- 'mode' => '0644'
+ 'mode' => '0644',
+ 'recurse' => false,
}) }
end
describe 'when deploying with parameters' do
- let(:params) { {:ensure => 'directory',
- :recurse => true,
- :owner => 'root',
- :group => 'root',
- :mode => '0755' }}
+ let(:params) { {:ensure => 'directory',
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0755',
+ :recurse => true }}
let(:facts) { { :operatingsystem => 'Debian',
:path => '/usr/local/bin:/usr/bin:/bin', } }
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'directory',
- 'recurse' => true,
'owner' => 'root',
'group' => 'root',
- 'mode' => '0755'
+ 'mode' => '0755',
+ 'recurse' => true,
}) }
end
@@ -61,14 +61,14 @@ describe 'tftp::file' do
'recurse' => false,
'purge' => nil,
'replace' => nil,
- 'recurselimit' => nil
+ 'recurselimit' => nil,
}) }
end
describe 'when deploying with recurse parameters' do
let(:params) { {:ensure => 'directory',
- :recurse => true,
:mode => '0755',
+ :recurse => true,
:recurselimit => 42,
:purge => true,
:replace => false }}
@@ -78,13 +78,60 @@ describe 'tftp::file' do
it { should include_class('tftp') }
it { should contain_file('/srv/tftp/sample').with({
'ensure' => 'directory',
- 'recurse' => true,
'owner' => 'tftp',
'group' => 'tftp',
'mode' => '0755',
+ 'recurse' => true,
'recurselimit' => 42,
'purge' => true,
'replace' => false,
}) }
end
+
+ describe 'when deploying directory' do
+ let(:params) { {:ensure => 'directory',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'directory',
+ 'mode' => '0755',
+ 'source' => nil,
+ }) }
+ end
+
+ describe 'when deploying file from another module' do
+ let(:params) { {:ensure => 'file',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'file',
+ 'mode' => '0755',
+ 'source' => 'puppet:///modules/acme/sample'
+ }) }
+ end
+
+ describe 'when deploying file with content' do
+ let(:params) { {:ensure => 'file',
+ :content => 'hi',
+ :mode => '0755' }}
+ let(:facts) { { :operatingsystem => 'Debian',
+ :caller_module_name => 'acme',
+ :path => '/usr/local/bin:/usr/bin:/bin', } }
+
+ it { should include_class('tftp') }
+ it { should contain_file('/srv/tftp/sample').with({
+ 'ensure' => 'file',
+ 'mode' => '0755',
+ 'content' => 'hi',
+ 'source' => nil,
+ }) }
+ end
end