Skip to content

Instantly share code, notes, and snippets.

View jeffbrl's full-sized avatar

Jeff Loughridge jeffbrl

View GitHub Profile
@jeffbrl
jeffbrl / user-data.yaml
Created October 21, 2018 00:04
AWS CloudFormation UserData Example
# This example is from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html.
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
@jeffbrl
jeffbrl / LICENSE
Created October 13, 2018 21:16
This license applies to all public gists https://gist.github.com/jeffbrl
MIT License
Copyright (c) 2018 Jeff Loughridge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jeffbrl
jeffbrl / create-aws-console-user.sh
Last active October 10, 2018 14:37 — forked from res0nat0r/create-aws-console-user.sh
Create AWS console user from the awscli
#!/bin/bash
# USAGE: ./create-aws-console-user.sh $GROUPNAME $USERNAME $PASSWORD
# http://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_cliwpsapi
# Create administrator group
aws iam create-group --group-name $1
@jeffbrl
jeffbrl / aws_instances.sh
Created September 25, 2018 12:17
List AWS EC2 instances in all regions
#!/bin/sh
# From fitblip at https://github.com/aws/aws-cli/issues/1777#issuecomment-284262414
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
done
@jeffbrl
jeffbrl / userdata.sh
Last active August 8, 2023 21:14
AWS EC2 User Data for installing apache on Amazon Linux 2
#!/bin/bash -xe
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
usermod -a -G apache ec2-user
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;
@jeffbrl
jeffbrl / NetworkInterfaces.yaml
Created September 9, 2018 00:04
AWS CloudFormation NetworkInterfaces Syntax
# From https://stackoverflow.com/questions/47644034/cloudformation-error-value-of-property-networkinterfaces-must-be-a-list-of-obje
MyAppNetworkInterface:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref SubnetPrivate
MyApp:
Type: AWS::EC2::Instance
Properties:
@jeffbrl
jeffbrl / ansible-vault-usage-example
Created May 22, 2018 13:22
ansible-vault usage example using encrypted variables file
jeffl@ubuntu:~/vault_testing$ cat vars/secrets.yml
---
username: jeffl
password: secretpassword
jeffl@ubuntu:~/vault_testing$
jeffl@ubuntu:~/vault_testing$ echo "my_vault_pass" > vault_pass
jeffl@ubuntu:~/vault_testing$ chmod go-r vault_pass
jeffl@ubuntu:~/vault_testing$ ansible-vault encrypt --vault-id vault_pass vars/secrets.yml
@jeffbrl
jeffbrl / describe_instances.py
Created February 27, 2018 17:28
How to make datetime.datetime json serializable - boto3 ec2 describe_instances
# Adapted from https://stackoverflow.com/questions/35869985/datetime-datetime-is-not-json-serializable
import datetime
import json
import boto3
def datetime_handler(x):
if isinstance(x, datetime.datetime):
return x.isoformat()
@jeffbrl
jeffbrl / xpath_junos_primary_loopback
Created June 23, 2017 14:30
xpath expression for obtaining primary loopback address in junos
//logical-interface[name='lo0.0']/address-family[address-family-name='inet']/interface-address[ifa-flags/ifaf-current-primary]/ifa-local
@jeffbrl
jeffbrl / pyez_get_config_rpc.py
Created March 17, 2017 01:20
Using PyEZ's get_config RPC
# This gist demonstrates how to use PyEZ's get_config RPC
from jnpr.junos import Device
from lxml import etree
def example_one(dev):
# This uses default options
cnf = dev.rpc.get_config()
print etree.tostring(cnf)