From f1a13d5e59e465b97935b22f47a7e5e61ff85d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Thu, 14 Oct 2010 01:03:48 +0300 Subject: [PATCH] Added custom file definition which supports http, https and ftp urls. --- custom/manifests/init.pp | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/custom/manifests/init.pp b/custom/manifests/init.pp index 5720a52..a6fc0d5 100644 --- a/custom/manifests/init.pp +++ b/custom/manifests/init.pp @@ -20,6 +20,89 @@ class custom { } +# Extended version of default File type. +# +# === Parameters: +# +# $ensure: +# See $ensure from File type. +# $group: +# See $ensure from File type. +# $mode: +# See $ensure from File type. +# $owner: +# See $ensure from File type. +# $seltype: +# See $ensure from File type. +# $source: +# See $ensure from File type. This define will also accept http, +# https and ftp urls. +# +# === Sample usage: +# +# custom::file { "/usr/src/puppet.tar.gz": +# ensure => present, +# source => "http://puppetlabs.com/downloads/puppet/puppet-2.6.2.tar.gz", +# } +# +define custom::file($ensure, $group="NONE", $mode="NONE", $owner="NONE", $seltype="NONE", $source) { + + $test = regsubst($source, '^([^:]+)://.+$', '\1') + if "${test}" == "${source}" { + $method = "file" + $path = "${source}" + } else { + $method = "${test}" + } + + case $method { + "ftp","http","https": { + $fetch_cmd = "wget -q -O '${name}' '${source}'" + $diff_cmd = "wget -q -O - '${source}' | diff -q - '${name}'" + } + } + + case $method { + "file": {} + "puppet": {} + default: { + exec { "fetch-file-${source}": + path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + command => $fetch_cmd, + unless => $diff_cmd, + before => File["${name}"], + } + } + } + + file { "${name}": + ensure => "${ensure}", + source => "${method}" ? { + "file" => "${path}", + "puppet" => "${source}", + default => undef, + }, + mode => "${mode}" ? { + "NONE" => undef, + default => "${mode}", + }, + owner => "${owner}" ? { + "NONE" => undef, + default => "${owner}", + }, + group => "${group}" ? { + "NONE" => undef, + default => "${group}", + }, + seltype => "${seltype}" ? { + "NONE" => undef, + default => "${seltype}", + }, + } + +} + + # Set root password # # === Global variables