Skip to content

Instantly share code, notes, and snippets.

View filipenf's full-sized avatar
☮️

Filipe Felisbino filipenf

☮️
  • Udemy
  • San Francisco, CA
View GitHub Profile
@filipenf
filipenf / compare_charts.py
Last active February 24, 2023 22:00
Compare kubernetes manifest files
#!/usr/bin/env python3
import argparse
import difflib
import sys
from collections import defaultdict
from typing import Dict, List
import yaml
@filipenf
filipenf / Ansible Inventory Compare.md
Last active March 15, 2024 15:19
Ansible inventory comparison

Usage:

1. Create a virtualenv with deepdiff

requirements:

PyYAML==3.13
deepdiff==3.3.0
jsonpickle==1.0
@filipenf
filipenf / fix-ssh.sh
Created July 27, 2018 08:59
tmux ssh agent fix
#!/bin/bash
#fix ssh-agent when attaching to a tmux session
fixssh() {
eval $(tmux show-env \
|sed -n 's/^\(SSH_[^=]*\)=\(.*\)/export \1="\2"/p')
}
@filipenf
filipenf / worktree.sh
Created July 12, 2018 14:15
git worktree
function worktree_add() {
## Run this function in the top level directory of a git repo
## to create a worktree directory from a new or existing branch
if [ -d ./.git ]; then
git rev-parse --verify "$1"
if [ $? -eq 0 ]; then
echo "Creating a worktree ../$1 from existing branch $1"
git worktree add "../$1" "$1"
else
echo "Creating a worktree ../$1 from a new branch $1"
@filipenf
filipenf / convert-and-test.sh
Last active March 28, 2023 20:39
Script to convert an ansible vault into a yaml file with encrypted strings
#!/bin/bash
#Vault password is 1
echo "Converting vault to yaml format:"
ansible-vault decrypt --output - vault | python ./convert_vault.py > new-vault.yml
echo "Decrypting a variable from the converted vault"
ansible localhost -i localhost, -e @new-vault.yml -m debug -a 'var=secret' --ask-vault-pas
- hosts: localhost
connection: local
gather_facts: false
vars:
region: us-east-1
version: 1.0
repository: ansible-deploy-test
server_type: todo
subnet_id: subnet-f7e20b80
@filipenf
filipenf / docker-generator.py
Created September 10, 2016 15:05
Template(jinja) generator using docker container list as input
#!/usr/bin/env python
import argh, os, sys
from docker import Client
from os.path import dirname, basename
def get_containers(cli):
container_ids = [ c['Id'] for c in cli.containers() ]
containers = [ cli.inspect_container(cid) for cid in container_ids ]
@filipenf
filipenf / lndupes.py
Created August 19, 2016 19:04
Reads fdupes(-r1) output and create relative symbolic links for each duplicate
#!/usr/bin/env python
# Reads fdupes(-r -1) output and create relative symbolic links for each duplicate
# usage: fdupes -r1 . | ./lndupes.py
import os
from os.path import dirname, relpath, basename, join
import sys
lines = sys.stdin.readlines()
@filipenf
filipenf / generate-peers.sh
Last active June 10, 2022 13:29
Auto generate haproxy "peers" based on existing ASG instances
#!/bin/bash
# just a quick-and-dirty solution to update the peers configuration of haproxy upon ASG changes
# instance-id becomes the peer name ( need to use -L<instance_id> on the haproxy command line)
# port 7777 is used for p2p communication
# call this script on crontab and redirect the output to > /etc/haproxy/peers.cfg then include that file into your haproxy config
instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)
region=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone/)
region=${region:0:${#region}-1}
@filipenf
filipenf / ip-probe.sh
Created July 13, 2016 22:06
infinite loop to test network with fping and mtr
#!/bin/bash
if [ -z $1 ]; then
echo "Usage: $0 <ip address>"
exit 1;
fi;
IP_ADDR=$1
while true; do