Skip to content

Instantly share code, notes, and snippets.

View optiz0r's full-sized avatar

Ben Roberts optiz0r

View GitHub Profile
@optiz0r
optiz0r / host_certs.tf
Created July 6, 2022 12:59
Terraform code allowing puppet clients to acquire TLS certificates matching their own hostname only
# Allow clients to auth using puppet certificates
resource "vault_auth_backend" "host_certs" {
path = "host_certs"
type = "cert"
}
resource "vault_cert_auth_backend_role" "puppet_certificate" {
name = "puppet_certificate"
backend = vault_auth_backend.host_certs.path
@optiz0r
optiz0r / Choria Playbook: Vault upgrade.md
Last active April 7, 2022 10:58
Upgrades a Hashicorp Vault cluster and clients using Choria

Upgrade Vault Cluster

This Choria Playbook will automate the steps to do a simple version upgrade of a Vault cluster

  • Upgrades follower servers first
  • Upgrades the leader last (to reduce risk of a failover from newer version to older one)
  • Sleeps in between each upgrade to allow operator unseal to be run, and for vault to re-register itself in service discovery
  • Bulk updates all clients

Warning!

# class params
$socket_group=undef
$docker_users=[]
# Override defaults which try to specify which repo to install from
# we install from spacewalk with different reponames, and will just install
# the latest version available
$repo_opt = {}
$dist_specific_opts = {
@optiz0r
optiz0r / Caddyfile.tmpl
Created April 29, 2021 07:35
Caddy with Nomad + Consul
{{- range services -}}
{{- if .Name | contains "sidecar" | not -}}
{{- $groupedServices := (service .Name | byMeta "caddy_enable") -}}
{{- $enabledServices := (index $groupedServices "true" ) -}}
{{- range $enabledServices -}}
{{- $vhost := index .ServiceMeta "caddy_vhost" -}}
{{- scratch.MapSetX "vhosts" $vhost . -}}
{{- end -}}
{{- end -}}
{{- end -}}
_choria_bash_autocomplete() {
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if ( _array_contains COMP_WORDS "req" || _array_contains COMP_WORDS "rpc" ) && [[ ${COMP_WORDS[$COMP_CWORD]} != "-"* ]] ; then
_choria_req_bash_autocomplete
else
opts=$( ${COMP_WORDS[0]} --completion-bash ${COMP_WORDS[@]:1:$COMP_CWORD} )
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
@optiz0r
optiz0r / README.md
Created December 14, 2020 08:35
Choria Playbook to upgrade a nomad cluster

Upgrade Nomad cluster

This Choria Playbook will automate the steps to do a simple version upgrade on a nomad cluster.

  • Upgrades servers first
  • Then upgrades clients
  • Sleeps in between each upgrade to allow things to settle
  • Aborts on any error

Dependencies

@optiz0r
optiz0r / nomad.pp
Created April 20, 2020 16:52
puppet code for deploying nomad as a docker container
# == Class: sihnon::nomad
#
# Deploys nomad in docker
#
class sihnon::nomad (
String $image_name = 'optiz0r/nomad',
String $image_tag = '0.11.0-beta2',
String $root_dir = '/srv/nomad',
String $cert_name = $::fqdn,
Array[Stdlib::Host] $servers = [
@optiz0r
optiz0r / puppet_env.ddl
Last active September 18, 2019 21:43
puppet_env
metadata :name => "puppet_env",
:description => "Triggers updates of puppetserver environments using puppet-env-manager library",
:author => "Ben Roberts",
:license => "Apache-2.0",
:version => "0.1",
:url => "https://github.com/optiz0r/puppet-env-manager-agent",
:provider => "external",
:timeout => 900
@optiz0r
optiz0r / 01-bacula-zfs-send.sh
Created May 1, 2017 20:21
Simple bacula ZFS/bpipe fileset and wrapper scripts
#!/bin/sh
#
# A script which does everything bacula bpipe needs ie:
# - create a snapshot with the current date / time
# - do a zfs send out of that snapshot
# - clean up snapshot when complete
#
FILESYSTEM=$1
# == Class: site::letsencrypt
#
class site::letsencrypt (
$tsig_name,
) {
if hiera('letsencrypt::letsencrypt_host') == $::fqdn {
class {
'::letsencrypt':
hook_content => template('site/etc/dehydrated/dehydrated_nsupdate.sh.erb'),
letsencrypt_contact_email => '[email protected]',