This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 }}", |