Skip to content

Instantly share code, notes, and snippets.

View filipenf's full-sized avatar
:shipit:

Filipe Felisbino filipenf

:shipit:
  • Udemy
  • Orlando, FL
  • 01:44 (UTC -04:00)
View GitHub Profile
@filipenf
filipenf / update_route.py
Created June 27, 2016 18:21
Updates route53 records to match the instances on autoscaling group
#!/usr/bin/env python
# Registers all instance IPs as weighted records on route53 ( and deletes the ones that aren't part of the ASG anymore )
# Example 1: will create/update/delete records for the "myservice.example.com" with currently registered ASG instances
# ./update_route53.py from_asg "my-asg" "myservice" "example.com"
# Example 2: will create/update/delete records to match the specified list of ips
# ./update_route53.py sync_records my-asg myservice example.com -i 200.200.200.201 200.200.200.202
import argh
import boto
import boto.route53
function retry-ssh() {
ssh $@
while [ $? -ne 0 ]; do
sleep 3;
ssh $@;
done
}
function ansiblify() {
echo $1 | tr '.-' '_'
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: "Create project VPC"
ec2_vpc:
state: present
region: "{{ project_region }}"
@filipenf
filipenf / ec2.coffee
Created January 29, 2016 19:53
Simple hubot script to get information about an instance
util = require 'util'
init_aws = () ->
aws = require 'aws-sdk'
return aws
module.exports = (robot) ->
robot.respond /ec2 get-instance (.*)$/i, (msg) ->
ins_id = msg.match[1].trim()
if ins_id.match /i-.*/
@filipenf
filipenf / ansible_nested.yml
Created January 20, 2016 12:48
Ansible with_nested example
---
- hosts: localhost
connection: local
vars:
all_networks:
- 10.80.128.0/20
- 10.80.144.0/20
- 10.80.208.0/20
- 10.10.5.0/24
#!/usr/bin/env python
#quick and dirty script to find any untagged and detached volumes,
#take a snapshot and delete it.
import json
import boto3
def get_detached_untagged_volumes(ec2_conn):
volumes = ec2_conn.describe_volumes()
return [ volume['VolumeId'] for volume in volumes['Volumes']
if (len(volume['Attachments'])==0 and
@filipenf
filipenf / flatten_list.py
Created December 4, 2015 12:01
Ansible's filter that receives a list of dicts and merges all of them in one single dict
# Receives a list of dicts and merges all
# sub-dicts into one
def flatten_list(l):
result = {}
for item in l:
result.update(item)
return result
class FilterModule(object):
@filipenf
filipenf / aws_saml_access.py
Last active July 7, 2021 05:39
Script to authenticate with SAML and write the security token to aws credentials file
#!/usr/bin/env python
"""
Prerequisites:
- keyring ( optional )
- argh
- beautifulsoup4
- requests-ntlm
This scripts authenticates you to your SAML provider and writes the
@filipenf
filipenf / aws-s3-buckets-with-tags.sh
Created April 22, 2015 18:46
Print a list of aws buckets along with their tags
#!/bin/bash
# lists all buckets along with their tags in the following format:
# bucket_name | { tag_name: tag_value }
# depends on AWS CLI and JQ
for bucket in `aws s3api list-buckets | jq .Buckets[].Name | tr -d \"`; do
tags=$(aws s3api get-bucket-tagging --bucket $bucket | jq -c '.[][] | {(.Key): .Value}' | tr '\n' '\t')
echo $bucket '|' $tags
done
@filipenf
filipenf / fullscreen-rotating-browser.py
Created April 20, 2015 13:59
A full screen webkit browser that rotates between URLs
#!/usr/bin/env python
import sys
import gobject
import gtk
import webkit
from itertools import cycle
class WebBrowser(gtk.Window):