From fd9a14744ee6fb5f076467a1090522d2713b88af Mon Sep 17 00:00:00 2001 From: Ben Leggett Date: Wed, 7 Feb 2018 15:57:02 -0500 Subject: [PATCH] [CE-268] Derive AMI ID, allow custom Subnet/VPC Change-Id: Ie1ecdabe40a780401d83cd5062f7a6037faa9cd0 Signed-off-by: Ben Leggett --- .../roles/cloud_aws/prepare/tasks/apply.yml | 15 +++++++++++++++ .../roles/cloud_aws/provision/tasks/apply.yml | 2 +- src/agent/ansible/vars/aws.yml | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/agent/ansible/roles/cloud_aws/prepare/tasks/apply.yml b/src/agent/ansible/roles/cloud_aws/prepare/tasks/apply.yml index 5f7560bf3..ae636cd58 100755 --- a/src/agent/ansible/roles/cloud_aws/prepare/tasks/apply.yml +++ b/src/agent/ansible/roles/cloud_aws/prepare/tasks/apply.yml @@ -4,6 +4,18 @@ aws_usr_key: "{{ auth.username }}" aws_sec_key: "{{ auth.password }}" +- name: Setup VPC filter if VPC ID defined + set_fact: + vpc_filters: + vpc-id: "{{ cluster.vpc_id }}" + when: cluster.vpc_id + +- name: Setup Subnet filter if Subnet ID defined + set_fact: + subnet_filters: + subnet-id: "{{ cluster.subnet_id }}" + when: cluster.subnet_id + - name: Retrieve AWS specific image flavor ec2_ami_find: region: "{{ cluster.region_name }}" @@ -38,6 +50,7 @@ region: "{{ cluster.region_name }}" aws_access_key: "{{ aws_usr_key }}" aws_secret_key: "{{ aws_sec_key }}" + filters: "{{ vpc_filters | default(omit)}}" register: vpcnet - name: Create EC2 security group @@ -73,6 +86,7 @@ region: "{{ cluster.region_name }}" aws_access_key: "{{ aws_usr_key }}" aws_secret_key: "{{ aws_sec_key }}" + filters: "{{ subnet_filters | default(omit)}}" register: vpcsubnet - name: Add provisioning host group @@ -81,6 +95,7 @@ ansible_host: "127.0.0.1" subnet_id: "{{ vpcsubnet.subnets[0].id }}" sg_id: "{{ vpcsg.security_groups[0].group_id }}" + ami_id: "{{ (found_amis.results | first).ami_id }}" groups: "prohosts" with_sequence: count={{ cluster.stack_size }} format=%03x no_log: True diff --git a/src/agent/ansible/roles/cloud_aws/provision/tasks/apply.yml b/src/agent/ansible/roles/cloud_aws/provision/tasks/apply.yml index da0176097..5f8fc5200 100755 --- a/src/agent/ansible/roles/cloud_aws/provision/tasks/apply.yml +++ b/src/agent/ansible/roles/cloud_aws/provision/tasks/apply.yml @@ -19,7 +19,7 @@ key_name: "{{ cluster.ssh_key_name }}" validate_certs: "{{ cluster.validate_certs }}" group_id: "{{ sg_id }}" - image: "{{ cluster.image_id }}" + image: "{{ ami_id }}" instance_type: "{{ cluster.flavor_name }}" state: present user_data: "{{ lookup('template', tp_path) }}" diff --git a/src/agent/ansible/vars/aws.yml b/src/agent/ansible/vars/aws.yml index a0d54ce4e..8f951e099 100755 --- a/src/agent/ansible/vars/aws.yml +++ b/src/agent/ansible/vars/aws.yml @@ -14,10 +14,10 @@ cluster: { region_name: "us-east-1", #TODO Dynamic fetch availability_zone: "", #TODO Dynamic fetch based on region security_group: "Fabric", - + subnet_id: "", #Optional, if unset will use the first subnet it finds + vpc_id: "", #Optional, if unset will use the default VPC target_os: "ubuntu", image_name: "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-*", - image_id: "ami-d15a75c7", flavor_name: "t2.medium", # "m2.medium" is big enough for Fabric ssh_user: "ubuntu", validate_certs: True,