Skip to content

Instantly share code, notes, and snippets.

View tomwwright's full-sized avatar
🎯
Focusing

Tom Wright tomwwright

🎯
Focusing
View GitHub Profile
@tomwwright
tomwwright / ansibled:vpc:host_vars:vpc.ansibled.yml
Last active February 8, 2018 09:53
ansibled : vpc : host_vars : vpc.ansibled
# host_vars/vpc.ansibled.yml
# IP CIDR block for the VPC
vpc_cidr_block: 10.0.0.0/16
# a map defining the subnets we will build in the VPC
vpc_subnets:
private-a:
cidr: 10.0.1.0/24
az: "{{ aws_region }}a"
@tomwwright
tomwwright / ansibled:vpc:tasks:setup.vpc.yml
Created February 5, 2018 11:55
ansibled : vpc : tasks : setup vpc
# tasks/vpc/setup.vpc.yml
# ---
# creates a VPC, configures a list of defined subnets, configures a list of defined security groups
# use the Ansible module to create our VPC, saving the output into `create_vpc`
- name: create VPC
ec2_vpc_net:
name: "{{ vpc_name }}"
cidr_block: "{{ vpc_cidr_block }}"
region: "{{ aws_region }}"
@tomwwright
tomwwright / ansibled:vpc:tasks:setup.gateways.yml
Created February 5, 2018 11:57
ansibled : vpc : tasks : setup gateways
# tasks/vpc/setup.gateways.yml
# ---
# creates the gateways for the VPC, and sets up routing for the subnets
# create the internet gateway, saving the output to extract the ID later
- name: create internet gateway
ec2_vpc_igw:
vpc_id: "{{ vpc_id }}"
register: create_gateway
@tomwwright
tomwwright / ansibled:vpc:vpc.yml
Last active February 5, 2018 12:16
ansibled : vpc : vpc playbook
# vpc.yml
# ---
# playbook that runs our VPC tasks for any hosts in the `vpc` group, providing AWS credentials in the environment
- hosts: vpc
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"
AWS_REGION: "{{ aws_region }}"
tasks:
@tomwwright
tomwwright / ansibled:vpc:tasks:facts.yml
Created February 5, 2018 12:00
ansibled : vpc : tasks : facts
# tasks/vpc/facts.yml
# ---
# sets facts for some important IDs and IPs of our VPC
# find the VPC by name
- name: VPC facts
ec2_vpc_net_facts:
filters:
"tag:Name": "{{ vpc_name }}"
register: vpc_facts
@tomwwright
tomwwright / ansibled:vpc:facts-usage.yml
Last active February 8, 2018 10:01
ansibled : vpc : facts usage
- name: define some facts about the VPC!
include_tasks: tasks/vpc/facts.yml
- name: now we can reference the subnet IDs of our subnets by friendly names
command: echo "The subnet ID of 'private-a' is: {{ vpc_subnet_ids['private-a'] }}"
- name: define some facts about a different VPC by providing the VPC name as a var!
include_tasks: tasks/vpc/facts.yml
vars:
vpc_name: "another_vpc"
@tomwwright
tomwwright / ansibled:vpc:group_vars:project.ansibled.yml
Created February 8, 2018 11:10
ansibled : vpc : group_vars : project.ansibled
# group_vars/project.ansibled.yml
# ---
# specify VPC details and AWS credentials
# general details about our VPC
vpc_name: ansibled-vpc
vpc_key: ansibled-key
vpc_dns_zone: ansibled
# credentials for AWS (no, they aren't real...)
@tomwwright
tomwwright / ansibled:es:tasks:setup.role.yml
Created March 19, 2018 09:40
ansibled : elasticsearch : tasks : setup role
# tasks/elasticsearch/setup.role.yml
# ---
# create the service-linked IAM role used by AWS Elasticsearch Service
# use the AWS CLI to retrieve a list of our IAM roles, store it in a variable
# using `register`
- name: list existing IAM roles
command: aws iam list-roles --no-paginate
changed_when: false
register: list_iam_roles
@tomwwright
tomwwright / ansibled:es:tasks:setup.cluster.yml
Created March 19, 2018 09:42
ansibled : elasticsearch : tasks : setup cluster
# tasks/elasticsearch/setup.cluster.yml
# ---
# look up our Elasticsearch cluster, create it if necessary, wait for it to be
# available, then update the DNS record for it in Route 53
# use the AWS CLI to query for details about this cluster, if it exists
- name: check for existing Elasticsearch cluster
command: aws es describe-elasticsearch-domains --region {{ aws_region }} --domain-names {{ elasticsearch_name }}
changed_when: false
register: elasticsearch_cluster_query
@tomwwright
tomwwright / ansibled:es:tasks:files:create-elasticsearch-domain.json.j2
Created March 19, 2018 09:44
ansibled : elasticsearch : tasks : setup cluster : configuration templates
{
"DomainName": "{{ elasticsearch_name }}",
"ElasticsearchVersion": "{{ elasticsearch_version }}",
"ElasticsearchClusterConfig": {
"InstanceType": "{{ elasticsearch_instance_type }}",
"InstanceCount": {{ elasticsearch_instance_count }},
"ZoneAwarenessEnabled": {{ (elasticsearch_instance_count == 1) | ternary('false', 'true') }},
"DedicatedMasterEnabled": {{ elasticsearch_dedicated_masters_enabled | lower }},
{% if elasticsearch_dedicated_masters_enabled %}
"DedicatedMasterType": "{{ elasticsearch_dedicated_masters_type }}",