Skip to content

Instantly share code, notes, and snippets.

View arbabnazar's full-sized avatar
🏠
Working from home

Arbab Nazar arbabnazar

🏠
Working from home
View GitHub Profile
@arbabnazar
arbabnazar / extras.py
Created October 23, 2017 18:45 — forked from halberom/extras.py
ansible - example of nasty custom jinja filter to get attribute from all hosts in a group
# ansible_plugins/filter_plugins/extras.py
def getFromDict(dataDict, mapList):
return reduce(lambda d, k: d[k], mapList, dataDict)
def get_host_attr_for_group(hosts, hostvars, keys):
# given a list of nested keys, return the value for each host in hostvars
results = []
for host in hosts:
results.append(getFromDict(hostvars[host], keys))
return results
@arbabnazar
arbabnazar / ec2_cloud.groovy
Created August 23, 2017 17:40 — forked from vrivellino/ec2_cloud.groovy
Jenkins EC2 Plugin Configuration via Groovy
/*
* Configure the Jenkins EC2 Plugin via Groovy Script
* EC2 Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Amazon+EC2+Plugin
*/
import hudson.model.*
import jenkins.model.*
import hudson.plugins.ec2.*
import com.amazonaws.services.ec2.model.InstanceType
@arbabnazar
arbabnazar / nodejs-installers.groovy
Created August 23, 2017 14:23 — forked from mllrjb/nodejs-installers.groovy
Jenkins init.groovy.d Nodejs installer script
import jenkins.model.*
import hudson.model.*
import jenkins.plugins.nodejs.tools.*
import hudson.tools.*
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("jenkins.plugins.nodejs.tools.NodeJSInstallation")
def versions = [
@arbabnazar
arbabnazar / snapshots.py
Created August 15, 2017 18:35 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots - this script generates csv raport about snapshot usage
import re
import boto3
import csv
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
def get_snapshots():
return ec2.describe_snapshots(OwnerIds=['self'])['Snapshots']
@arbabnazar
arbabnazar / info.md
Created May 12, 2017 19:00 — forked from manicminer/info.md
RDS Production termination protection

RDS Production Termination Protection

Create a policy like this, substituting your AWS account number, then attach it to all groups and roles. It will prevent deletion of RDS instances containing the string "prod" in their name.

Note: This is intended to prevent accidental deletion, and is easily sidestepped.

@arbabnazar
arbabnazar / info.md
Created May 12, 2017 19:00 — forked from manicminer/info.md
RDS Production termination protection

RDS Production Termination Protection

Create a policy like this, substituting your AWS account number, then attach it to all groups and roles. It will prevent deletion of RDS instances containing the string "prod" in their name.

Note: This is intended to prevent accidental deletion, and is easily sidestepped.

@arbabnazar
arbabnazar / changepassword.sh.j2
Created August 20, 2016 19:50 — forked from elleryq/changepassword.sh.j2
Create Django super user in ansible
#!/usr/bin/expect
set timeout -1;
spawn {{django_dir}}/venv/bin/python manage.py changepassword {{admin_user}};
expect {
"Password:" { exp_send "{{admin_pass}}\r" ; exp_continue }
"Password (again):" { exp_send "{{admin_pass}}\r" ; exp_continue }
eof
}
@arbabnazar
arbabnazar / ansible.yml
Created August 20, 2016 19:40 — forked from ernestas-poskus/ansible.yml
Ansible Tips
# Extracting all ips from defined group
ips: "{{ groups['webservers']|map('extract', hostvars, ['ansible_eth1', 'ipv4', 'address'])|list }}"
# Iterate through dict, reject empty values
nsq_nsqd_opts: "{% for key, value in nsq_nsqd.iteritems() if value is not none %}-{{ key | replace('_', '-') }}=\"{{ value }}\" {% endfor %}"
@arbabnazar
arbabnazar / elastic_beanstalk_external_sessions.md
Created July 12, 2016 09:26 — forked from mlconnor/elastic_beanstalk_external_sessions.md
Analaysis and recommendation for externalizing session in Elastic Beanstalk using Tomcat and memcached.

Session Management in an Autoscaling Environment

Problem Statement

User sessions in J2EE and LAMP stacks have traditionally been handled in memory by the application server handling the user request. Because of that, load balancers have been configured to use sticky sessions. By sticky sessions we mean that once the user has visited the site, they will be assigned an app server and will return to that server for subsequent requests. The load balancers typically handle that by referencing the users session cookie.

Elastic cloud environments differ from traditional server configurations in that they have a variable number of servers based on traffic loads whereas traditional configurations had a fixed number of servers. When traffic volumes decline it is necessary to vaporize servers. In doing so, we would lose user sessions (essentially forcing a logout) unless we come up with a new strategy for session management.

A new approach

After much research, it is clear that the best

@arbabnazar
arbabnazar / gist:6b9909cfba52ac066512ba5d1c1a1080
Created July 9, 2016 09:20 — forked from mpolden/gist:8559017
Example for Ansible git-module and ssh agent forwarding
# files/env:
Defaults env_keep += "SSH_AUTH_SOCK"
# tasks/main.yml
- name: ensure sudo keeps SSH_AUTH_SOCK in environment
copy: src=env
dest=/etc/sudoers.d/env
mode=0440
owner=root
group=root