This repository was archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathreposync.pp
More file actions
158 lines (152 loc) · 4.69 KB
/
reposync.pp
File metadata and controls
158 lines (152 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# = Define: git::reposync
#
# This define creates, executes and optionally crontabs a
# simple git_reposync_* script that exports or checkouts a git
# repository to a local directory.
# By default this script is placed in:
# /usr/local/sbin/git_reposync_${name}
# and can be executed directly by hand, via Puppet (if autorun is true)
# via cron (if cron is defined) or via the master script:
# /usr/local/sbin/git_reposync
#
# == Parameters:
#
# [*source_url*]
# Url of the repository to use. As passed to the git command
# present in the git_reposync script. Required.
#
# [*destination_dir*]
# Local directory where to sync the repository. As passed to the
# git command present in the git_reposync script. Required.
#
# [*extra_options*]
# Optional extra options to add to git command. Default: ''.
#
# [*branch*]
# Optional branch name defaults to master
#
# [*autorun*]
# Define if to automatically execute the git_reposync script when
# Puppet runs. Default: true.
#
# [*creates*]
# Path of a file or directory created by the git command. If it
# exists Puppet does not automatically execute the git_reposync
# command (when autorun is enabled). Default: $destination_dir.
#
# [*pre_command*]
# Optional command to execute before executing the git command.
# Note that this command is placed in the git_reposync script created
# by this define and it's executed every time this script is run (either
# manually or via Puppet). Default: ''
#
# [*post_command*]
# Optional command to execute after executing the git command.
# Note that this command is placed in the git_reposync script created
# by this define and it's executed every time this script is run (either
# manually or via Puppet). Default: ''
#
# [*execute_on_change*]
# Define if the pre_command and post_command will be execute at the same
# time as puppet (default) or only when change has been made into repository.
#
# [*basedir*]
# Directory where the git_reposync scripts are created.
# Default: /usr/local/sbin
#
# [*cron*]
# Optional cron schedule to crontab the execution of the
# git_reposync script. Format must be in standard cron style.
# Example: '0 4 * * *' . Default: '' (no cron scheduled).
#
# [*owner*]
# Owner of the created git_reposync script. Default: root.
#
# [*group*]
# Group of the created git_reposync script. Default: root.
#
# [*mode*]
# Mode of the created git_reposync script. Default: '7550'.
# NOTE: Keep the execution flag!
#
# [*ensure*]
# Define if the git_reposync script and eventual cron job
# must be present or absent. Default: present.
#
# == Examples
#
# - Minimal setup (with autorun and export)
# git::reposync { 'my_app':
# source_url => 'http://repo.example42.com/git/trunk/my_app/',
# destination_dir => '/opt/myapp',
# }
#
# - Execute a custom command after git (with default autorun)
# git::reposync { 'my_app':
# source_url => 'http://repo.example42.com/git/trunk/my_app/',
# destination_dir => '/opt/myapp',
# post_command => 'chown -R my_user:my_user /opt/myapp',
# }
#
define git::reposync (
$source_url,
$destination_dir,
$extra_options = '',
$branch = 'master',
$autorun = true,
$creates = $destination_dir,
$pre_command = '',
$post_command = '',
$execute_on_change = false,
$basedir = '/usr/local/sbin',
$cron = '',
$owner = 'root',
$group = 'root',
$mode = '0755',
$ensure = 'present' ) {
include git
$manage_execute_on_change = any2bool($execute_on_change)
if ! defined(File[$basedir]) {
file { $basedir:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
}
if ! defined(File['git_reposync']) {
file { 'git_reposync':
ensure => present,
path => "${basedir}/git_reposync",
mode => $mode,
owner => $owner,
group => $group,
content => template('git/reposync/git_reposync.erb'),
}
}
file { "git_reposync_${name}":
ensure => $ensure,
path => "${basedir}/git_reposync_${name}",
mode => $mode,
owner => $owner,
group => $group,
content => template('git/reposync/git_reposync-command.erb'),
require => Package[$git::package],
}
if $autorun == true {
exec { "git_reposync_run_${name}":
command => "${basedir}/git_reposync_${name}",
creates => $creates,
}
}
if $cron != '' {
file { "git_reposync_cron_${name}":
ensure => $ensure,
path => "/etc/cron.d/git_reposync_${name}",
mode => '0644',
owner => 'root',
group => 'root',
content => template('git/reposync/git_reposync-cron.erb'),
}
}
}