Skip to content

Instantly share code, notes, and snippets.

@ananace
Created September 29, 2022 18:03
Show Gist options
  • Save ananace/57c4cbd8cbff6818b155bb71e664489f to your computer and use it in GitHub Desktop.
Save ananace/57c4cbd8cbff6818b155bb71e664489f to your computer and use it in GitHub Desktop.
Puppet profile manifests for improved handling of Raspberry Pi nodes
# frozen_string_literal: true
# Fact to check Raspberry Pi information;
Facter.add(:pi) do
pi_dtb = '/sys/firmware/devicetree/base'
confine { File.exist? pi_dtb }
setcode do
{
raspberrypi: 'raspberrypi',
model: File.read(File.join(pi_dtb, 'model')).delete("\000"),
serial: File.read(File.join(pi_dtb, 'serial-number')).delete("\000"),
compatible: File.read(File.join(pi_dtb, 'compatible')).delete("\000").split(','),
}
end
end
# Creates the necessary information to turn a manual install into something that looks/works like an AiO install
class profiles::raspberry_pi::fake_aio {
file {
default:
ensure => file;
'/etc/facter/facts.d/aio_agent_version.txt':
content => "aio_agent_version=${fact('puppetversion')}";
'/etc/facter/facts.d/aio_fake_agent.txt':
content => "aio_fake_agent=true";
}
file {
'/opt/puppetlabs/bin':
ensure => directory;
'/opt/puppetlabs/puppet/bin':
ensure => directory;
'/opt/puppetlabs/puppet/lib':
ensure => directory;
'/opt/puppetlabs/bin/puppet':
ensure => link,
target => '/usr/local/bin/puppet';
'/opt/puppetlabs/puppet/bin/gem':
ensure => link,
target => '/usr/bin/gem';
'/opt/puppetlabs/puppet/bin/ruby':
ensure => link,
target => '/usr/bin/ruby';
'/opt/puppetlabs/puppet/lib/pkgconfig':
ensure => link,
target => '/usr/lib/pkgconfig/';
}
ensure_packages([
'pkgconf', 'ruby-augeas',
])
package { 'RPi puppet gem':
name => 'puppet',
ensure => 'latest',
provider => 'gem',
notify => Service['puppet'],
}
systemd::unit_file { 'puppet.service':
ensure => present,
content => @(EOF),
[Unit]
Description=Puppet agent
Wants=basic.target
After=basic.target network.target
[Service]
EnvironmentFile=-/etc/sysconfig/puppetagent
EnvironmentFile=-/etc/sysconfig/puppet
EnvironmentFile=-/etc/default/puppet
ExecStart=/usr/local/bin/puppet agent $PUPPET_EXTRA_OPTS --no-daemonize
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
WantedBy=multi-user.target
|-EOF
notify => Service['puppet'],
}
}
# Basic Pi configuration
class profiles::raspberry_pi(
Hash[String,String] $config_txt = { 'gpu_mem' => '16' },
Hash[String,String] $extra_config_txt = {},
String $cmdline_txt = '',
String $extra_cmdline_txt = '',
) {
if !fact('pi') {
notify { 'Not a Pi?':
message => 'profiles::raspberry_pi added to a non-pi, skipping.',
}
return()
}
if fact('os.name') == 'Raspbian' {
} elsif fact('os.name') == 'Debian' {
file_line {
default:
ensure => present,
path => '/etc/default/raspi-firmware',
notify => Exec['RPi Rebuild initrd/bootfiles'];
'RPi GPU Frequency':
line => 'GPU_FREQ="360"',
match => '^#?GPU_FREQ=.*';
}
file { '/etc/default/raspi-firmware-custom':
ensure => file,
}
($config_txt + $extra_config_txt).each |$k, $v| {
ini_setting { "RPi config.txt ${k}":
ensure => present,
path => '/etc/default/raspi-firmware-custom',
notify => Exec['RPi Rebuild initrd/bootfiles'],
setting => $k,
value => $v,
}
}
file { '/etc/default/raspi-extra-cmdline':
ensure => present,
content => [$cmdline_txt, $extra_cmdline_txt].join(' '), # 'dtoverlay=gpio-fan,gpiopin=18,temp=75000',
notify => Exec['RPi Rebuild initrd/bootfiles'],
}
exec { 'RPi Rebuild initrd/bootfiles':
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
command => 'update-initramfs -u -k all',
refreshonly => true,
}
}
systemd::dropin_file { '00-ensure-log.conf':
unit => 'sssd.service',
content => @(EOF),
[Service]
ExecStartPre=-mkdir -p /var/log/sssd
|-EOF
}
# To help ensure SD-card longevity;
mount {
default:
ensure => present,
fstype => 'tmpfs',
device => 'tmpfs';
'/tmp':
options => 'defaults,noatime,nosuid,size=100m';
'/var/tmp':
options => 'defaults,noatime,nosuid,size=1024m';
'/var/log':
options => 'defaults,noatime,nosuid,mode=0755,size=50m';
'/var/spool/mqueue':
options => 'defaults,noatime,nosuid,mode=0700,gid=12,size=10m';
}
file {
default:
ensure => directory;
'/etc/facter':;
'/etc/facter/facts.d':;
}
file {
default:
ensure => file;
'/etc/facter/facts.d/model.txt':
content => "model=${fact('pi.model')}";
}
#if !fact('aio_agent_version') or fact('aio_fake_agent') {
include profiles::raspberry_pi::fake_aio
#}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment