Skip to content

Instantly share code, notes, and snippets.

View acsrujan's full-sized avatar
🏠

Srujan acsrujan

🏠
View GitHub Profile
@acsrujan
acsrujan / connectionTest.sh
Last active July 18, 2016 09:18
Script to test connection of a host, port and print time taken for each connection. Output is STDOUT.
#!/bin/bash
START=`date +%s`
while [ $(( $(date +%s) - 30 )) -lt $START ]; do
{ time nc -zw30 <host ip> <port>;} |& grep real | awk '{print $2}'
done
@acsrujan
acsrujan / updatesudoers.yml
Created September 12, 2016 09:39
Ansible Playbook to update sudo file on ubuntu with NOPASSWD for all users with 'sudo' permission.
---
#Updates sudo file on ubuntu with NOPASSWD for all users.
- hosts: all
sudo: yes
tasks:
- name: Allow 'sudo' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%sudo'
@acsrujan
acsrujan / homebrew.yml
Created September 15, 2016 18:15
Setting up new Mac with Ansible
---
- hosts: all
tasks:
- name: Installs homebrew if not already present
command: brew -v
register: brew_check
- name: install homebrew with curl
command: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
when: brew_check.stdout.find('command not found') > -1
@acsrujan
acsrujan / logrotate.conf
Created January 9, 2017 10:05
logrotate config with most of the options.
#To rotate file every 100kb, truncate the file and delete the older logs.
#This keeps only latest 100kb.
/var/logs/randomdump.log
{
size 100k
copytruncate
rotate 0
}
# Copytruncate avoids file delete and create new file.
@acsrujan
acsrujan / install_nodejs_ubuntu.sh
Created July 7, 2017 06:55
Installs nodejs on ubuntu..
#!/bin/bash
# This script installs node in ' $HOME/local/node ' directory wihtout sudo
# Store script's filename in $SELF_NAME
SELF_NAME=$(basename $0)
# Prints warning/error $MESSAGE in red foreground color (for [E]rror messages)
red_echo() {
echo -e "\e[1;31m[E] $SELF_NAME: $MESSAGE\e[0m"
}
@acsrujan
acsrujan / fluentd.yaml
Created June 12, 2019 18:17
fluentd for kubernetes
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: fluentd
@acsrujan
acsrujan / aws.tf
Last active June 17, 2019 07:05
Setup VPC with AWS NAT gateways
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
@acsrujan
acsrujan / launch_bastion.tf
Last active November 24, 2020 09:54
Launches bastion instance once provided values of variables
#Read more on https://acsrujan.net/launch-bastion-aws
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
@acsrujan
acsrujan / mysql_rds.tf
Created July 31, 2019 11:57
Creates mysql RDS database using terraform. Needs development.
resource "aws_security_group" "mydatabase_sg" {
name = "mydatabase_sg"
description = "Allows services to talk to mydatabase mysql"
vpc_id = "vpc-xxxx"
ingress {
from_port = 3306
to_port = 3306
protocol = "TCP"
self = true
@acsrujan
acsrujan / chef_cleanup.sh
Created August 9, 2019 08:43
Cleans up terminated nodes from Chef server.. run it as cron on a server with both AWS access and Chef access, with knife installed.
#!/bin/bash
# Scan for terminated nodes on AWS and remove from Chef
cleanupNodes() {
# get nodes that are terminated via aws-cli
terminated_nodes=$(aws ec2 describe-instances --region=us-east-1 --filters Name=instance-state-name,Values=terminated | grep "InstanceId" | awk -F ":" '{print $2}' | awk -F '"' '{print $2}')
for node in $terminated_nodes;
do