Skip to content

Instantly share code, notes, and snippets.

@madsonic
madsonic / ansible.sh
Last active August 1, 2019 02:25
ansible tips and tricks
# render template via ansible module
$ ansible all -i "localhost," \
-c local \
-m template \
-a "src=test.txt.j2 dest=./test.txt" \
--extra-vars='{"users": ["Mike", "Smith", "Klara", "Alex"]}'
# render template via playbook
- hosts: 127.0.0.1
tasks:
@madsonic
madsonic / pyenv
Created July 19, 2019 07:32
pyenv virtualenv godforsaken syntax
# create virtual env
pyenv virtualenv <py version> <env name>
pyenv activate <env name>
pyenv deactivate
# list virtual env
pyenv virtualenvs
@madsonic
madsonic / tar
Created July 16, 2019 04:16
compressions
# compress file into gzip
tar --create --gzip --verbose --file <output file path> <input file path>
tar -czvf <output file path> <input file path>
# extract
tar -xzvf <file path>
# gzip option can be changed to use different compression algo
# https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/
@madsonic
madsonic / etc logrotate.d
Last active July 16, 2019 04:17
log rotation
<file glob> {
}
# run logrotate
logrotate --verbose --debug --force <logroate file | logrotate.d/>
# logrotate status
# check for past logrotate actions
/var/lib/logrotate.status
@madsonic
madsonic / encryption decryption
Last active July 16, 2019 02:58
openssl encryption decryption
# encrypt
openssl aes-256-cbc -in <file> -out <file> -md sha1 -base64
# decrypt
openssl aes-256-cbc -d -in <file> -out <file> -md sha1 -base64
@madsonic
madsonic / fingerprint
Created July 16, 2019 02:52
key fingerprint
ssh-keygen -E md5 -lf id_rsa.pub
@madsonic
madsonic / certs creation
Last active July 9, 2019 03:59
self signed cert
# self-signed certificates only provide cryptographic security to HTTPS request
# they do not verify the identity of the server
sudo openssl req -x509 -nodes -newkey rsa:4096 \
-keyout /etc/ssl/<name>.key \
-out /etc/ssl/<name>.crt \
-days <NUMBER_OF_DAYS>
@madsonic
madsonic / service
Last active July 8, 2019 09:57
common systemd service config
[Unit]
StartLimitIntervalSec=60 #length of limit interval
StartLimitBurst=6 #start limit within interval
# i.e. can start 6 times in a span of 60 sec
ConditionPathExists=/etc/foo/foo.conf # only start if this file exists
# see other Condition* directives
[Service]
RestartSec=10 # restart every 10 if restart conditions are met
sudo du -Sh | sort -r -h | head -n 100
@madsonic
madsonic / sed.sh
Created June 25, 2019 03:20
search and replace file content
# mac
sed 's/<target>/<replacement>/g' <inputfile> > <outputfile>
# inplace
sed -i '.bck' 's/<target>/<replacement>/g' <inputfile>
# only if FOO appears in the line
sed 'FOO/s/<target>/<replacement>/g' <inputfile>
# multiple command