Skip to content

Instantly share code, notes, and snippets.

@kevduggan
kevduggan / gist:3942f5f405e4f49380fb
Created January 13, 2016 14:29
route to docker-machine container network (from mac)
#!/bin/bash
# Script to instruct the Mac how to route packets to the
# software defined network where containers created via docker machine
# reside. This lets you casually directly to ports (ssh, http, etc. etc.)
# on those containers.
if [ -z "$1" ]; then
echo "Please supply the name of the docker-machine VM${NC}"
exit 1
fi
@kevduggan
kevduggan / map_host_vars.yml
Created January 5, 2016 16:25
maps ec2 facts to host vars
#
# maps the hostvars from ec2 tags in the dynamic inventory to the var names expected by our roles
# this allows us to have no host var files and alsonot have host specific vars in the group_vars files as these are only evaluated in the scope
# of the current host the play is being applied to i.e. all host dont have a seperate copy of all the facts.
# this leads to a dangerous situation when using jinja2 loops over nodes in groups and then accessing hostvars
# (that have been set in the groupvars) for that node
#
- hosts: all
tasks:
@kevduggan
kevduggan / inventory
Last active January 14, 2016 13:18
merge dynamic ec2 and static inventory
#
# Map the ec2 groups (from the dynamic inventory ec2.py) to our groups.
# This merges the static and dynamic inventory.
#
# Placeholders for the dynamic ec2 groups must be added to the static inventory.
# You can then use them throughout the rest of the inventory
[tag_kafka_yes]
# map all dynamic instances tagged with 'tag_kafka_yes' into the static kafka group
@kevduggan
kevduggan / zookeeper.yml
Last active January 14, 2016 12:38
example of a group vars file for provisioning a zookeeper host where the GROUP_TAG fact is populate by a generated zookeeper_servier_id
# must be between 1 and 255
ZOOKEEPER_SERVER_ID: "{% set zk_id = groups['zookeeper'].index(inventory_hostname)+1 %}{{ zk_id }}"
ZK_PORT: 2181
# must have preceeding comma as it is being appended onto the tags list!!
GROUP_TAGS: ",'zookeeper_server_id': {{ ZOOKEEPER_SERVER_ID }}"
@kevduggan
kevduggan / inventory
Last active January 14, 2016 13:17
dummy inventory for creating ec2 instances
# dummy inventory for provisioning blank zookeeper, kafka and kubenetes instances
[zookeeper]
zookeeper-0[1:3]
[kafka]
kafka-0[1:3]
[kubernetes]
kube-master-01
kube-minion-01
- hosts: all # run for all hosts in the inventory
connection: local # ec2 module runs locally, no need to connect to a non existant host!
gather_facts: False
vars:
# build up dictionary of tags so we can use them as facts in the dynamic inventory when configuring the instances
TAGS: "{'env': 'Test', 'Name': '{{ inventory_hostname }}', {% for group in group_names %}'{{ group }}':'yes'{% if not loop.last %},{% endif %}{% endfor %}{{ GROUP_TAGS | default() }} }"
tasks:
- name: Provision an instance {{ inventory_hostname }}
ec2:
@kevduggan
kevduggan / EstimatePiSparkApp.scala
Last active June 14, 2018 14:15
An example Ansible playbook that validates a Spark cluster (including source for test Spark App)
package com.newsweaver.spark.test
import org.apache.spark.{SparkConf, SparkContext}
/**
* simple Spark app to calculate Pi
*/
object EstimatePiSparkApp {
def main(args: Array[String]) {