Skip to content

Instantly share code, notes, and snippets.

@ouyi
ouyi / ansible-decrypt-vaulted-string.sh
Created Jan 30, 2019
Ansible decrypt vaulted strings
View ansible-decrypt-vaulted-string.sh
ansible --vault-password-file my-vault-password.txt -m debug -a 'var=my_secret_password' \
-i my_inventory my_host.mydomain.com
@ouyi
ouyi / docker_run_gui.sh
Created Jan 26, 2019
Run a Docker container with GUI support
View docker_run_gui.sh
#!/usr/bin/env bash
USAGE="$0 args"
if (( $# == 0 )); then
echo "$USAGE"
exit 1
fi
function get_ip() {
@ouyi
ouyi / ansible-list-hosts.sh
Created Jan 26, 2019
Ansible list hosts from a host group
View ansible-list-hosts.sh
#!/usr/bin/env bash
if (( $# < 2 )); then
echo "Usage: $0 inventory host_group [other ansible options]"
exit 1
fi
inventory="$1"
host_group="$2"
@ouyi
ouyi / minikube-sierra.md
Created Dec 4, 2018 — forked from inadarei/minikube-sierra.md
Minikube Setup: Docker for Mac / Sierra
View minikube-sierra.md

Prerequisite: latest Docker for Mac on MacOS Sierra

$ brew update
$ brew install --HEAD xhyve
$ brew install docker-machine-driver-xhyve
$ sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
$ sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.18.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
@ouyi
ouyi / copy_reinvented.sh
Last active Nov 29, 2018
Bash boilerplate code for parsing command-line args
View copy_reinvented.sh
#/usr/bin/env bash
#set -euo pipefail
EXIT_SUCCESS=0
EXIT_FAILURE=1
IFS='' read -r -d '' USAGE <<HEREDOC
Copy-reinvented to showcase Bash heredoc usage and command-line arguments handling.
@ouyi
ouyi / bash_parameter_expansion.txt
Last active Oct 20, 2018
Bash parameter expansion
View bash_parameter_expansion.txt
## Indirect expansion
# aax="x"
# aay="y"
# var_name="aax"
# echo ${!var_name}
x
# var_name="aay"
@ouyi
ouyi / jinja2_file_less.py
Created Sep 7, 2018 — forked from wrunk/jinja2_file_less.py
python jinja2 examples
View jinja2_file_less.py
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#
@ouyi
ouyi / daterange.py
Last active Oct 4, 2018
A command-line tool to work with dates
View daterange.py
#/usr/bin/env python
import sys, argparse, pytz
from datetime import datetime, timedelta
DEFAULT_DATETIME_FORMAT = '%Y%m%d'
SECONDS_IN_A_DAY = 3600 * 24
def main():
parser = argparse.ArgumentParser(description='A command-line tool to work with dates')
@ouyi
ouyi / setup_openvpn.sh
Last active Jul 24, 2018
Setting up OpenVPN with Docker in a public cloud
View setup_openvpn.sh
# Install docker
yum check-update
curl -fsSL https://get.docker.com/ | sh
systemctl start docker
systemctl status docker
systemctl enable docker
systemctl status docker
# Set up the server-side of things
@ouyi
ouyi / s2s_copy.sh
Last active Jul 18, 2018
Server-to-server file copying
View s2s_copy.sh
#/usr/bin/env bash
set -euo pipefail
src_host="$1"
src_path="$2"
dst_host="$3"
dst_path="$4"
pattern="${5:-*}"