Skip to content

Instantly share code, notes, and snippets.

Avatar

David Wittman DavidWittman

View GitHub Profile
@DavidWittman
DavidWittman / audit_iam_accounts.py
Created Apr 14, 2016
Parses the output from AWS credential reports and displays users which have been inactive for 60+ days.
View audit_iam_accounts.py
#!/usr/bin/env python
# Parses the output from AWS credential reports and displays
# users which have been inactive for 60+ days.
#
# Usage:
# audit_iam_accounts.py credential_report.csv <days>
#
import csv
View supermicro-mount-iso.sh
#!/usr/bin/env bash
# Loads and mounts an ISO over SMB via the
# SuperMicro IPMI web interface
#
# usage: supermicro-mount-iso.sh <ipmi-host> <smb-host> <path>
# e.g.: supermicro-mount-iso.sh 10.0.0.1 10.0.0.2 '\foo\bar\windows.iso'
set -x
@DavidWittman
DavidWittman / supermicro-ipmi-mac-address.md
Last active May 13, 2021
Pull the LAN1/eth0 MAC address from SuperMicro IPMI
View supermicro-ipmi-mac-address.md

You can find the MAC address for LAN1/eth0 (not the BMC MAC) via the SuperMicro IPMI interface by running the following command:

$ ipmitool -U $IPMI_USER -P $IPMI_PASS -H $IPMI_HOST raw 0x30 0x21 | tail -c 18

The eth0 MAC address will be output in this format:

00 25 90 f0 be ef
@DavidWittman
DavidWittman / vlan-check.sh
Last active Apr 3, 2021
Validates the VLAN configuration on an interface by creating a tagged subinterface, assigning the next available address, and sending a ping to the provided gateway IP address.
View vlan-check.sh
#!/usr/bin/env bash
# vlan-check.sh
#
# Validates the VLAN configuration on an interface
# by creating a tagged subinterface, assigning the
# next available address, and sending a ping to the
# provided gateway IP address.
#
# Supports Ubuntu and RHEL/CentOS. I think.
@DavidWittman
DavidWittman / mongo-ansible.py
Last active Apr 3, 2021
MongoDB-backed dynamic inventory script for Ansible
View mongo-ansible.py
#!/usr/bin/env python
#
# MongoDB-backed dynamic inventory script for Ansible
# http://docs.ansible.com/intro_dynamic_inventory.html
import os
from argparse import ArgumentParser
import pymongo
@DavidWittman
DavidWittman / check_peer_interfaces.py
Last active Apr 3, 2021
Checks to see if two interfaces are on the same network on Linux. Useful when bonding interfaces.
View check_peer_interfaces.py
#!/usr/bin/env python
# check_peer_interfaces.py
# Author: David Wittman <david@wittman.com>
#
# Checks to see if two interfaces are on the same network by sending a
# unique broadcast packet out of the first interface and listening for that
# packet on the second interface.
#
# Assumes that you're running a Linux variant, and that both interfaces
@DavidWittman
DavidWittman / ansible-dynamic-inventory-converter.py
Created Apr 12, 2016
Script for converting Ansible dynamic inventory to static files. It's not perfect, but it'll get you 90% of the way there.
View ansible-dynamic-inventory-converter.py
#!/usr/bin/env python
# Converts Ansible dynamic inventory sources to static files
# Input is received via stdin from the dynamic inventory file
# ex:
# ec2.py --list | ansible-dynamic-inventory-converter.py
import json
import os
import sys
@DavidWittman
DavidWittman / merge-s3-parts.sh
Created Dec 23, 2015
Script to merge .part files from Amazon S3
View merge-s3-parts.sh
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Merge matching *.part files in a directory"
echo
echo "usage: $0 <directory>"
exit 1
fi
DIRECTORY="$1"
View iptables-nat.md

iptables n'at

Source NAT

Source NAT changes the source address in IP header of a packet. It may also change the source port in the TCP/UDP headers. The typical usage is to change the a private (rfc1918) address/port into a public address/port for packets leaving your network. Available only in the POSTROUTING chain in iptables.

Syntax

iptables -t nat -A POSTROUTING -i eth1 -j SNAT --to-source 1.2.3.4[:port]

Example

@DavidWittman
DavidWittman / notes.md
Created Feb 22, 2012
A Brief Introduction to Fabric
View notes.md

A Brief Introduction to Fabric

Fabric is a deployment management framework written in Python which makes remotely managing multiple servers incredibly easy. If you've ever had to issue a change to a group servers, this should look pretty familiar:

for s in $(cat servers.txt); do ssh $s service httpd graceful; done

Fabric improves on this process by providing a suite of functions to run commands on the servers, as well as a number of other features which just aren't possible in a simple for loop. While a working knowledge of Python is helpful when using Fabric, it certainly isn't necessary. This tutorial will cover the steps necessary to get started with the framework and introduce how it can be used to improve on administering groups of servers.