Skip to content

Instantly share code, notes, and snippets.

View mrajani's full-sized avatar

Mahesh Rajani mrajani

  • San Francisco Bay Area
  • 02:16 (UTC -08:00)
View GitHub Profile
@mrajani
mrajani / change_pw.sh
Last active October 1, 2019 16:21
script to change password on first login
#!/bin/bash
#--- it has a syntax error need to fix ----#
# format of x9.csv, add error checking
# ipaddr, password, user
# 172.16.12.22, HKJP5763qhvf, ec2-user
set -x
echo "Start!"
f=x9.csv
@mrajani
mrajani / aws_cli_example.sh
Created September 27, 2019 21:01
aws cli example scripts
#!/bin/bash
## Requires jq install
## filter by region, here it is us
regions=$(aws ec2 describe-regions --filters "Name=region-name,Values=*us*" | jq '.Regions[]| .RegionName')
echo $regions
##
## regions=$(aws ec2 describe-regions --filters "Name=region-name,Values=*us*" --output text | cut -f 3)
regions=$(aws ec2 describe-regions --filters "Name=region-name,Values=*us*" --query 'Regions[*].RegionName' --outpu
@mrajani
mrajani / aws_networking.sh
Last active September 27, 2019 19:23
Create Subnets, IGW, SG in an existing VPC
vpcname="linuxacademy"
subnetcidr="10.0.2.0/24"
region="us-east-1"
az="${region}b"
sgname="${vpcname}-sg"
sshingress="0.0.0.0/0" # use your IP address /32
# query default vpc and tag
vpcs=$(aws ec2 describe-vpcs)
@mrajani
mrajani / change_pw.yaml
Last active September 24, 2019 15:09
change password with ansible - can use used for initial login
---
- name: Change password when connecting as a non-root/non-sudoer user.
# https://stackoverflow.com /45988965/
# Ansible's 'user' module can only change a password if it is ran as a root user or 'become' is used.
# For a non-root user, when you run 'passwd', it asks for current password before you can enter a new one.
# Workaround: Create a a temporary script that updates the password and run that script remoteley
# and use 'no_log' directive to prevent passwords being visible in any log.
# Tested that passwords not visible in verbose output '-vvvvv' and not in 'history' of remote computers.
# The temporary script is deleted remotley automatically by 'script' module.
# Note: New password must comply with your passwd security policy.
@mrajani
mrajani / configure_k8s.sh
Last active September 24, 2019 19:37
Prepare Ubuntu for Kubernetes
#!/bin/bash
# apt-cache policy docker-ce
# START Install on all nodes
export docker_version=5:18.09.9~3-0~ubuntu-bionic
export user=$(whoami)
export LBExt=3.91.9.240
export LBInt=10.21.0.223
export K8sCP1=10.21.0.71
@mrajani
mrajani / install_cfss_kubectl.sh
Last active September 17, 2019 20:13
Install cfssl and kubectl
#!/bin/bash
sudo wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 \
-O /usr/local/bin/cfssl
sudo wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 \
-O /usr/local/bin/cfssljson
sudo chmod +x /usr/local/bin/cfssl*
cfssl version
#!/bin/bash
#-- Run in all Nodes --#
#-- Install Docker K8sGPG --#
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
#-- Add Repos --#
cat << EOF | sudo tee /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
@mrajani
mrajani / install_nvm.sh
Last active July 17, 2019 23:55
Install NVM
#!/bin/bash
# https://github.com/nvm-sh/nvm#git-install
export NVM_DIR="$HOME/.nvm" && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
@mrajani
mrajani / rename-file-extensions.sh
Last active June 17, 2019 17:07
Rename file extensions
#!/bin/bash
# https://mywiki.wooledge.org/BashFAQ/030
# rename .tf to .ignore
for f in *.tf
do
mv -- "$f" "${f%.tf}.ignore"
done
# reverse *.ignore to .tf
@mrajani
mrajani / aws-cli-snippets.sh
Last active June 17, 2019 16:20
aws cli collections
#!/bin/bash
## Find regions pipe it to jq to get an array, filter just the us regions
aws ec2 describe-regions --filters "Name=endpoint,Values=*us*" | jq '.Regions[].RegionName'
## amazon instances
instances=( $(aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value[],PublicIpAddress]' \
--output text | awk '{ print $0}') )