Defined Type: rsync::get

Defined in:
manifests/get.pp

Summary

get files via rsync ussing exec

Overview

Examples:

rsync::get { '/foo':
  source  => "rsync://${rsync_server}/repo/foo/",
  require => File['/foo'],
}

Parameters:

  • source (String)

    source to copy from

  • path (String) (defaults to: $name)

    path to copy to

  • user (Optional[String]) (defaults to: undef)

    username on remote system

  • keyfile (String) (defaults to: "/home/${user}/.ssh/id_rsa")

    path to ssh key used to connect to remote host

  • timeout (String) (defaults to: '900')

    timeout in seconds

  • execuser (String) (defaults to: 'root')

    user to run the command (passed to exec)

  • options (String) (defaults to: '-a')

    commandline options to pass to rsync (-a)

  • onlyif (Optional[String]) (defaults to: undef)

    Condition to run the rsync command



15
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
# File 'manifests/get.pp', line 15

define rsync::get (
  String            $source,
  String            $path          = $name,
  Optional[String]  $user          = undef,
  String            $keyfile       = "/home/${user}/.ssh/id_rsa",
  String            $timeout       = '900',
  String            $execuser      = 'root',
  String            $options       = '-a',
  Optional[String]  $onlyif        = undef,
) {
  if $user {
    $myuser = "-e 'ssh -i ${keyfile} -l ${user}' ${user}@"
  } else {
    $myuser = undef
  }

  $rsync_options = join(
  delete_undef_values([$options, "${myuser}${source}", $path]), ' ')

  if !$onlyif {
    $onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
  } else {
    $onlyif_real = $onlyif
  }

  exec { "rsync ${name}":
    command => "rsync -q ${rsync_options}",
    path    => ['/bin', '/usr/bin', '/usr/local/bin'],
    user    => $execuser,
    # perform a dry-run to determine if anything needs to be updated
    # this ensures that we only actually create a Puppet event if something needs to
    # be updated
    # TODO - it may make senes to do an actual run here (instead of a dry run)
    #        and relace the command with an echo statement or something to ensure
    #        that we only actually run rsync once
    onlyif  => $onlyif_real,
    timeout => $timeout,
  }
}