Skip to content

Instantly share code, notes, and snippets.

@pwalkr
pwalkr / pwned.sh
Created February 17, 2023 04:05
Check haveIbeenpwned database for a password
#!/bin/sh
if [ -z "$1" ]; then
echo "$0 <password>"
exit
fi
checksum="$(printf '%s' "$1" | sha1sum | awk '{print $1}')"
prefix="$(printf '%.5s' "$checksum")"
suffix="$(printf "$checksum" | sed 's/^.\{5\}//')"
@pwalkr
pwalkr / ansible-docker-swarm-config.yaml
Created February 5, 2023 20:38
Automatic rotation of a docker swarm config using an ansible template
# This set of tasks rotates a swarm config by generating a config name.
# If input contents change, the hash changes, triggering a name change and restart of consuming service(s)
# Tasks should all `run_once` if multiple swarm managers are in play.
- hosts: swarm_manager
tasks:
- set_fact:
config_data: '{{ lookup("template", "templates/my-template.cfg") }}'
- name: create config
@pwalkr
pwalkr / jenkins-extract-file-cred.groovy
Created January 11, 2023 18:22
Extract file credential from Jenkins using script console
import java.nio.charset.StandardCharsets
import org.apache.commons.io.IOUtils
// https://stackoverflow.com/questions/57107486/how-to-read-jenkins-credentials-at-folder-level
def folder = Jenkins.instance.getItems(com.cloudbees.hudson.plugins.folder.Folder).find({
// TODO handle sub-folders as required
it.getFullName() == 'folder-name'
})
@pwalkr
pwalkr / retropie-n64-controller.md
Last active December 18, 2022 23:38
Configuring N64 controller in RetroPie

The controller is easy enough to configure in Emulation Station frontend, but once in a game, the buttons are not correct. A tuned configuration is required for use with mupen64 emulators.

$ dmesg
[194164.863158] usb 1-1: new low-speed USB device number 6 using xhci_hcd
[194165.007396] usb 1-1: New USB device found, idVendor=0079, idProduct=0006, bcdDevice= 1.09
[194165.007420] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[194165.007432] usb 1-1: Product: Generic   USB  Joystick  
[194165.036270] input: Generic USB Joystick as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:0079:0006.0006/input/input28
@pwalkr
pwalkr / ansible-find-exec-docker-swarm.yml
Last active December 11, 2022 17:14
Find (gitlab) container/node in swarm for executing backup via ansible
# Run on a swarm manager node
- name: find container and node
shell: |
set -e
{% raw %}
task_id="$(docker stack ps gitlab --filter desired-state=running --format="{{.ID}}")"
# stdout_lines[0]
docker inspect $task_id --format="{{.Status.ContainerStatus.ContainerID}}"
@pwalkr
pwalkr / error.md
Last active May 31, 2023 21:13
Ansible not detecting locale after system update
ansible --version
ERROR: Ansible requires the locale encoding to be UTF-8; Detected None.

Hacked with explicit assignment of LC_ALL:

LC_ALL=C.UTF-8 ansible --version
ansible [core 2.14.1]
@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

@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 / 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 / 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