Commit e47788f8 by Feanil Patel

Update the service play.

It can now bring up instances as well as ASGs for a service.

Also update the VPC play to fix some bugs.
 - Add an EIP to the NAT.
 - Source/Dest checks need to be disabled for NAT instances.
parent a0d2923e
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
connection: local connection: local
gather_facts: True gather_facts: True
vars: vars:
# TODO remove before merging
ansible_python_interpreter: "/home/edward/.virtualenvs/configuration/bin/python"
state: "present" state: "present"
auto_scaling_service: True
tasks: tasks:
- name: Manage IAM Role and Profile - name: Manage IAM Role and Profile
ec2_iam_role: ec2_iam_role:
...@@ -125,13 +124,14 @@ ...@@ -125,13 +124,14 @@
ec2_lc_local: ec2_lc_local:
profile: "{{ profile }}" profile: "{{ profile }}"
region: "{{ aws_region }}" region: "{{ aws_region }}"
name: "{{ launch_config.name }}" name: "{{ service_config.name }}"
image_id: "{{ launch_config.ami }}" image_id: "{{ service_config.ami }}"
key_name: "{{ launch_config.key_name }}" key_name: "{{ service_config.key_name }}"
security_groups: "{{ service_sec_group.group_id }}" security_groups: "{{ service_sec_group.group_id }}"
instance_type: "{{ launch_config.instance_type }}" instance_type: "{{ service_config.instance_type }}"
instance_profile_name: "{{ instance_profile_name }}" instance_profile_name: "{{ instance_profile_name }}"
volumes: "{{ launch_config.volumes }}" volumes: "{{ service_config.volumes }}"
when: auto_scaling_service
# #
# Hack alert, this registers a string in the global namespace # Hack alert, this registers a string in the global namespace
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
profile: "{{ profile }}" profile: "{{ profile }}"
region: "{{ aws_region }}" region: "{{ aws_region }}"
name: "{{ asg_name }}" name: "{{ asg_name }}"
launch_config_name: "{{ launch_config.name }}" launch_config_name: "{{ service_config.name }}"
load_balancers: "{{ elb_name }}" load_balancers: "{{ elb_name }}"
availability_zones: "{{ aws_availability_zones }}" availability_zones: "{{ aws_availability_zones }}"
min_size: "{{ asg_min_size }}" min_size: "{{ asg_min_size }}"
...@@ -154,6 +154,7 @@ ...@@ -154,6 +154,7 @@
vpc_zone_identifier: "{{ service_vpc_zone_identifier_string.msg }}" vpc_zone_identifier: "{{ service_vpc_zone_identifier_string.msg }}"
tags: "{{ asg_instance_tags }}" tags: "{{ asg_instance_tags }}"
register: asg register: asg
when: auto_scaling_service
- name: Manage scaling policies - name: Manage scaling policies
ec2_scaling_policy_devel: ec2_scaling_policy_devel:
...@@ -168,6 +169,7 @@ ...@@ -168,6 +169,7 @@
cooldown: "{{ item.cooldown }}" cooldown: "{{ item.cooldown }}"
with_items: scaling_policies with_items: scaling_policies
register: created_policies register: created_policies
when: auto_scaling_service
- name: Apply function to policy data - name: Apply function to policy data
util_map: util_map:
...@@ -177,6 +179,7 @@ ...@@ -177,6 +179,7 @@
- "name" - "name"
- "arn" - "arn"
register: policy_data register: policy_data
when: auto_scaling_service
- name: Manage metric alarms - name: Manage metric alarms
ec2_metric_alarm: ec2_metric_alarm:
...@@ -196,3 +199,28 @@ ...@@ -196,3 +199,28 @@
dimensions: "{{ item.dimensions }}" dimensions: "{{ item.dimensions }}"
alarm_actions: "{{ policy_data.function_output[item.target_policy] }}" alarm_actions: "{{ policy_data.function_output[item.target_policy] }}"
with_items: metric_alarms with_items: metric_alarms
when: auto_scaling_service
- name: See if instances already exist
local_action:
module: "ec2_lookup"
region: "{{ aws_region }}"
tags: "{{ asg_instance_tags }}"
register: potential_existing_instances
- name: Manage instances
ec2:
profile: "{{ profile }}"
region: "{{ aws_region }}"
wait: "yes"
group_id: "{{ service_sec_group.group_id }}"
key_name: "{{ service_config.key_name }}"
vpc_subnet_id: "{{ item.subnet_id }}"
instance_type: "{{ service_config.instance_type }}"
instance_tags: "{{ asg_instance_tags }}"
image: "{{ service_config.ami }}"
instance_profile_name: "{{ instance_profile_name }}"
volumes: "{{ service_config.volumes }}"
with_items: created_service_subnets.results
when: not auto_scaling_service and potential_existing_instances.instances|length == 0
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
module: 'ec2' module: 'ec2'
state: 'present' state: 'present'
wait: "yes" wait: "yes"
source_dest_check: false
region: "{{ aws_region }}" region: "{{ aws_region }}"
profile: "{{ profile }}" profile: "{{ profile }}"
group_id: "{{ created_nat_security_group.group_id }}" group_id: "{{ created_nat_security_group.group_id }}"
...@@ -97,6 +98,15 @@ ...@@ -97,6 +98,15 @@
register: created_nat_instance register: created_nat_instance
when: potential_existing_nat.instances|length == 0 when: potential_existing_nat.instances|length == 0
- name: assign eip to nat
ec2_eip:
profile: "{{ profile }}"
region: "{{ aws_region }}"
instance_id: "{{ created_nat_instance.instances[0].id }}"
in_vpc: true
reuse_existing_ip_allowed: true
when: potential_existing_nat.instances|length == 0
- name: create private route table - name: create private route table
ec2_rt: ec2_rt:
profile: "{{ profile }}" profile: "{{ profile }}"
...@@ -107,4 +117,4 @@ ...@@ -107,4 +117,4 @@
routes: "{{ vpc_private_route_table }}" routes: "{{ vpc_private_route_table }}"
register: created_public_rt register: created_public_rt
when: potential_existing_nat.instances|length == 0 when: potential_existing_nat.instances|length == 0
...@@ -82,8 +82,8 @@ class RTManager(): ...@@ -82,8 +82,8 @@ class RTManager():
if len(results) == 1: if len(results) == 1:
self.rt = results[0] self.rt = results[0]
elif len(results) > 1: elif len(results) > 1:
msg = "Found multiple route tables with name '{}' in vpc with id '{}'" msg = "Found multiple route tables with name '{}' in vpc with id '{}'."
raise DuplicateRouteTableError(msg.format(self.acl_name, self.vpc_id)) raise DuplicateRouteTableError(msg.format(self.name, self.vpc_id))
else: else:
pass pass
# Doesn't exist yet # Doesn't exist yet
......
...@@ -82,7 +82,7 @@ def zip_to_dict(module, input, key_key, value_key): ...@@ -82,7 +82,7 @@ def zip_to_dict(module, input, key_key, value_key):
For example, the input dict of For example, the input dict of
[{'name':'fred', 'id':'123'},['name':'bill', 'id':'321'}] [{'name':'fred', 'id':'123'},{'name':'bill', 'id':'321'}]
with an args array of ['id','name'] with an args array of ['id','name']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment