Skip to content

Instantly share code, notes, and snippets.

View h0tw1r3's full-sized avatar
🏝️
Living the dream

Jeffrey Clark h0tw1r3

🏝️
Living the dream
View GitHub Profile
@h0tw1r3
h0tw1r3 / resolv.rb
Created August 28, 2023 16:13
resolv.conf fact for puppet
# local resolver configuration
require 'resolv'
Facter.add('resolv') do
setcode do
Resolv::DNS::Config.default_config_hash
end
end
@h0tw1r3
h0tw1r3 / loggertest.sh
Last active August 23, 2023 19:30
continuously log random meat ipsum to syslog using logger
#!/bin/bash
TMPFILE=$(mktemp)
finish() {
rm -f "${TMPFILE}"
}
trap 'finish' EXIT
UNIQ_LINES=20
@h0tw1r3
h0tw1r3 / region_tzinfo.rb
Created August 15, 2023 16:57
aws region timezone fact for puppet, useful for cron offsets when system time is UTC
Facter.add('region_tzinfo') do
ec2m = Facter.value(:ec2_metadata)
# aws instances that have not been powercycled in 2+ years
# will not have region in the metadata
aws_zone = ec2m.dig('placement', 'availability-zone')
iana_tz = case aws_zone
when %r{^ap-southeast-1}
'Asia/Singapore'
when %r{^ap-southeast-2}
'Australia/Sydney'
@h0tw1r3
h0tw1r3 / catalog.sh
Last active August 8, 2023 19:41
Directly request a puppet catalog with curl
puppet plugin download --verbose
puppet facts upload --verbose
curl "https://$(puppet config print server):8140/puppet/v3/catalog/$(hostname -f)?environment=$(puppet config print environment)" \
--cert $(puppet config print hostcert) \
--cacert $(puppet config print localcacert) \
--key "$(puppet config print hostprivkey)" \
--silent | jq . > catalog.json
jq '.resources[] | select(.parameters.recurse == true )' catalog.json
@h0tw1r3
h0tw1r3 / test.pp
Created June 10, 2023 04:09
Test single exec to manage systemd unit override with Puppet
exec { 'override-service-unit':
provider => 'shell',
environment => ['SYSTEMD_EDITOR=tee'],
command => 'echo "[Service]\nPrivateTmp=no\n" | script -qefc "systemctl edit nutcracker.service" /dev/null',
unless => '/usr/bin/env systemctl show nutcracker.service --property=PrivateTmp | grep "=no"',
notify => Service['nutcracker'],
}
$ git clone -b 1.22 https://github.com/crosstool-ng/crosstool-ng.git
$ cd crosstool-ng
$ ./bootstrap
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd ..
$ mkdir ctng
$ cd rpi1
$ ct-ng menuconfig
@h0tw1r3
h0tw1r3 / mingw-copy-deps.sh
Created October 16, 2015 15:25
Recursively copy windows binary (dll/exe) dependencies from a sysroot (mingw toolchain) to the binaries directory.
#!/usr/bin/env bash
#
# Copyright: © 2015 Jeffrey Clark <https://github.com/h0tw1r3/>
# License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
#
set -o errtrace
error() {
echo "ERROR in $0 : line $1 exit code $2"
exit $2
@h0tw1r3
h0tw1r3 / docker_cleanup_beaker.sh
Created February 21, 2023 21:45
shell function to cleanup beaker docker containers
# clean up all beaker containers and images
# useful when using BEAKER_destroy=no
function docker-cleanup-beaker() {
while read i; do
X=($i)
echo -n "Cleaning up ${X[2]}: stopping container"
docker stop "${X[0]}" >/dev/null
echo -n ", removing container"
docker rm "${X[0]}" >/dev/null
echo -n ", removing images"
@h0tw1r3
h0tw1r3 / rand.rb
Created January 2, 2023 19:13
puppet custom functions
# Return a random number
Puppet::Functions.create_function(:rand) do
# @param [Integer] max
# maximum random number
# @return [Variant[Integer,Float]]
# random number
# @example Calling the function
# rand(10)
dispatch :generate_random_number do
optional_param 'Integer', :max
@h0tw1r3
h0tw1r3 / nessusagent.pp
Last active October 26, 2022 17:35
Deploy nessus agent with Puppet
class nessusagent (
String $agent_key,
Array[String] $agent_groups = ['All'],
String $agent_name = $facts['networking']['hostname'],
String $nessus_host = 'cloud.tenable.com',
Integer $nessus_port = 443,
String $package_name = 'NessusAgent',
Hash $package_params = {
ensure => 'latest',
},