Added boilerplate for debian host management
* added apt repo management * added switcher based on OS to base.pp
This commit is contained in:
parent
2321925298
commit
4e30d9b6d9
7
hieradata/os/Debian/Debian12.yaml
Normal file
7
hieradata/os/Debian/Debian12.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
# hieradata/os/Debian/Debian12.yaml
|
||||
---
|
||||
profiles::apt::managed_repos:
|
||||
- 'base'
|
||||
- 'security'
|
||||
- 'updates'
|
||||
- 'puppet7'
|
||||
3
hieradata/os/Debian/all_releases.yaml
Normal file
3
hieradata/os/Debian/all_releases.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
# hieradata/os/debian/all_releases.yaml
|
||||
---
|
||||
profiles::apt::base::baseurl: http://debian.mirror.digitalpacific.com.au/debian
|
||||
36
site/profiles/manifests/apt/base.pp
Normal file
36
site/profiles/manifests/apt/base.pp
Normal file
@ -0,0 +1,36 @@
|
||||
class profiles::apt::base (
|
||||
Array[String] $managed_repos,
|
||||
Array[String] $components,
|
||||
String $baseurl,
|
||||
) {
|
||||
$releasever = $facts['os']['release']['major']
|
||||
$basearch = $facts['os']['architecture']
|
||||
$codename = $facts['os']['distro']['codename']
|
||||
|
||||
# Join the array into a space-separated string
|
||||
$repo_components = join($components, ' ')
|
||||
|
||||
apt::source { "deb.debian.org-${codename}":
|
||||
location => $baseurl,
|
||||
repos => $repo_components,
|
||||
release => $codename,
|
||||
}
|
||||
|
||||
apt::source { "deb.debian.org-${codename}-security":
|
||||
location => $baseurl,
|
||||
repos => $repo_components,
|
||||
release => "${codename}-security",
|
||||
}
|
||||
|
||||
apt::source { "deb.debian.org-${codename}-updates":
|
||||
location => $baseurl,
|
||||
repos => $repo_components,
|
||||
release => "${codename}-updates",
|
||||
}
|
||||
|
||||
apt::source { "deb.debian.org-${codename}-backports":
|
||||
location => $baseurl,
|
||||
repos => $repo_components,
|
||||
release => "${codename}-backports",
|
||||
}
|
||||
}
|
||||
97
site/profiles/manifests/apt/global.pp
Normal file
97
site/profiles/manifests/apt/global.pp
Normal file
@ -0,0 +1,97 @@
|
||||
# Class: profiles::apt::global
|
||||
#
|
||||
# This class manages global APT configurations and optionally includes the
|
||||
# base and Puppet7 apt repository profiles. The profiles included are based on
|
||||
# the content of the $managed_repos parameter, which is an array of repository names.
|
||||
#
|
||||
# Parameters:
|
||||
# -----------
|
||||
# $managed_repos: An array of repository names that should be managed by Puppet agent.
|
||||
# This parameter is mandatory and the class will fail if it is not provided via hieradata.
|
||||
# Example: ['base', 'security', 'updates', 'backports']
|
||||
#
|
||||
# Actions:
|
||||
# --------
|
||||
# Configures global APT settings, including setting up the 'src' and 'deb' options for all
|
||||
# repositories managed by Puppet.
|
||||
# Establishes default parameters for any APT repositories managed by Puppet.
|
||||
# These parameters include the repository description, the inclusion of 'src' and 'deb',
|
||||
# and the pinning.
|
||||
# Depending on the content of the $managed_repos parameter, it includes the
|
||||
# profiles::apt::base and/or profiles::apt::puppet7 classes.
|
||||
# Manages all .list files under /etc/apt/sources.list.d. All the repositories listed
|
||||
# in $managed_repos will have their corresponding .list files preserved. Any
|
||||
# .list file that is not listed in $managed_repos will be removed.
|
||||
# Creates and maintains a /etc/apt/sources.list.d/.managed file that lists all the
|
||||
# .list files that should be managed by Puppet.
|
||||
# Manages /etc/apt/sources.list file to include the .list files in /etc/apt/sources.list.d.
|
||||
#
|
||||
# Example usage:
|
||||
# --------------
|
||||
# To use this class, include it and configure hieradata:
|
||||
# include profiles::apt::global
|
||||
#
|
||||
# profiles::apt::managed_repos:
|
||||
# - 'base'
|
||||
# - 'security'
|
||||
# - 'updates'
|
||||
# - 'backports'
|
||||
class profiles::apt::global (
|
||||
Array[String] $managed_repos = lookup('profiles::apt::managed_repos'),
|
||||
Array[String] $components = lookup('profiles::apt::components'),
|
||||
){
|
||||
class { 'apt':
|
||||
update => {
|
||||
frequency => 'daily',
|
||||
loglevel => 'debug',
|
||||
},
|
||||
}
|
||||
|
||||
Apt::Source {
|
||||
include => {
|
||||
'src' => true,
|
||||
'deb' => true,
|
||||
},
|
||||
}
|
||||
|
||||
# Generate the content for the .managed file
|
||||
$managed_file_content = $managed_repos.map |$repo_name| { "${repo_name}.repo" }.join("\n")
|
||||
|
||||
# Create the .managed file
|
||||
file { '/etc/apt/sources.list.d/.managed':
|
||||
ensure => file,
|
||||
content => $managed_file_content,
|
||||
}
|
||||
|
||||
# Define exec resource to remove .list files not listed in .managed
|
||||
exec { 'cleanup_apt_repos':
|
||||
command => '/bin/bash -c "comm -23 <(ls /etc/apt/sources.list.d | sort)
|
||||
<(sort /etc/apt/sources.list.d/.managed) |
|
||||
xargs -n1 rm -f /etc/apt/sources.list.d/{}"',
|
||||
path => ['/bin', '/usr/bin'],
|
||||
onlyif => '/bin/bash -c "comm -23 <(ls /etc/apt/sources.list.d | sort)
|
||||
<(sort /etc/apt/sources.list.d/.managed) | grep .list"',
|
||||
}
|
||||
|
||||
file { '/etc/apt/sources.list':
|
||||
ensure => 'file',
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => @(END)
|
||||
## Apt is managed by Puppet, do not edit this file
|
||||
END
|
||||
}
|
||||
|
||||
# Setup base repos
|
||||
class { 'profiles::apt::base':
|
||||
managed_repos => $managed_repos,
|
||||
components => $components,
|
||||
}
|
||||
|
||||
# Setup puppet7 if included in managed_repos
|
||||
class { 'profiles::apt::puppet7':
|
||||
managed_repos => $managed_repos,
|
||||
components => $components,
|
||||
}
|
||||
}
|
||||
0
site/profiles/manifests/apt/puppet7.pp
Normal file
0
site/profiles/manifests/apt/puppet7.pp
Normal file
Loading…
Reference in New Issue
Block a user