Skip to content

Instantly share code, notes, and snippets.

View jriguera's full-sized avatar

José Riguera Lopez jriguera

View GitHub Profile
@jriguera
jriguera / deploy_role.txt
Created July 14, 2015 19:20
How to deploy a single role without create a specific playbook
Create a playbook called deploy_role.yml:
- hosts: {{ hosts }}
roles: {{ roles }}
And then you can do:
ansible-playbook deploy_role.yml -e hosts=somehost -e roles=somerole
@jriguera
jriguera / strace.txt
Last active August 29, 2015 14:26
strace examples
# Examples
# Debug syscalls for a daemon
strace -e poll,select,connect,recvfrom,sendto nc www.news.com 80
# Attach to process and sent to output.txt
strace -c -p 11084 -o output.txt
# Check permissions
strace -e open,read,access ls 2>&1 | grep your-filename
@jriguera
jriguera / opensource.txt
Created August 23, 2015 23:07
Howto opensource a project ... or howto keep your configuration not public
GITHUB_URL = Public repo on GitHub.
BITBUCKET_URL = Private repo on Bitbucket.
Given a upstream repo on GitHub in order to clone it to Bitbucket to keep
the configuration non public (for example, to create specific ansible playbooks
with a set of roles), do this (only once!).
1. Create a new repo on Bitbucket. (BITBUCKET_URL)
2. Clone the upstream repo from Github to your local machine: git clone GITHUB_URL
3. git remote rename origin upstream BITBUCKET_URL
@jriguera
jriguera / ksm.sh
Created November 14, 2015 16:14
KSM
#!/usr/bin/env bash
cat <<EOF
http://www.kernel.org/doc/Documentation/vm/ksm.txt :
The effectiveness of KSM and MADV_MERGEABLE is shown in /sys/kernel/mm/ksm/:
pages_shared - how many shared pages are being used
pages_sharing - how many more sites are sharing them i.e. how much saved
pages_unshared - how many pages unique but repeatedly checked for merging
pages_volatile - how many pages changing too fast to be placed in a tree
@jriguera
jriguera / external_net.sh
Created November 17, 2015 16:02
Defining external networks on OpenStack
# Load the admin credentials
. /root/openrc
# Creating the external network type VLAN with VLAND ID == 300 (Online_dev).
# The name of the provider physical_network "ext" is mapped to a physical
# device on the ML2 configuration file of each network node
neutron net-create \
--provider:network_type vlan \
--provider:physical_network ext \
--router:external \
@jriguera
jriguera / iptables_redirect.txt
Created December 17, 2015 12:52
Iptables redirect port
# All incoming trafic (mainly via eth2) will be redirected to 2005 (old graphite relay)
iptables -t nat -A PREROUTING -p tcp --dport 2003 -j REDIRECT --to-port 2005
iptables -t nat -A PREROUTING -p udp --dport 2003 -j REDIRECT --to-port 2005
# Another example using ips
#iptables -t nat -A PREROUTING -i eth2 -p udp -d 10.9.2.197 --dport 2003 -j REDIRECT --to-port 2005
# loopback traffic do not go via PREROUTING chain
iptables -t nat -A OUTPUT -o lo -p tcp --dport 2003 -j REDIRECT --to-port 2005
# just the same but using ips instead of interfaces (for udp)
iptables -t nat -A OUTPUT --src 0/0 --dst 127.0.0.1 -p udp --dport 2003 -j REDIRECT --to-port 2005
@jriguera
jriguera / notify_slack_hipchat.sh
Created January 6, 2016 13:59
how to notify slack and hipchat
# Define those variables according to hipchar of slack (in this case is for slack)
ROOM_ID="XXXXX"
ROOM_TOKEN="XXXXXX/XXXXXXX/XXXXXXXXXXXXXXXXXXXX"
notify_hipchat() {
local msg="[$(hostname)] microBOSH/CF $ENVIRONMET $BKPLEVEL backup $BKPSTATUS"
local notify="0"
[ "$STATUS" != "1" ] && notify="1"
curl -H "Content-type: application/json" \
@jriguera
jriguera / interfaces.cfg
Created February 3, 2016 15:02
Debian/Ubuntu interfaces with routing tables
auto bond0.502
# Static interface with an address, will be brought up directly on boot.
iface bond0.502 inet static
address 10.10.11.10
netmask 255.255.248.0
#gateway 10.10.8.1
vlan-raw-device bond0
post-up grep -q " live" /etc/iproute2/rt_tables || echo "202 live" >> /etc/iproute2/rt_tables
post-up ip rule add from 10.10.11.10 table live
post-up ip route add table live default via 10.10.8.1
@jriguera
jriguera / bosh_release.md
Last active March 8, 2016 12:29
Creating bosh releases

Start here: http://mariash.github.io/learn-bosh/, then goto: http://bosh.io/docs/create-release.html

  1. Prepare the environment with bosh lite.
  2. Create the workspace for the new release: bosh init release <release_name>
  3. Create the source packages to compile: bosh generate package <package_name>
  4. After defining the compilation steps, add the source packages bosh add blob <package.tgz> <package_name>
  5. Create the job (or jobs) to run: bosh generate job <job_name> and write the monit, spec and startup files
  6. Create a manifest for the new project: http://bosh.io/docs/deployment-manifest.html, using cd templates && make_manifest warden. Option: copy from another simple release like: https://github.com/cloudfoundry-community/carbon-c-relay-boshrelease
  7. bosh status has to be pointing to the deployment manifest created before.
@jriguera
jriguera / cf_org.py
Created October 14, 2016 09:31
Ansibe cf organizations
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Program to create an ansible inventory from all the deployments, jobs and
instances managed by a BOSH Director.
# This program 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.