Skip to content

Instantly share code, notes, and snippets.

@yakatz
Created May 25, 2022 15:44
Show Gist options
  • Save yakatz/1df458814dcbc6f2604a5a9d9f2073d4 to your computer and use it in GitHub Desktop.
Save yakatz/1df458814dcbc6f2604a5a9d9f2073d4 to your computer and use it in GitHub Desktop.
Manage System Git Config with Puppet
class myweb::sites::wiki_example_com {
wiki_base = '/var/www/sites/wiki.example.com'
include ::profile::gitconfig
profile::gitconfig::safe_directory {"${wiki_base}/code/mediawiki-1.35-LTS":}
vcsrepo { "${wiki_base}/code/mediawiki-1.35-LTS/":
ensure => latest,
provider => git,
source => '[email protected]:wiki/mediawiki-1.35-LTS.git',
revision => 'master',
}
}
# == Class: profile::gitconfig
#
# Control System-Wide Git Configuration
#
# === Authors
#
# Yehuda Katz <[email protected]>
#
class profile::gitconfig {
$gitconfig_file = lookup('profile::gitconfig::file', {default_value => '/etc/gitconfig'})
$gitconfig_dir = lookup('profile::gitconfig::dir', {default_value => '/etc/gitconfig.d'})
Concat::Fragment <| tag == gitconfig |> -> Vcsrepo <| |>
file { $gitconfig_file:
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
}
file { $gitconfig_dir:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
ini_setting { 'Include Puppet-Managed Git Config':
ensure => present,
path => $gitconfig_file,
section => 'include',
setting => 'path',
value => "${gitconfig_dir}/puppet",
}
concat { 'gitconfig':
path => "${gitconfig_dir}/puppet",
owner => 'root',
group => 'root',
mode => '0644',
warn => true,
}
# For ordering, space comes before /: The space is important
concat::fragment { 'gitconfig-safedir- header':
target => 'gitconfig',
content => "[safe]\n",
order => '10',
}
}
# == Class: profile::gitconfig::safe_directory
#
# Add `safe.directory` to system config
#
# === Authors
#
# Yehuda Katz <[email protected]>
#
define profile::gitconfig::safe_directory (
Stdlib::Absolutepath $path = $title
) {
if $path =~ /^.+\/$/ {
fail("safe.directory can not have a trailing slash: ${path}")
}
concat::fragment { "gitconfig-safedir-${title}":
target => 'gitconfig',
content => " directory = ${path}\n",
order => '10',
tag => ['gitconfig'],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment