Added custom file definition which supports http, https and ftp urls.
This commit is contained in:
parent
9f0c254675
commit
f1a13d5e59
1 changed files with 83 additions and 0 deletions
|
@ -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
|
# Set root password
|
||||||
#
|
#
|
||||||
# === Global variables
|
# === Global variables
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue