Skip to content

Commit

Permalink
[CE-268] Derive AMI ID, allow custom Subnet/VPC
Browse files Browse the repository at this point in the history
Change-Id: Ie1ecdabe40a780401d83cd5062f7a6037faa9cd0
Signed-off-by: Ben Leggett <benjamin.leggett1@t-mobile.com>
  • Loading branch information
Ben Leggett committed Feb 8, 2018
1 parent 2b3b8d1 commit fd9a147
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/agent/ansible/roles/cloud_aws/prepare/tasks/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}"
Expand Down
4 changes: 2 additions & 2 deletions src/agent/ansible/vars/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fd9a147

Please sign in to comment.