Skip to content

Instantly share code, notes, and snippets.

@zircote
zircote / ec2_facts.py
Created April 2, 2014 21:08
provides object instance of iam credentials
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@zircote
zircote / ip2long.py
Last active August 29, 2015 13:57
ansible filters
# !/usr/bin/env python
"""
Example Usage:
---
- debug: msg="{{ ansible_eth0.ipv4.address | ip2long }}"
"""
from socket import inet_aton
from struct import unpack
@zircote
zircote / ct2ls.py
Last active June 23, 2016 01:41
A script to manage and import CloudTrail logs into logstash via redis
#!/usr/bin/env python
import boto
from boto.sqs.message import RawMessage
import tempfile
import json
import logging
import argparse
import gzip
import redis
@zircote
zircote / aws-cli.debug
Created March 12, 2014 23:07
aws fails to return instances when filtering on security group-id
$ aws ec2 describe-instances --filter file://filters/elasticsearch.json --debug
2014-03-12 18:01:59,468 - awscli.clidriver - DEBUG - CLI version: aws-cli/1.3.1 Python/2.7.6 Darwin/13.1.0, botocore version: 0.35.0
2014-03-12 18:01:59,468 - botocore.service - DEBUG - Creating service object for: ec2
2014-03-12 18:01:59,468 - botocore.base - DEBUG - Attempting to load: aws/ec2
2014-03-12 18:01:59,536 - botocore.base - DEBUG - Found data file: /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/botocore/data/aws/ec2.json
2014-03-12 18:01:59,536 - botocore.hooks - DEBUG - Event service-data-loaded.ec2: calling handler <function signature_overrides at 0x10bc81a28>
2014-03-12 18:01:59,536 - botocore.hooks - DEBUG - Event service-created: calling handler <function register_retries_for_service at 0x10bc81848>
2014-03-12 18:01:59,536 - botocore.handlers - DEBUG - Registering retry handlers for service: Service(ec2)
2014-03-12 18:01:59,536 - botocore.service - DEBUG - Crea
@zircote
zircote / init_ansible_role.sh
Last active January 8, 2020 04:54
bash function to create a boilerplate ansible role (I am lazy)
#!/bin/sh
function init_ansible_role {
if [[ ! -n $1 ]]; then
echo no init
return
fi
mkdir -p roles/${1}/{defaults,tasks,files,templates,vars,handlers,meta}
for i in defaults tasks vars handlers meta; do
if [[ ! -f roles/${1}/${i}/main.yaml ]]; then
echo creating file: roles/${1}/${i}/main.yaml
@zircote
zircote / Time Intervals.md
Last active January 1, 2016 13:29
Explanation of time interval definition.

Duration Data Type

The duration data type is used to specify a time interval. The time interval is specified in the following form "PnYnMnDTnHnMnS" where:

  • P indicates the period (required)
  • nY indicates the number of years
  • nM indicates the number of months
  • nD indicates the number of days
  • T indicates the start of a time section (required if you are going to specify hours, minutes, or seconds)
  • nH indicates the number of hours
@zircote
zircote / com.zircote.headlessvm.plist
Created December 23, 2013 21:13
vmware fusion headless vm
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.zircote.headlessvm</string>
#! /usr/bin/env python
"""
see: http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html
ec2-describe.py --filter tag:ACCT_ROLE=DEVELOPMENT --format report
ec2-describe.py --filter tag:ACCT_ROLE=OPERATIONS --format report
ec2-describe.py --filter instance-type=m1.small --format report
"""
import argparse
import os
@zircote
zircote / direct_queue_routed_delay.php
Last active December 31, 2015 01:59
Rhubarb 3.2-dev use examples
<?php
/**
*
* @license http://www.apache.org/licenses/LICENSE-2.0
* Copyright [2013] [Robert Allen]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@zircote
zircote / monitor.py
Last active March 6, 2022 22:05
AWS/Celery Monitor
from boto.ec2.cloudwatch import CloudWatchConnection
from datetime import datetime
from main.settings import AWS_CREDENTIALS, CLOUDWATCH_NAMESPACE
def monitor(app):
cloudwatch = CloudWatchConnection(**AWS_CREDENTIALS)
state = app.events.State()
def get_task(event):