Defined Type: git::replicated_local_repo
- Defined in:
- modules/git/manifests/replicated_local_repo.pp
Summary
This class handles creating a repository and replicating it to other servers.Overview
SPDX-License-Identifier: Apache-2.0
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 |
# File 'modules/git/manifests/replicated_local_repo.pp', line 29
define git::replicated_local_repo (
Array[Stdlib::Fqdn] $servers,
String $user,
String $user_homedir,
Sensitive[String] $ssh_privkey,
Optional[String] $ssh_pubkey = undef,
Boolean $mail_changes = false,
String $mailto = 'ops@wikimedia.org',
) {
$repo_path = "/srv/git/${title}"
$safe_title = regsubst($title, '[^a-zA-Z0-9]', '_', 'G')
## ssh setup ##
file { "${user_homedir}/.ssh":
ensure => directory,
owner => $user,
group => $user,
mode => '0700',
}
$privkey_path = "${user_homedir}/.ssh/id_${safe_title}"
$git_ssh_wrapper = "${user_homedir}/.ssh/ssh_wrapper_${safe_title}"
# We want to be able to connect to other servers
file { $privkey_path:
ensure => file,
content => $ssh_privkey,
owner => $user,
group => $user,
mode => '0600',
}
# If you have declared the ssh_pubkey parameter, we will add it to the
# authorized_keys file. If you have not, you will need to add the key.
# This is to support cases where the same user has multiple ssh userkeys.
# They will need to be declared separately.
if $ssh_pubkey != undef {
ssh::userkey { $user:
ensure => present,
user => $user,
content => $ssh_pubkey,
}
}
file { $git_ssh_wrapper:
ensure => file,
content => "#!/bin/sh\n/usr/bin/ssh -i '${privkey_path}' \"$@\"",
owner => $user,
group => $user,
mode => '0550',
}
## git setup ##
# If we have more than just this server, clone from another server and install the git commit hook.
# Otherwise, just initialize the repository.
if ($servers != [] and $servers != [$facts['networking']['fqdn']]) {
$controller = $servers[0]
$git_command = "GIT_SSH=${git_ssh_wrapper} /usr/bin/git clone 'ssh://${user}@${controller}:${repo_path}' '${repo_path}'"
$hook_ensure = file
} else {
$git_command = "/usr/bin/git -C '${repo_path}' init && git -C '${repo_path}' switch -c main"
$hook_ensure = absent
# TODO: add a README with a "What not to do" section?
}
$create = "git init ${safe_title}"
exec { $create:
command => "/usr/bin/mkdir -p '${repo_path}' && ${git_command} && chown -R '${user}:${user}' '${repo_path}'",
creates => "${repo_path}/.git",
notify => Exec["set config for ${safe_title}"],
}
exec { "set config for ${safe_title}":
command => "/usr/bin/git -C '${repo_path}' config receive.denyCurrentBranch ignore",
refreshonly => true,
user => $user,
}
file { "${repo_path}/.git/hooks/post-commit":
ensure => $hook_ensure,
content => template('git/replicated_local_postcommit.sh.erb'),
owner => $user,
group => $user,
mode => '0755',
require => Exec[$create],
}
}
|