Skip to content

Instantly share code, notes, and snippets.

View darkone23's full-sized avatar
💭
💾☠🕸

0/∞ darkone23

💭
💾☠🕸
View GitHub Profile
@darkone23
darkone23 / get_cow.py
Created January 31, 2013 22:21
get a random cow for use in `cowsay -f cow $msg`
#!/usr/bin/env python
import subprocess
from random import randint
COWSAY = "/usr/games/cowsay"
def get_randomth(arr):
return arr[randint(0, len(arr) - 1)]
def get_critters(cowsay):
@darkone23
darkone23 / load-to-graphite.sh
Created July 4, 2013 06:06
send load average to graphite using simple shell utilities
#!/bin/sh
# set up our graphite namespace
graphite_host="localhost"
graphite_port=2003
namespace="system.$(hostname).loadavg"
# get current time and loadavg
time=$(date +'%s')
load=$(cat /proc/loadavg)
@darkone23
darkone23 / net.cljs
Last active May 11, 2021 12:12
websocket as a cljs core.async channel
(ns example.net
(:require [goog.net.WebSocket]
[goog.events :refer (listen)]
[cljs.core.async :as async :refer (chan <! >! put! close)]
[cljs.core.async.impl.protocols :as proto])
(:require-macros [cljs.core.async.macros :refer (go)]))
(defn ws
"WebSocket as a core.async channel
returns a channel which delivers the ws chan then closes"
- hosts: localhost
connection: local
vars:
special: '{{ hostvars[inventory_hostname]["ansible_" + cluster_interface]["ipv4"]["address"] }}'
tasks:
- set_fact: {cluster_interface: eth0}
- name: reading special var
@darkone23
darkone23 / shell.yaml
Created October 6, 2013 19:00
ansible install from compiled
- name: compiling & installing some package
shell: >
creates=/path/to/some/binary
curl somebinary | tar xz && cd /path/to/extracted &&
make &&
make install
# ansible uses jinja templates for variable substitution
# because of this, you are free to use all of jinja anywhere ansible templates
# for example the arguments to modules
- name: pattern or antipattern? you decide
hosts: local
connection: local
vars:
iferate: no
@darkone23
darkone23 / arg_vars.yaml
Last active December 25, 2015 09:09
Storing module arguments in vars
- name: control some app
hosts: localhost
vars:
git_repo: git://example.org/path/to/repo.git
app_home: ~/projects/app
super_args: >
config=~/.virtualenvs/supervisor/conf/supervisord.conf
supervisorctl_path=~/.virtualenvs/supervisor/bin/supervisorctl
# SETUP VARS:
# this assumes this script is in $ANSIBLE_ROOT/scripts/setup-ansible.sh and roles are in $ANSIBLE_ROOT/roles
ANSIBLE_ROOT=$(dirname $(dirname $(readlink -e $0)))
# ANSIBLE_PACKAGE_NAME="ansible" # latest official release
ANSIBLE_PACKAGE_NAME="git+https://github.com/ansible/ansible@devel" # mainline dev branch
function install_ansible() {
echo "Beginning ansible installation.."
sudo su -c "apt-get remove ansible -y; apt-get install python-pip python-virtualenv -y && pip uninstall ansible -y; pip install ${ANSIBLE_PACKAGE_NAME}"
@darkone23
darkone23 / using-working-dir.yaml
Created October 17, 2013 00:28
Ansible searches for files in different places depending on which part of ansible you are using. The `getcwd` role just looks up your current working directory and provides it as the variable 'basedir'. This way, you can do things like this:
- hosts: webservers
vars_files:
- vars/web-archival-config.yaml
roles:
- getcwd
- role: cron-job
frequency: hourly
@darkone23
darkone23 / Vagrantfile
Created October 23, 2013 21:31
Install serf into a vagrant vm, provisioning with ansible
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :serf do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"