Skip to content

Instantly share code, notes, and snippets.

@pwalkr
pwalkr / eeval.sh
Last active July 23, 2022 17:13
Echo-evaluate individual commands
#!/bin/sh
eeval () {
set -x
"$@"
{ set +x; } 2>/dev/null
}
# Print command and evaluate
eeval touch file
@pwalkr
pwalkr / statement_balance.py
Last active April 1, 2022 01:55
Get a report of statement balances (sorted by oldest, needs-attention, last)
#!/usr/bin/env python3
import argparse
from beancount import loader
from beancount.core.data import Balance, Open, Close
class Report:
def __init__(self):
self.accounts = {}
@pwalkr
pwalkr / vars_lib.groovy
Created June 2, 2022 20:30
Jenkins - get list of parameters from internal memory
static def getBuildParameters(currentBuild) {
def project = currentBuild.getRawBuild().getParent()
def params = null
// Find or create parameters object
for (e in project.properties) {
if (e.value instanceof ParametersDefinitionProperty) {
params = e.value
break
}
@pwalkr
pwalkr / ansible_install_containerd.yml
Last active June 4, 2022 01:17
Ansible tasks to install containerd
# Input:
# containerd_version: 1.6.4
- name: download containerd
ansible.builtin.unarchive:
src: 'https://github.com/containerd/containerd/releases/download/v{{ containerd_version }}/containerd-{{ containerd_version }}-linux-{{ a[ansible_distribution].tar.gz'
dest: '/usr/local'
remote_src: yes
vars:
# Translate ansible_architecture to containerd arch
@pwalkr
pwalkr / ansible_pve_lxc_playbook.yml
Created June 4, 2022 12:21
Ansible playbook to bring up an LXC container on a Proxmox node
# Inputs:
# proxmox_host # ansible host running proxmox. Is also destination node: for container
# proxmox_user
# proxmox_pass
# vmid # ID for lxc instance in proxmox
# admin_ssh_keys # SSH keys to install for passwordless login
---
- hosts: lxc_guests
vars:
@pwalkr
pwalkr / jenkinsAbortOnIndexTrigger.groovy
Created June 9, 2022 14:53
Abort build on indexing trigger
import hudson.model.Result
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
// Callable as a step, defined in vars/
void call() {
if (this.isBranchIndexingCause()) {
echo "ABORTED: $message"
throw new FlowInterruptedException(Result.NOT_BUILT)
}
}
@pwalkr
pwalkr / swarm_promote.yml
Last active July 23, 2022 18:02
Docker swarm promotion based on inventory group membership
---
- hosts: swarm_manager
gather_facts: no
tasks:
- name: run pre-flight checks
fail:
msg: '{{ checks[item].message }}'
register: r
# abort after first failure - https://medium.com/opsops/how-to-break-from-the-loop-in-ansible-1e8ebb92be0d
when: not (r.failed|d(false)) and checks[item].condition
@pwalkr
pwalkr / ansible_vault_helper.sh
Created July 23, 2022 17:33
Ansible shell snippet to have ansible load a vault password from environment
#!/bin/sh
# If not set, tell the user what variable we're looking for.
if [ -z "$SOMETHING" ]; then
echo "Missing vault pass. Set:"
echo " export SOMETHING='SECRET'"
exit
fi
# Ansible checks this variable for executable or password as text.
@pwalkr
pwalkr / ansible_docker_build_tag.yaml
Last active July 24, 2022 02:33
Build docker container with dynamic tag
# This step generates an image tag based on git tree hash of the source folder so
# the tag changes whenever your source changes and will trigger new builds/pulls.
# If the image is tracking an upstream app, I'll add a "{{ base_tag }}-" prefix
# so I get a new image if the source version changes but my wrapper does not.
# This can be hidden in vars/main.yml to avoid a dedicated step
- set_fact:
# Extracted for shorter lines - this command assumes the parent directory to
# roles/ is the root of a git repository.
get_tag_cmd: git rev-parse HEAD:roles/myapp/files/docker
@pwalkr
pwalkr / error.md
Created December 9, 2022 02:59
Foreground ansible docker_container times out

Error

TASK [backup to backblaze] ********************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: requests.exceptions.ConnectionError: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out.
fatal: [cirrus]: FAILED! => {"changed": false, "msg": "An unexpected requests error occurred when trying to talk to the Docker daemon: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out."}

Source