Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit ecab7d2

Browse files
committed
Merge pull request #7 from gehel/git-clone
Added a git::clone define
2 parents aa4763f + 66ba10f commit ecab7d2

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

Modulefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ source 'https://github.com/example42/puppet-git'
77
summary 'Puppet module for git'
88
description 'This module installs and manages git. Check README for details.'
99
dependency 'example42/puppi', '>= 2.0.0'
10+
dependency 'puppetlabs-stdlib', '>=4.1.0'
1011
# dependency 'example42/monitor', '>= 2.0.0'
1112
# dependency 'example42/firewall', '>= 2.0.0'

manifests/clone.pp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# = Define: git::clone
2+
#
3+
# Clone a git repository if it does not exist yet. Will not do anything
4+
# if the clone already exists.
5+
#
6+
# == Parameters
7+
#
8+
# [*ensure*]
9+
# Define if the git_reposync script and eventual cron job
10+
# must be present or absent. Default: present.
11+
#
12+
# [*source_url*]
13+
# Url of the repository to use. As passed to the git command. Required.
14+
#
15+
# [*destination_dir*]
16+
# Local directory where to clone the repository. Required.
17+
#
18+
# [*creates*]
19+
# Path of a file or directory created by the git command. If it
20+
# exists Puppet will not clone the repo.
21+
# Default: $destination_dir.
22+
#
23+
# [*extra_options*]
24+
# Optional extra options to add to git command. Default: ''.
25+
#
26+
# [*branch*]
27+
# Optional branch name
28+
#
29+
# [*owner*]
30+
# Owner of the cloned repo.
31+
#
32+
define git::clone (
33+
$ensure = 'present',
34+
$source_url,
35+
$destination_dir,
36+
$creates = $destination_dir,
37+
$extra_options = '',
38+
$branch = $git::default_branch,
39+
$owner = $git::default_owner,) {
40+
include git
41+
42+
validate_string($owner)
43+
validate_string($branch)
44+
45+
case $ensure {
46+
'present' : {
47+
exec { "git-clone-${name}":
48+
command => "git clone --recursive ${source_url} -b ${branch} ${extra_options} ${destination_dir}",
49+
path => '/usr/bin',
50+
creates => $creates,
51+
user => $owner,
52+
}
53+
}
54+
'absent' : {
55+
file { "${destination_dir}":
56+
ensure => 'absent',
57+
recurse => true,
58+
force => true,
59+
}
60+
}
61+
default : {
62+
fail("git::clone only supports 'present' and 'absent', '${ensure}' is unknown.'")
63+
}
64+
}
65+
66+
}

manifests/init.pp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@
6262
# [*config_file*]
6363
# Main configuration file path
6464
#
65+
# [*default_owner*]
66+
# Owner of the repositories cloned via git::clone. Use this if most of the
67+
# repositories you clone should belong to the same user.
68+
# Default: root
69+
#
70+
# [*default_branch*]
71+
# Branch on which to execute operations. In most cases 'master' is what you
72+
# want, but if most of your repos should use another branch, use this
73+
# parameter to set the default.
74+
# Default: master
75+
#
76+
# [*clones*]
77+
# A hash describing a list of repo to clone.
78+
# Default: {}
79+
#
6580
# == Examples
6681
#
6782
# You can use this class in 2 ways:
@@ -81,7 +96,10 @@
8196
$audit_only = params_lookup( 'audit_only' , 'global' ),
8297
$noops = params_lookup( 'noops' ),
8398
$package = params_lookup( 'package' ),
84-
$config_file = params_lookup( 'config_file' )
99+
$config_file = params_lookup( 'config_file' ),
100+
$default_owner = params_lookup( 'default_owner' ),
101+
$default_branch = params_lookup( 'default_branch' ),
102+
$clones = params_lookup( 'clones' ),
85103
) inherits git::params {
86104

87105
$config_file_mode=$git::params::config_file_mode
@@ -152,4 +170,5 @@
152170
include $git::my_class
153171
}
154172

173+
create_resources('git::clone', $clones)
155174
}

manifests/params.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
default => 'root',
3737
}
3838

39+
$default_owner = 'root'
40+
$default_branch = 'master'
41+
$clones = {}
42+
3943
# General Settings
4044
$my_class = ''
4145
$source = ''

0 commit comments

Comments
 (0)