Defined Type: tp::copy_file
- Defined in:
- manifests/copy_file.pp
Summary
Copies a file from source to destinationOverview
This defines copied a file from a source to a destination using an exec resource. It does not overwrite the destination file if it exists (and overwrite is set to true) and can be used as alternative to a file resource to avoid duplicated resources.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'manifests/copy_file.pp', line 16
define tp::copy_file (
Stdlib::AbsolutePath $source,
Enum['present','absent'] $ensure = 'present',
Stdlib::AbsolutePath $path = $title,
Optional[String] $owner = undef,
Optional[String] $group = undef,
Optional[String] $mode = undef,
Boolean $overwrite = false,
) {
if $overwrite {
$exec_creates = undef
$exec_unless = "diff ${source} ${path} >/dev/null"
} else {
$exec_creates = $path
$exec_unless = undef
}
if $ensure == 'present' {
exec { "tp::copy_file ${title}":
command => "cp ${source} ${path}",
path => $facts['path'],
creates => $exec_creates,
unless => $exec_unless,
}
if $owner {
exec { "chown ${owner} ${title}":
command => "chown ${owner} ${path}",
path => $facts['path'],
onlyif => "[ $(ls -ld ${path} | awk '{ print \$3 }') != ${owner} ]",
}
}
if $group {
exec { "chgrp ${group} ${title}":
command => "chgrp ${group} ${path}",
path => $facts['path'],
onlyif => "[ $(ls -ld ${path} | awk '{ print \$4 }') != ${group} ]",
}
}
if $mode {
exec { "chmod ${mode} ${title}":
command => "chmod ${mode} ${path}",
path => $facts['path'],
subscribe => Exec["tp::copy_file ${title}"],
refreshonly => true,
}
}
} else {
exec { "tp::copy_file ${title}":
command => "rm -f ${path}",
path => $facts['path'],
onlyif => "test -f ${path}",
}
}
}
|