Skip to content

Instantly share code, notes, and snippets.

@renaudhager
renaudhager / aws-region.txt
Created March 13, 2020 19:02
Text file with all AWS region
us-east-2
us-east-1
us-west-1
us-west-2
ap-east-1
ap-south-1
ap-northeast-2
ap-southeast-1
ap-southeast-2
ap-northeast-1
#!/bin/bash
for region in `cat ~/Documents/work/tmp/aws-region-list.txt`
do
for profile in `cat ~/Documents/work/tmp/aws-profiles-list.txt`
do nb=$(aws ec2 describe-instances --region=${region} --profil=$profile | jq | grep -c InstanceId)
echo "${region}-1,$profile,$nb" | tee ~/Documents/work/tmp/aws-list-instances.csv
done
done
@renaudhager
renaudhager / keybase.md
Created June 27, 2019 11:12
Keybase proof of identity

Keybase proof

I hereby claim:

  • I am renaudhager on github.
  • I am renaudhager (https://keybase.io/renaudhager) on keybase.
  • I have a public key whose fingerprint is 7024 8C68 150D 3CC6 D2C8 797E BE05 C5F1 CA6F 0B3F

To claim this, I am signing this object:

@renaudhager
renaudhager / create-admin-account.groovy
Created November 7, 2017 14:46
Create a admin account in jenkins.
import jenkins.model.*
import hudson.security.*
def instance = Jenkins.getInstance()
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount("admin","admin")
instance.setSecurityRealm(hudsonRealm)
def strategy = new GlobalMatrixAuthorizationStrategy()
@renaudhager
renaudhager / aws-instances-lookup.py
Last active September 26, 2017 17:29
Query aws api to lookup for tag=value and print the instance name
#!/usr/bin/python
# Usage :
# aws ec2 describe-instances --filter="Name=instance-state-name,Values=running" | aws-instances-lookup <tag name> <tag value>
import sys
import json
def get_tag(instance, tag_key):
for tag in instance['Tags']:
@renaudhager
renaudhager / aws-tag-lookup.py
Created September 26, 2017 15:49
Query aws api to lookup for tag=value and print the instance name
#!/usr/bin/python
# Usage :
# aws ec2 describe-tags | python search_tags.py <tag name> <tag value>
import sys
import json
tag_key = sys.argv[1]
tag_value = sys.argv[2]
@renaudhager
renaudhager / rename_files.py
Last active September 23, 2017 11:27
Replace space by _ on filename
import os
path = os.getcwd()
directory_1_level = os.listdir(path)
for directory in directory_1_level:
if os.path.isdir(directory):
filenames = os.listdir(directory)
@renaudhager
renaudhager / aws_cli-cheatsheet.bash
Last active October 4, 2017 16:22
aws cli cheatsheet
# List all tags from the current instance
aws ec2 describe-tags --filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
# Print value of specific tag
aws ec2 describe-tags --filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" \
| jq '.Tags[] | select(.Key == "Owner" ) | .Value'
# Get the current region.
export AWS_DEFAULT_REGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq '.region' | tr -d \"`
@renaudhager
renaudhager / query-puppetdb.txt
Last active July 11, 2017 16:54
Query puppetdb nodes endpoint
curl -s -X GET http://localhost:8080/v3/nodes --data-urlencode 'query=["and",["=", ["fact", "nap_base_system_role"], "jiradb"],["=", ["fact", "nap_base_system_env"], "dev"]]'
curl -s -X GET http://localhost:8080/v3/nodes --data-urlencode query@myfile
Content of myfile:
["and",
["=", ["fact", "nap_base_system_role"], "jiradb"],
["=", ["fact", "nap_base_system_env"], "dev"]
]
@renaudhager
renaudhager / yum-list.bash
Created June 28, 2017 12:21
Format annoying yum output to be able to easily parse it
yum list installed | tr "\n" "#" | sed -e 's/# / /g' | tr "#" "\n" | grep blabla