Skip to content

Instantly share code, notes, and snippets.

Avatar
🕳️
🌑

Dirk Avery YakDriver

🕳️
🌑
View GitHub Profile
@YakDriver
YakDriver / shell_try_catch.sh
Created Feb 14, 2018
Bash Basics: A Robust try/catch/finally for shell scripts
View shell_try_catch.sh
#!/bin/bash
# This script uses traps to create try/catch/finally functionality in shell scripts.
#
# OUTPUT:
#
# Hello! We're reporting live from script
# ./try_catch2.sh: line 23: badcommand: command not found
# ./try_catch2.sh: line 23: exiting with status 127
# It's the end of the line
@YakDriver
YakDriver / sg.sh
Created Feb 22, 2018
Manage security groups (shell script) from AWS CLI
View sg.sh
#!/bin/bash
# Errors are thrown if Terraform is given the name of an existing security group.
# One solution is to find the existing security group and delete it. (That will fail if any instances are associated.)
# This installs jq, finds security group id, deletes security group.
#
security_group_name=your_sg
# 1. Install jq
curl -L "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" -o jq.dms && chmod +x jq.dms
@YakDriver
YakDriver / gen_key.sh
Last active Feb 22, 2018
Generate keys
View gen_key.sh
#!/bin/bash
org=$1
name=${2:-$USER}
echo "Usage: $0 [organization] [name]"
create_date=$(date +'%Y%m%d')
if [ -n "${org}" ] ; then org="$org " ; fi
@YakDriver
YakDriver / node_from_uuid.sh
Created Feb 22, 2018
Extract node portion of UUID, bash
View node_from_uuid.sh
$uuid = 'some-name-or-urn:8754258d-506d-e094-d51d-e0a0d891fe08' #16 octets, 10-15 are the node
$node = $(echo $uuid | cut -d':' -f 2 | cut -d'-' -f 5)
echo $node
@YakDriver
YakDriver / utc.sh
Last active Mar 1, 2018
Linux/bash to display date in UTC format
View utc.sh
#!/bin/bash
# Many things want UTC time as input, so here it is. As 14 days ago. Like for a query to AWS spot instance history:
# aws ec2 describe-spot-price-history --instance-types t2.micro --start-time $(date -v-14d -u '+%FT%TZ') --product-description "Linux/UNIX"
#
# Output (of command below, not the aws cli command):
# 2018-02-13T15:24:46Z
#
date -v-14d -u '+%FT%TZ'
@YakDriver
YakDriver / nametag.sh
Created Mar 1, 2018
Set the name tag of an AWS instance from the AWS instance (e.g., in userdata)
View nametag.sh
# terraform locals (in a .tf file)
locals {
name_prefix = "terrafirm"
full_build_id = format("notcb:%s", uuid()) #128-bit rfc 4122 v4 UUID
build_id = "${substr(element(split(":",local.full_build_id),1), 0, 8)}${substr(element(split(":",local.full_build_id),1), 9, 4)}"
resource_name = "${local.name_prefix}-${local.build_id}"
}
# terraform template declaration (in a .tf file)
data "template_file" "lx_userdata" {
@YakDriver
YakDriver / building.misc
Created Mar 2, 2018
adventures in RPM builds
View building.misc
pip install --index-url="https://pypi.org/simple" --upgrade virtualenv
sudo yum groupinstall -y development
sudo yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel
sudo yum install xz-libs
wget http://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
xz -d Python-2.7.14.tar.xz
tar -xvf Python-2.7.14.tar
@YakDriver
YakDriver / running-terraform-providers-acceptance-test.txt
Last active Mar 7, 2018
Running acceptance tests for Terraform Providers in go
View running-terraform-providers-acceptance-test.txt
# Hashicorp documentation is a bit out of date so it took a minute to figure this out...
# 1. Install go
https://golang.org/dl/
# 2. Make a go workspace
$ mkdir ~/go # or wherever you want
$ export GOPATH=~/go # could add to .bash_profile
$ export PATH=$GOPATH:$PATH
@YakDriver
YakDriver / userdata.ps1
Created Mar 16, 2018
Userdata PowerShell to set Admin Password
View userdata.ps1
<powershell>
$Admin = [adsi]("WinNT://./Administrator, user")
$Admin.psbase.invoke("SetPassword", "<password>")
</powershell>
View terraform_debug.log
2018-03-22T15:09:41.743Z [DEBUG] plugin.terraform: file-provisioner (internal) 2018/03/22 15:09:41 Uploading file to 'C:\scripts\check_build.ps1'
2018-03-22T15:09:42.378Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 connecting to remote shell using WinRM
2018-03-22T15:09:42.408Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018-03-22T15:09:43.054Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:43 starting remote command: C:/Temp/terraform_1217694552.cmd
2018-03-22T15:10:52.390Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:52 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018/03/22 15:10:53 [DEBUG] plugin: waiting for all plugin processes to complete...
2018-03-22T15:10:53.201Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:53 [ERR] plugin: plugin server: accept unix /tmp/plugin522209802