Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
@amosshapira
amosshapira / vpcs.yaml
Created July 16, 2016 21:14
Example for VPC + VPN configuration in yaml files
# This file describes all subnets on our WAN. The name 'vpc' is a bit
# misleading since it also refers to non-VPC subnets (e.g. office network,
# physical data centre etc.)
# and also defines the IPSec tunnels between the various locations.
# For the sake of this document, "VPC" is used to refer to any location.
#
# VPC's are configured by a separate stack template than the IPSec tunnels,
# but both template types read this file to know what to do.
#
# The rule is that each VPC can have EITHER incoming OR outgoing
@amosshapira
amosshapira / gist:2ec6ca21ff9ed6733e0f96fc85d65f14
Created July 4, 2016 02:48
Lock OSX screen from command line, goes to User Switch screen
# Source: http://osxdaily.com/2012/03/30/lock-mac-desktop-command-line/
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
@amosshapira
amosshapira / get-all-azs
Created June 29, 2016 00:44
List all AZ's in all AWS regions
#!/bin/bash
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text | \
tr '\t' '\n' | \
while read REGION
do
aws ec2 describe-availability-zones --region $REGION \
--query 'AvailabilityZones[*].{ZoneName:ZoneName,Region:RegionName}' \
--output text
done
@amosshapira
amosshapira / jenkins-plugins-puppet.sh
Last active February 2, 2017 12:48
Extract list of current plugins from Jenkins and convert them into a Puppet hash with versions, suitable to feed to "plugin_hash" parameter of "rtyler-jenkins" Puppet class
# aligns the '=>' to be accepted by our puppet-lint. The indentation is very
# specific to our source so will have to be adjusted to other files.
# The "29" in the awk printf is the length of the longest plugin name, so all
# other entries are aligned with it. You can get it using "wc -c <<<(longest-plugin-name)"
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar \
-s http://localhost list-plugins | \
tr -d '()' | \ # get rid of versions in parenthesis, perhaps available upgrades
sort | \
awk '{ printf " \047%s\047%*s=> {\n version => \047%s\047,\n },\n", $1, 29-length($1), "", $NF }'
@amosshapira
amosshapira / tmpfsroot-el6.sh
Created June 20, 2016 20:14 — forked from lorengordon/tmpfsroot-el6.sh
Create AWS AMIs from Scratch
#!/bin/bash
#
# Pivot the root partition to a tmpfs mount point so that the root volume can
# be re-partitioned.
#
##############################################################################
set -x
set -e
# Prevent selinux from interfering
@amosshapira
amosshapira / aws-bootstrap-puppetmaster
Created May 11, 2016 12:24 — forked from gehel/aws-bootstrap-puppetmaster
Bootstrap a puppet master on AWS
#!/bin/sh
# create custom fact to identify the role of this server
mkdir -p /etc/facter/facts.d/
echo "server_role=puppetmaster" >> /etc/facter/facts.d/server_role.txt
# make sure everything is up to date
wget http://apt.puppetlabs.com/puppetlabs-release-raring.deb
dpkg -i puppetlabs-release-raring.deb
apt-get update
@amosshapira
amosshapira / treeps
Created March 30, 2016 01:50
"pstree" simulation for OS X - from http://apple.stackexchange.com/a/137355/56031
#!/usr/bin/perl
# treeps -- show ps(1) as process hierarchy -- v1.0 [email protected] 07/08/14
my %p; # Global array of pid info
sub PrintLineage($$) { # Print proc lineage
my ($pid, $indent) = @_;
printf("%s |_ %-8d %s\n", $indent, $pid, $p{$pid}{cmd}); # print
foreach my $kpid (sort {$a<=>$b} @{ $p{$pid}{kids} } ) { # loop thru kids
PrintLineage($kpid, " $indent"); # Recurse into kids
}
}
@amosshapira
amosshapira / packer-issue-template.json
Created March 21, 2016 23:14
minimal packer template to demonstrate problem getting guest ip on bridged vmware network
{
"builders": [
{
"boot_wait": "2s",
"disk_size": 40960,
"guest_os_type": "darwin12-64",
"iso_checksum_type": "none",
"iso_url": "{{user `iso_url`}}",
"shutdown_command": "echo '{{user `username`}}'|sudo -S shutdown -h now",
"skip_compaction": false,
import os.path
import sys
import yaml
import json
import importlib
import getopt
from troposphere import Template
sys.path.append(os.path.dirname(os.path.realpath(__file__ + "/..")))
development:
adapter: mysql2
encoding: utf8
database: my_database
username: root
roles:
- admin
- developer
- guest
password: