elb_target / elb_target_info : Integration test fixups (#61256)

* Update AWS policy to enable management of TargetGroups

* elb_target: (integration tests) migrate to using module_defaults

* elb_target: (integration tests) lookup the AMI by name rather than hard coding AMI IDs

* elb_target_info: (integration tests) finish rename of integration test role

* elb_target: (integration tests) rename various resources to consistently use {{ resource_prefix }}

* elb_target_info: (integration tests) Migrate to using module_defaults

* elb_target_info: (integration tests) Lookup AMI by name rather than hard coding AMI IDs

* Apply suggestions from code review

Co-Authored-By: Jill R <4121322+jillr@users.noreply.github.com>

* elb_target: (integration tests) Remove the 'unsupported' alias

* Try bumping up the timeout

* Rules don't permit 'shippable' (resource_prefix uses this when run in shippable)

* Try bumping up more timeouts :/

* Avoid double evaluation of target_health assertion

* Simplify target_type usage a little (rather than constantly performing a lookup)

* mark elb_target tests 'unstable' for now, they're slow

Co-authored-by: Jill R <4121322+jillr@users.noreply.github.com>
pull/67638/head
Mark Chappell 5 years ago committed by GitHub
parent 65646179f1
commit 9c6495d4d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -97,17 +97,16 @@
"elasticloadbalancing:*TargetGroup", "elasticloadbalancing:*TargetGroup",
"elasticloadbalancing:AddTags", "elasticloadbalancing:AddTags",
"elasticloadbalancing:ConfigureHealthCheck", "elasticloadbalancing:ConfigureHealthCheck",
"elasticloadbalancing:CreateListener", "elasticloadbalancing:Create*",
"elasticloadbalancing:CreateRule", "elasticloadbalancing:Delete*",
"elasticloadbalancing:DeleteListener", "elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:DeleteRule", "elasticloadbalancing:Describe*",
"elasticloadbalancing:DescribeInstanceHealth", "elasticloadbalancing:DisableAvailabilityZonesForLoadBalancer",
"elasticloadbalancing:DescribeLoadBalancer*", "elasticloadbalancing:EnableAvailabilityZonesForLoadBalancer",
"elasticloadbalancing:DescribeTags", "elasticloadbalancing:Modify*",
"elasticloadbalancing:ModifyListener", "elasticloadbalancing:Register*",
"elasticloadbalancing:ModifyLoadBalancerAttributes", "elasticloadbalancing:Deregister*",
"elasticloadbalancing:ModifyRule", "elasticloadbalancing:Remove*"
"elasticloadbalancing:RemoveTags"
], ],
"Resource": "*" "Resource": "*"
}, },

@ -449,8 +449,10 @@ def create_or_update_target_group(connection, module):
changed = False changed = False
new_target_group = False new_target_group = False
params = dict() params = dict()
target_type = module.params.get("target_type")
params['Name'] = module.params.get("name") params['Name'] = module.params.get("name")
if module.params.get("target_type") != "lambda": params['TargetType'] = target_type
if target_type != "lambda":
params['Protocol'] = module.params.get("protocol").upper() params['Protocol'] = module.params.get("protocol").upper()
params['Port'] = module.params.get("port") params['Port'] = module.params.get("port")
params['VpcId'] = module.params.get("vpc_id") params['VpcId'] = module.params.get("vpc_id")
@ -500,10 +502,8 @@ def create_or_update_target_group(connection, module):
params['Matcher']['HttpCode'] = module.params.get("successful_response_codes") params['Matcher']['HttpCode'] = module.params.get("successful_response_codes")
# Get target type # Get target type
if module.params.get("target_type") is not None: if target_type == 'ip':
params['TargetType'] = module.params.get("target_type") fail_if_ip_target_type_not_supported(module)
if params['TargetType'] == 'ip':
fail_if_ip_target_type_not_supported(module)
# Get target group # Get target group
tg = get_target_group(connection, module) tg = get_target_group(connection, module)
@ -578,7 +578,7 @@ def create_or_update_target_group(connection, module):
if module.params.get("targets"): if module.params.get("targets"):
if module.params.get("target_type") != "lambda": if target_type != "lambda":
params['Targets'] = module.params.get("targets") params['Targets'] = module.params.get("targets")
# Correct type of target ports # Correct type of target ports
@ -660,7 +660,7 @@ def create_or_update_target_group(connection, module):
module.fail_json_aws( module.fail_json_aws(
e, msg="Couldn't register targets") e, msg="Couldn't register targets")
else: else:
if module.params.get("target_type") != "lambda": if target_type != "lambda":
current_instances = current_targets['TargetHealthDescriptions'] current_instances = current_targets['TargetHealthDescriptions']
@ -701,7 +701,7 @@ def create_or_update_target_group(connection, module):
tg = get_target_group(connection, module) tg = get_target_group(connection, module)
if module.params.get("targets"): if module.params.get("targets"):
if module.params.get("target_type") != "lambda": if target_type != "lambda":
params['Targets'] = module.params.get("targets") params['Targets'] = module.params.get("targets")
try: try:
connection.register_targets(TargetGroupArn=tg['TargetGroupArn'], Targets=params['Targets']) connection.register_targets(TargetGroupArn=tg['TargetGroupArn'], Targets=params['Targets'])

@ -1,3 +1,4 @@
cloud/aws cloud/aws
unsupported
elb_target_group elb_target_group
shippable/aws/group4
unstable

@ -0,0 +1,5 @@
resource_shortprefix: 'ansible-test-{{ resource_prefix | regex_search("([0-9]+)$") }}'
lambda_role_name: '{{ resource_shortprefix }}-elb-target-lambda'
#lambda_role_name: '{{ resource_prefix }}-elb-target-lambda'
lambda_name: '{{ resource_prefix }}-elb-target-lambda'
elb_target_group_name: '{{ resource_shortprefix }}-elb-tg'

@ -1,14 +1,12 @@
--- ---
- name: set up aws connection info - name: set up lambda as elb_target
set_fact:
aws_connection_info: &aws_connection_info module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key }}" aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}" aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}" security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}" region: "{{ aws_region }}"
no_log: yes
- name: set up lambda as elb_target
block: block:
- name: create zip to deploy lambda code - name: create zip to deploy lambda code
@ -19,21 +17,19 @@
- name: "create or update service-role for lambda" - name: "create or update service-role for lambda"
iam_role: iam_role:
<<: *aws_connection_info name: '{{ lambda_role_name }}'
name: ansible_lambda_execution
assume_role_policy_document: "{{ lookup('file', role_path + '/files/assume-role.json') }}" assume_role_policy_document: "{{ lookup('file', role_path + '/files/assume-role.json') }}"
managed_policy: managed_policy:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
register: ROLE_ARN register: ROLE_ARN
- name: when it is to fast, the role is not usable. - name: when it is too fast, the role is not usable.
pause: pause:
minutes: 1 seconds: 10
- name: deploy lambda.zip to ansible_lambda_target function - name: deploy lambda.zip to ansible_lambda_target function
lambda: lambda:
<<: *aws_connection_info name: "{{ lambda_name }}"
name: "ansible_lambda_target"
state: present state: present
zip_file: "/tmp/lambda.zip" zip_file: "/tmp/lambda.zip"
runtime: "python3.7" runtime: "python3.7"
@ -47,8 +43,7 @@
- name: create empty target group - name: create empty target group
elb_target_group: elb_target_group:
<<: *aws_connection_info name: '{{ elb_target_group_name }}'
name: ansible-lambda-targetgroup
target_type: lambda target_type: lambda
state: present state: present
modify_targets: False modify_targets: False
@ -61,9 +56,8 @@
- name: allow elb to invoke the lambda function - name: allow elb to invoke the lambda function
lambda_policy: lambda_policy:
<<: *aws_connection_info
state: present state: present
function_name: ansible_lambda_target function_name: "{{ lambda_name }}"
version: "{{ lambda_function.configuration.version }}" version: "{{ lambda_function.configuration.version }}"
statement_id: elb1 statement_id: elb1
action: lambda:InvokeFunction action: lambda:InvokeFunction
@ -72,8 +66,7 @@
- name: add lambda to elb target - name: add lambda to elb target
elb_target_group: elb_target_group:
<<: *aws_connection_info name: "{{ elb_target_group_name }}"
name: ansible-lambda-targetgroup
target_type: lambda target_type: lambda
state: present state: present
targets: targets:
@ -87,8 +80,7 @@
- name: re-add lambda to elb target (idempotency) - name: re-add lambda to elb target (idempotency)
elb_target_group: elb_target_group:
<<: *aws_connection_info name: "{{ elb_target_group_name }}"
name: ansible-lambda-targetgroup
target_type: lambda target_type: lambda
state: present state: present
targets: targets:
@ -102,8 +94,7 @@
- name: remove lambda target from target group - name: remove lambda target from target group
elb_target_group: elb_target_group:
<<: *aws_connection_info name: "{{ elb_target_group_name }}"
name: ansible-lambda-targetgroup
target_type: lambda target_type: lambda
state: absent state: absent
targets: [] targets: []
@ -117,19 +108,19 @@
always: always:
- name: remove elb target group - name: remove elb target group
elb_target_group: elb_target_group:
<<: *aws_connection_info name: "{{ elb_target_group_name }}"
name: ansible-lambda-targetgroup
target_type: lambda target_type: lambda
state: absent state: absent
ignore_errors: yes
- name: remove lambda function - name: remove lambda function
lambda: lambda:
<<: *aws_connection_info name: "{{ lambda_name }}"
name: "ansible_lambda_target"
state: absent state: absent
ignore_errors: yes
- name: remove iam role for lambda - name: remove iam role for lambda
iam_role: iam_role:
<<: *aws_connection_info name: '{{ lambda_role_name }}'
name: ansible_lambda_execution
state: absent state: absent
ignore_errors: yes

@ -1,8 +1,10 @@
--- ---
ec2_ami_image: ec2_ami_name: 'amzn2-ami-hvm-2.0.20190612-x86_64-gp2'
us-east-1: ami-8c1be5f6
us-east-2: ami-c5062ba0
tg_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg" resource_shortprefix: 'ansible-test-{{ resource_prefix | regex_search("([0-9]+)$") }}'
tg_tcpudp_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tgtcpudp" tg_name: "{{ resource_shortprefix }}-tg"
lb_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-lb" tg_tcpudp_name: "{{ resource_shortprefix }}-tgtcpudp"
lb_name: "{{ resource_shortprefix }}-lb"
healthy_state:
state: 'healthy'

@ -1,29 +1,35 @@
--- ---
- name: set up elb_target test prerequisites - name: set up elb_target test prerequisites
module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block: block:
- name:
debug: msg="********** Setting up elb_target test dependencies **********"
# ============================================================ # ============================================================
- name: set up aws connection info - name:
set_fact: debug: msg="********** Setting up elb_target test dependencies **********"
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes
# ============================================================ # ============================================================
- name: Find AMI to use
ec2_ami_info:
owners: 'amazon'
filters:
name: '{{ ec2_ami_name }}'
register: ec2_amis
- set_fact:
ec2_ami_image: '{{ ec2_amis.images[0].image_id }}'
- name: set up testing VPC - name: set up testing VPC
ec2_vpc_net: ec2_vpc_net:
name: "{{ resource_prefix }}-vpc" name: "{{ resource_prefix }}-vpc"
state: present state: present
cidr_block: 20.0.0.0/16 cidr_block: 20.0.0.0/16
<<: *aws_connection_info
tags: tags:
Name: "{{ resource_prefix }}-vpc" Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test" Description: "Created by ansible-test"
@ -33,7 +39,6 @@
ec2_vpc_igw: ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}" vpc_id: "{{ vpc.vpc.id }}"
state: present state: present
<<: *aws_connection_info
register: igw register: igw
- name: set up testing subnet - name: set up testing subnet
@ -44,7 +49,6 @@
az: "{{ aws_region }}a" az: "{{ aws_region }}a"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_1 register: subnet_1
- name: set up testing subnet - name: set up testing subnet
@ -55,7 +59,6 @@
az: "{{ aws_region }}b" az: "{{ aws_region }}b"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_2 register: subnet_2
- name: create routing rules - name: create routing rules
@ -69,7 +72,6 @@
subnets: subnets:
- "{{ subnet_1.subnet.id }}" - "{{ subnet_1.subnet.id }}"
- "{{ subnet_2.subnet.id }}" - "{{ subnet_2.subnet.id }}"
<<: *aws_connection_info
register: route_table register: route_table
- name: create testing security group - name: create testing security group
@ -86,7 +88,6 @@
from_port: 22 from_port: 22
to_port: 22 to_port: 22
cidr_ip: 0.0.0.0/0 cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: sg register: sg
- name: set up testing target group (type=instance) - name: set up testing target group (type=instance)
@ -100,7 +101,6 @@
target_type: instance target_type: instance
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group (type=instance) with UDP protocol - name: set up testing target group (type=instance) with UDP protocol
elb_target_group: elb_target_group:
@ -113,7 +113,6 @@
tags: tags:
Protocol: "UDP" Protocol: "UDP"
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group for ALB (type=instance) - name: set up testing target group for ALB (type=instance)
elb_target_group: elb_target_group:
@ -126,13 +125,12 @@
target_type: instance target_type: instance
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up ec2 instance to use as a target - name: set up ec2 instance to use as a target
ec2: ec2:
group_id: "{{ sg.group_id }}" group_id: "{{ sg.group_id }}"
instance_type: t2.micro instance_type: t3.micro
image: "{{ ec2_ami_image[aws_region] }}" image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}" vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags: instance_tags:
Name: "{{ resource_prefix }}-inst" Name: "{{ resource_prefix }}-inst"
@ -152,7 +150,6 @@
runcmd: runcmd:
- "service httpd start" - "service httpd start"
- echo "HELLO ANSIBLE" > /var/www/html/index.html - echo "HELLO ANSIBLE" > /var/www/html/index.html
<<: *aws_connection_info
register: ec2 register: ec2
- name: create an application load balancer - name: create an application load balancer
@ -170,7 +167,6 @@
- Type: forward - Type: forward
TargetGroupName: "{{ tg_name }}-used" TargetGroupName: "{{ tg_name }}-used"
state: present state: present
<<: *aws_connection_info
# ============================================================ # ============================================================
@ -184,7 +180,6 @@
target_group_name: "{{ tg_name }}" target_group_name: "{{ tg_name }}"
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: present state: present
<<: *aws_connection_info
register: result register: result
- name: target is registered - name: target is registered
@ -192,7 +187,7 @@
that: that:
- result.changed - result.changed
- result.target_group_arn - result.target_group_arn
- "'{{ result.target_health_descriptions.target.id }}' == '{{ ec2.instance_ids[0] }}'" - result.target_health_descriptions.target.id == ec2.instance_ids[0]
# ============================================================ # ============================================================
@ -201,7 +196,6 @@
target_group_name: "{{ tg_name }}" target_group_name: "{{ tg_name }}"
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: present state: present
<<: *aws_connection_info
register: result register: result
- name: target was already registered - name: target was already registered
@ -217,7 +211,6 @@
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: absent state: absent
deregister_unused: true deregister_unused: true
<<: *aws_connection_info
register: result register: result
- name: target group was deleted - name: target group was deleted
@ -234,8 +227,7 @@
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: present state: present
target_status: healthy target_status: healthy
target_status_timeout: 200 target_status_timeout: 400
<<: *aws_connection_info
register: result register: result
- name: target is registered - name: target is registered
@ -243,8 +235,8 @@
that: that:
- result.changed - result.changed
- result.target_group_arn - result.target_group_arn
- "'{{ result.target_health_descriptions.target.id }}' == '{{ ec2.instance_ids[0] }}'" - result.target_health_descriptions.target.id == ec2.instance_ids[0]
- "{{ result.target_health_descriptions.target_health }} == {'state': 'healthy'}" - result.target_health_descriptions.target_health == healthy_state
# ============================================================ # ============================================================
@ -255,7 +247,6 @@
state: absent state: absent
target_status: unused target_status: unused
target_status_timeout: 400 target_status_timeout: 400
<<: *aws_connection_info
register: result register: result
- name: target was deregistered - name: target was deregistered
@ -270,7 +261,6 @@
target_group_name: "{{ tg_name }}-used" target_group_name: "{{ tg_name }}-used"
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: absent state: absent
<<: *aws_connection_info
register: result register: result
- name: target was already deregistered - name: target was already deregistered
@ -286,8 +276,7 @@
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: present state: present
target_status: healthy target_status: healthy
target_status_timeout: 200 target_status_timeout: 400
<<: *aws_connection_info
register: result register: result
- name: target is registered - name: target is registered
@ -295,15 +284,14 @@
that: that:
- result.changed - result.changed
- result.target_group_arn - result.target_group_arn
- "'{{ result.target_health_descriptions.target.id }}' == '{{ ec2.instance_ids[0] }}'" - result.target_health_descriptions.target.id == ec2.instance_ids[0]
- "{{ result.target_health_descriptions.target_health }} == {'state': 'healthy'}" - result.target_health_descriptions.target_health == healthy_state
- name: start deregisteration but don't wait - name: start deregisteration but don't wait
elb_target: elb_target:
target_group_name: "{{ tg_name }}-used" target_group_name: "{{ tg_name }}-used"
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: absent state: absent
<<: *aws_connection_info
register: result register: result
- name: target is starting to deregister - name: target is starting to deregister
@ -319,7 +307,6 @@
state: absent state: absent
target_status: unused target_status: unused
target_status_timeout: 400 target_status_timeout: 400
<<: *aws_connection_info
register: result register: result
- name: target was deregistered already and now has finished - name: target was deregistered already and now has finished
@ -339,7 +326,7 @@
ec2: ec2:
group_id: "{{ sg.group_id }}" group_id: "{{ sg.group_id }}"
instance_type: t2.micro instance_type: t2.micro
image: "{{ ec2_ami_image[aws_region] }}" image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}" vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags: instance_tags:
Name: "{{ resource_prefix }}-inst" Name: "{{ resource_prefix }}-inst"
@ -350,7 +337,6 @@
volumes: [] volumes: []
wait: true wait: true
ebs_optimized: false ebs_optimized: false
<<: *aws_connection_info
ignore_errors: true ignore_errors: true
- name: remove testing target groups - name: remove testing target groups
@ -365,8 +351,7 @@
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
wait: true wait: true
wait_timeout: 200 wait_timeout: 400
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -387,8 +372,7 @@
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
Protocol: "UDP" Protocol: "UDP"
wait: true wait: true
wait_timeout: 200 wait_timeout: 400
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -412,8 +396,7 @@
TargetGroupName: "{{ tg_name }}-used" TargetGroupName: "{{ tg_name }}-used"
state: absent state: absent
wait: true wait: true
wait_timeout: 200 wait_timeout: 400
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -434,7 +417,6 @@
from_port: 22 from_port: 22
to_port: 22 to_port: 22
cidr_ip: 0.0.0.0/0 cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -445,7 +427,6 @@
state: absent state: absent
lookup: id lookup: id
route_table_id: "{{ route_table.route_table.id }}" route_table_id: "{{ route_table.route_table.id }}"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -459,7 +440,6 @@
az: "{{ aws_region }}a" az: "{{ aws_region }}a"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -473,7 +453,6 @@
az: "{{ aws_region }}b" az: "{{ aws_region }}b"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -483,7 +462,6 @@
ec2_vpc_igw: ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}" vpc_id: "{{ vpc.vpc.id }}"
state: absent state: absent
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -497,7 +475,6 @@
tags: tags:
Name: "{{ resource_prefix }}-vpc" Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test" Description: "Created by ansible-test"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed

@ -4,31 +4,38 @@
tasks: tasks:
- name: set up aws connection info - name: set up aws connection info
set_fact: module_defaults:
aws_connection_info: &aws_connection_info group/aws:
aws_access_key: madeup aws_access_key: "{{ aws_access_key }}"
aws_secret_key: madeup aws_secret_key: "{{ aws_secret_key }}"
security_token: madeup security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}" region: "{{ aws_region }}"
no_log: yes block:
- name: set up testing target group (type=ip)
elb_target_group:
state: present
#name: "{{ resource_shortprefix }}-tg"
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg"
health_check_port: 80
protocol: http
port: 80
vpc_id: 'vpc-abcd1234'
target_type: ip
tags:
Description: "Created by {{ resource_prefix }}"
register: elb_target_group_type_ip
ignore_errors: yes
- name: set up testing target group (type=ip) - name: check that setting up target group with type=ip fails with friendly message
elb_target_group: assert:
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg" that:
health_check_port: 80 - elb_target_group_type_ip is failed
protocol: http - "'msg' in elb_target_group_type_ip"
port: 80
vpc_id: 'vpc-abcd1234'
state: present
target_type: ip
tags:
Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
register: elb_target_group_type_ip
ignore_errors: yes
- name: check that setting up target group with type=ip fails with friendly message # In the off-chance that this went (partially) through when it shouldn't...
assert: always:
that: - name: Remove testing target group (type=ip)
- elb_target_group_type_ip is failed elb_target_group:
- "'msg' in elb_target_group_type_ip" state: absent
#name: "{{ resource_shortprefix }}-tg"
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg"

@ -1,7 +1,5 @@
--- ---
ec2_ami_image: ec2_ami_name: 'amzn2-ami-hvm-2.0.20190612-x86_64-gp2'
us-east-1: ami-8c1be5f6
us-east-2: ami-c5062ba0
tg_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg" tg_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg"
lb_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-lb" lb_name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-lb"

@ -1,20 +1,27 @@
--- ---
- name: set up elb_target_info test prerequisites - name: set up elb_target_info test prerequisites
module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block: block:
# ============================================================
- name: - name:
debug: msg="********** Setting up elb_target_info test dependencies **********" debug: msg="********** Setting up elb_target_info test dependencies **********"
# ============================================================
- name: set up aws connection info - name: Find AMI to use
set_fact: ec2_ami_info:
aws_connection_info: &aws_connection_info owners: 'amazon'
aws_access_key: "{{ aws_access_key }}" filters:
aws_secret_key: "{{ aws_secret_key }}" name: '{{ ec2_ami_name }}'
security_token: "{{ security_token }}" register: ec2_amis
region: "{{ aws_region }}" - set_fact:
no_log: yes ec2_ami_image: '{{ ec2_amis.images[0].image_id }}'
# ============================================================ # ============================================================
@ -23,7 +30,6 @@
name: "{{ resource_prefix }}-vpc" name: "{{ resource_prefix }}-vpc"
state: present state: present
cidr_block: 20.0.0.0/16 cidr_block: 20.0.0.0/16
<<: *aws_connection_info
tags: tags:
Name: "{{ resource_prefix }}-vpc" Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test" Description: "Created by ansible-test"
@ -33,7 +39,6 @@
ec2_vpc_igw: ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}" vpc_id: "{{ vpc.vpc.id }}"
state: present state: present
<<: *aws_connection_info
register: igw register: igw
- name: set up testing subnet - name: set up testing subnet
@ -44,7 +49,6 @@
az: "{{ aws_region }}a" az: "{{ aws_region }}a"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_1 register: subnet_1
- name: set up testing subnet - name: set up testing subnet
@ -55,7 +59,6 @@
az: "{{ aws_region }}b" az: "{{ aws_region }}b"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_2 register: subnet_2
- name: create routing rules - name: create routing rules
@ -69,7 +72,6 @@
subnets: subnets:
- "{{ subnet_1.subnet.id }}" - "{{ subnet_1.subnet.id }}"
- "{{ subnet_2.subnet.id }}" - "{{ subnet_2.subnet.id }}"
<<: *aws_connection_info
register: route_table register: route_table
- name: create testing security group - name: create testing security group
@ -86,7 +88,6 @@
from_port: 22 from_port: 22
to_port: 22 to_port: 22
cidr_ip: 0.0.0.0/0 cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: sg register: sg
- name: set up testing target group (type=instance) - name: set up testing target group (type=instance)
@ -103,7 +104,6 @@
deregistration_delay_timeout: 30 deregistration_delay_timeout: 30
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group (type=ip) - name: set up testing target group (type=ip)
register: nlb_target_group register: nlb_target_group
@ -119,7 +119,6 @@
target_type: ip target_type: ip
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group which will not be associated with any load balancers - name: set up testing target group which will not be associated with any load balancers
register: idle_target_group register: idle_target_group
@ -133,13 +132,12 @@
target_type: instance target_type: instance
tags: tags:
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up ec2 instance to use as a target - name: set up ec2 instance to use as a target
ec2: ec2:
group_id: "{{ sg.group_id }}" group_id: "{{ sg.group_id }}"
instance_type: t2.micro instance_type: t2.micro
image: "{{ ec2_ami_image[aws_region] }}" image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}" vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags: instance_tags:
Name: "{{ resource_prefix }}-inst" Name: "{{ resource_prefix }}-inst"
@ -159,7 +157,6 @@
runcmd: runcmd:
- "service httpd start" - "service httpd start"
- echo "HELLO ANSIBLE" > /var/www/html/index.html - echo "HELLO ANSIBLE" > /var/www/html/index.html
<<: *aws_connection_info
register: ec2 register: ec2
- name: create an application load balancer - name: create an application load balancer
@ -177,7 +174,6 @@
- Type: forward - Type: forward
TargetGroupName: "{{ tg_name }}-inst" TargetGroupName: "{{ tg_name }}-inst"
state: present state: present
<<: *aws_connection_info
- name: create a network load balancer - name: create a network load balancer
@ -193,7 +189,6 @@
- Type: forward - Type: forward
TargetGroupName: "{{ tg_name }}-ip" TargetGroupName: "{{ tg_name }}-ip"
state: present state: present
<<: *aws_connection_info
- name: register with the ALB - name: register with the ALB
elb_target: elb_target:
@ -201,7 +196,6 @@
target_id: "{{ ec2.instance_ids[0] }}" target_id: "{{ ec2.instance_ids[0] }}"
state: present state: present
target_status: "initial" target_status: "initial"
<<: *aws_connection_info
- name: register with the NLB IP target group - name: register with the NLB IP target group
elb_target: elb_target:
@ -209,7 +203,6 @@
target_id: "{{ ec2.instances[0].private_ip }}" target_id: "{{ ec2.instances[0].private_ip }}"
state: present state: present
target_status: "initial" target_status: "initial"
<<: *aws_connection_info
# ============================================================ # ============================================================
@ -219,7 +212,6 @@
- name: gather facts - name: gather facts
elb_target_info: elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}" instance_id: "{{ ec2.instance_ids[0]}}"
<<: *aws_connection_info
register: target_facts register: target_facts
- assert: - assert:
@ -237,12 +229,10 @@
target_id: "{{ ec2.instance_ids[0]}}" target_id: "{{ ec2.instance_ids[0]}}"
state: present state: present
target_status: "unused" target_status: "unused"
<<: *aws_connection_info
- name: gather facts again, including the idle group - name: gather facts again, including the idle group
elb_target_info: elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}" instance_id: "{{ ec2.instance_ids[0]}}"
<<: *aws_connection_info
register: target_facts register: target_facts
- assert: - assert:
@ -257,7 +247,6 @@
elb_target_info: elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}" instance_id: "{{ ec2.instance_ids[0]}}"
get_unused_target_groups: false get_unused_target_groups: false
<<: *aws_connection_info
register: target_facts register: target_facts
- assert: - assert:
@ -275,14 +264,12 @@
target_id: "{{ ec2.instances[0].private_ip }}" target_id: "{{ ec2.instances[0].private_ip }}"
state: present state: present
target_status: "healthy" target_status: "healthy"
target_status_timeout: 300 target_status_timeout: 400
<<: *aws_connection_info
- name: gather facts - name: gather facts
elb_target_info: elb_target_info:
instance_id: "{{ ec2.instance_ids[0] }}" instance_id: "{{ ec2.instance_ids[0] }}"
get_unused_target_groups: false get_unused_target_groups: false
<<: *aws_connection_info
register: target_facts register: target_facts
- assert: - assert:
@ -309,7 +296,6 @@
target_id: "{{ item.1.target_id }}" target_id: "{{ item.1.target_id }}"
state: absent state: absent
target_status: "draining" target_status: "draining"
<<: *aws_connection_info
with_subelements: with_subelements:
- "{{ original_target_groups }}" - "{{ original_target_groups }}"
- "targets" - "targets"
@ -318,7 +304,6 @@
elb_target_info: elb_target_info:
get_unused_target_groups: false get_unused_target_groups: false
instance_id: "{{ ec2.instance_ids[0] }}" instance_id: "{{ ec2.instance_ids[0] }}"
<<: *aws_connection_info
register: target_facts register: target_facts
until: (target_facts.instance_target_groups | length) == 0 until: (target_facts.instance_target_groups | length) == 0
retries: 60 retries: 60
@ -332,7 +317,6 @@
target_id: "{{ item.1.target_id }}" target_id: "{{ item.1.target_id }}"
state: present state: present
target_status: "initial" target_status: "initial"
<<: *aws_connection_info
with_subelements: with_subelements:
- "{{ original_target_groups }}" - "{{ original_target_groups }}"
- "targets" - "targets"
@ -343,7 +327,6 @@
elb_target_info: elb_target_info:
get_unused_target_groups: false get_unused_target_groups: false
instance_id: "{{ ec2.instance_ids[0] }}" instance_id: "{{ ec2.instance_ids[0] }}"
<<: *aws_connection_info
register: target_facts register: target_facts
until: > until: >
(target_facts.instance_target_groups | (target_facts.instance_target_groups |
@ -379,7 +362,7 @@
ec2: ec2:
group_id: "{{ sg.group_id }}" group_id: "{{ sg.group_id }}"
instance_type: t2.micro instance_type: t2.micro
image: "{{ ec2_ami_image[aws_region] }}" image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}" vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags: instance_tags:
Name: "{{ resource_prefix }}-inst" Name: "{{ resource_prefix }}-inst"
@ -390,7 +373,6 @@
volumes: [] volumes: []
wait: true wait: true
ebs_optimized: false ebs_optimized: false
<<: *aws_connection_info
ignore_errors: true ignore_errors: true
- name: remove application load balancer - name: remove application load balancer
@ -410,7 +392,6 @@
state: absent state: absent
wait: true wait: true
wait_timeout: 200 wait_timeout: 200
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -421,7 +402,6 @@
elb_network_lb: elb_network_lb:
name: "{{ lb_name }}-nlb" name: "{{ lb_name }}-nlb"
state: absent state: absent
<<: *aws_connection_info
- name: remove testing target groups - name: remove testing target groups
elb_target_group: elb_target_group:
@ -436,7 +416,6 @@
Description: "Created by {{ resource_prefix }}" Description: "Created by {{ resource_prefix }}"
wait: true wait: true
wait_timeout: 200 wait_timeout: 200
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -461,7 +440,6 @@
from_port: 22 from_port: 22
to_port: 22 to_port: 22
cidr_ip: 0.0.0.0/0 cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -472,7 +450,6 @@
state: absent state: absent
lookup: id lookup: id
route_table_id: "{{ route_table.route_table.id }}" route_table_id: "{{ route_table.route_table.id }}"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -486,7 +463,6 @@
az: "{{ aws_region }}a" az: "{{ aws_region }}a"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -500,7 +476,6 @@
az: "{{ aws_region }}b" az: "{{ aws_region }}b"
resource_tags: resource_tags:
Name: "{{ resource_prefix }}-subnet" Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -510,7 +485,6 @@
ec2_vpc_igw: ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}" vpc_id: "{{ vpc.vpc.id }}"
state: absent state: absent
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
@ -524,7 +498,6 @@
tags: tags:
Name: "{{ resource_prefix }}-vpc" Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test" Description: "Created by ansible-test"
<<: *aws_connection_info
register: removed register: removed
retries: 10 retries: 10
until: removed is not failed until: removed is not failed
Loading…
Cancel
Save