Instantly share code, notes, and snippets.

View lxde_desktop_user_data.sh
#!/bin/bash -xe
apt-get -y update
apt-get -y install xorg lxde-core lxterminal autocutsel chromium-browser
add-apt-repository -y ppa:x2go/stable
apt-get -y update
apt-get install -y x2goserver x2goserver-xsession
View CF_lambda_custom_resource_vpn_IPs.yml
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation template to demonstrate the use of an Lambda-backed custom resource.
In this example, I use boto3 in the Lambda function to find and return the two Outside
IP addresses for the VGW side of the VPN connection.
Parameters:
VpnConnectionId:
Description: Identifer of the VPN for which to obtain the Outside IP addresses
Type: String
Resources:
View AWS-cloudformation-aliases.md

Add the lines in the alias file to ~/.aws/cli/alias. These will take effect immediately.

cvt - validates template on local disk

dse - describe stack events; prints nice table with logical nresources with associated status

instances - list table of EC2 instances including Name tag, status, and IP addresses

active-stacks - list of stack names that are not in DELETE_COMPLETED. The name is a bit of a misnomer. Change it to something to is logical to you.

View user-data.yaml
# 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}
View LICENSE
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:
View create-aws-console-user.sh
#!/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
View aws_instances.sh
#!/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
View userdata.sh
#!/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 {} \;
View NetworkInterfaces.yaml
# 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:
View ansible-vault-usage-example
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