Skip to content

Instantly share code, notes, and snippets.

View DrPsychick's full-sized avatar
🤔

DrPsychick DrPsychick

🤔
View GitHub Profile
@DrPsychick
DrPsychick / gist:12cbee2b36c82ef8441ef00af47fcadf
Last active September 2, 2018 01:24
ansible dict filter with attribute name same as built-in method
# 'values' is a built-in method and therefore always exists. This is especially useful for "influxDB" API output from an uri command.
# test attribute type with selectattr('fieldname', TEST), see http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-tests
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |selectattr('values', 'string') |map(attribute='values') |list }}"
# alternatively filter:
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |rejectattr('values', 'callable') |map(attribute='values') |list }}"
@DrPsychick
DrPsychick / gist:4a1faa089c4bda04f1365adfdd599bac
Created September 2, 2018 13:52
nested dict with lists filtering example
"ansible_influx_mm_backfill.results|map(attribute='json.results')|flatten|map(attribute='series')|flatten|list": [
{
"columns": [
"time",
"written"
],
"name": "result",
"values": [
[
"1970-01-01T00:00:00Z",
@DrPsychick
DrPsychick / macOS-remote-environment.md
Last active May 9, 2024 18:36
macOS / OSX ansible path test

INFO

  • remote SSH shell on macOS does not use /etc/paths
  • this is not an issue of ansible, it is the way macOS processes config files on remote shells:
  • see ssh localhost echo \$PATH

ANSIBLE executes remote shell /bin/sh

  • ...if not specified otherwise and macOS does not read any startup files
  • example: [...]localhost '/bin/sh -c '"'"'sudo -H -S -n -u test /bin/sh -c '"'"'"'"'"[...]
  • even /bin/bash does not read any startup files by default
@DrPsychick
DrPsychick / compile-travis.yml.md
Last active February 2, 2019 23:43
compile .travis.yml into script to test locally
@DrPsychick
DrPsychick / git-auto-checksheet.md
Last active August 4, 2022 07:46
git commands for automation

create or update a version branch from master

# make sure to have your origin set correctly
# git remote set-url origin "[email protected]:DrPsychick/docker-telegraf.git"

branch="testbranch"
# checkout master from origin, skip if you already have a fresh checkout!
@DrPsychick
DrPsychick / Dockerfile
Created March 18, 2020 23:03
extend pdflatex docker image
FROM drpsychick/texlive-pdflatex:latest
RUN tlmgr update --self && \
tlmgr install collection-latexextra \
utopia
@DrPsychick
DrPsychick / medium-demo.sh
Last active April 27, 2020 21:34
airprint-bridge playground
# start a container to play with it
docker run -d --rm -e CUPS_WEBINTERFACE="yes" -e CUPS_REMOTE_ADMIN="yes" \
--hostname mycups --name cups-setup drpsychick/airprint-bridge
# you can search for local printers via the web interface
IP=$(docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress }}' cups-setup)
echo "http://$IP:631"
# you can open a shell to explore printers via `lpinfo`, `lpadmin`, `lpoptions`
docker exec -it cups-setup lpinfo --make-and-model "Epson Stylus Photo RX" -m
@DrPsychick
DrPsychick / cups.env
Last active April 20, 2020 22:09
airprint-bridge environment
CUPS_ADMIN_USER=admin
CUPS_ADMIN_PASSWORD=admin
CUPS_REMOTE_ADMIN=yes
CUPS_WEBINTERFACE=yes
CUPS_SHARE_PRINTERS=yes
CUPS_ACCESS_LOGLEVEL=access
CUPS_LOGLEVEL=info
CUPS_LPADMIN_PRINTER1=lpadmin -p Epson-RX520 -D 'Epson RX520' -m 'gutenprint.5.3://escp2-rx620/expert' -o PageSize=A4 -v smb://user:pass@host/Epson-RX520
CUPS_LPADMIN_PRINTER1_ENABLE=cupsenable Epson-RX520
@DrPsychick
DrPsychick / cups-cert.sh
Created May 2, 2020 10:08
Signed SSL certificate with Root CA
# generate a root CA (which will be your master certificate)
openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 \
-keyout RootCA.key -out RootCA.pem \
-subj "/C=DE/CN=Root CA for .mydomain"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt
# import the cert as trusted on macOS
sudo security add-trusted-cert -d -r trustRoot \
-k /Library/Keychains/System.keychain RootCA.crt
@DrPsychick
DrPsychick / ascii-art.py
Last active May 2, 2020 21:02
Medium code
import sys
import os
import fortune
from pyfiglet import Figlet
def main():
f = Figlet()
# take text from command line or env
text = " ".join(sys.argv[1:])
if (text == ""):