Ansible

Always cast non-string variables

See https://moreati.org.uk/blog/2020/07/05/ansible-is-stringly-typed.html

when: (skip_install is not defined) or (not skip_install | bool)
ansible localhost -i <inventory> -m debug -a "var=groups['<group_name>']"

Key/CSR Generation with Vaulting

export F=FQDN
export TLS_BITS=4096
export C=Canada
export ST=Ontario
export L=Toronto
export O=Company
export OU=Dept
export EMAIL=email@company.com

# Generate new key and csr
openssl req \
    -out "host_files/${F}/${F}.csr" \
    -new \
    -newkey rsa:${TLS_BITS} \
    -nodes \
    -keyout "host_vars/${F}/vault_tls_private_key" \
    -subj "/C=${COUNTRY}/ST=${ST}/L=${L}/O=${O}/OU=${OU}/CN=${F}/emailAddress=${EMAIL}"

# indent the key file
sed -i 's/^/\ \ /g' "host_vars/${F}/vault_tls_private_key"

# add YAML header for Ansible variable
sed -i '1s/^/---\ntls_private_key: |\n/' "host_vars/${F}/vault_tls_private_key"

# vault the TLS private key
ansible-vault \
    encrypt \
    "host_vars/${F}/vault_tls_private_key"

Git

Global Ignore File

git config --global core.excludesfile ~/.config/git/gitignore

Pushing to Multiple Repositories

git clone repo1 example
cd example
git remote set-url --add origin repo2

Multi-line Commit Messages From CLI

git commit -m "line 1" -m "line 2"

Limit Clone to Just Master Branch For Performance

When cloning large repositories with many branches, you can isolate the branch you’d like to clone (good for builds) but setting the fetch refspec as follows:

git clone -c remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master repo

Setup GPG Signing

git config --global gpg.program gpg
git config --global commit.gpgsign true
git config --global user.signingkey KEY_ID

HTML

Small/Basic Favicons

From https://news.ycombinator.com/item?id=24111105.

<link rel="icon" href="data:image/gif;base64,R0lGODlhEAAQAAAAACwAAAAAAQABAAACASgAOw==">

Prometheus

Query Core/Thread Counts

count without(cpu, mode) (node_cpu_seconds_total{mode="idle"})

Shell

Bash

Force Command Prompt on New Line

From https://www.vidarholen.net/contents/blog/?p=878.

Some commands don’t properly end their output with \n so your command prompt will be on the middle of the last line of their output. This can be fixed using the following setting.

PROMPT_COMMAND='printf "%%%$((COLUMNS-1))s\\r"'

Loop Over Unique Pairings of Items

set -- item0 item1 item2
for outer; do
    shift
    for inner; do
        echo "${outer}-${inner}"
    done
done

Zsh

Suffix Aliases

Suffix aliases will match file suffixes.

The following opens vscode when you enter any .md filename:

alias -s md=code

The following will run git clone for any .git repository pasted into the command line:

alias -s git="git clone"

Global Aliases

Matches all usage in a line, example:

alias -g G="| grep "
ps ux G foo