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: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: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: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: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: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: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: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:group_vars:all.yml
Last active September 3, 2019 09:21
ansibled : vpc : group_vars : all
# group_vars/all.yml
# ---
# global definitions, not too much to go here...
# specify to run Ansible for hosts locally by default, not over SSH
ansible_connection: local
@tomwwright
tomwwright / ansibled:vpc:hosts.inventory
Last active February 8, 2018 11:11
ansibled : vpc : hosts.inventory
# hosts.inventory
[vpc]
vpc.ansibled
[project.ansibled:children]
vpc
@tomwwright
tomwwright / ansible:intro:example-playbook-2.yml
Created January 13, 2018 09:21
ansible : intro : example playbook 2
# imagining we have some hosts defined in an `elasticsearch` group
- hosts: elasticsearch
tasks:
# `when` allows us to define a condition that has to be true for this task to run
# in this case, it is including another list of tasks to execute using `include_tasks`
- name: do some sort of required setup
include_tasks: tasks/setup.yml