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 4 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:AddTags",
"elasticloadbalancing:ConfigureHealthCheck",
"elasticloadbalancing:CreateListener",
"elasticloadbalancing:CreateRule",
"elasticloadbalancing:DeleteListener",
"elasticloadbalancing:DeleteRule",
"elasticloadbalancing:DescribeInstanceHealth",
"elasticloadbalancing:DescribeLoadBalancer*",
"elasticloadbalancing:DescribeTags",
"elasticloadbalancing:ModifyListener",
"elasticloadbalancing:ModifyLoadBalancerAttributes",
"elasticloadbalancing:ModifyRule",
"elasticloadbalancing:RemoveTags"
"elasticloadbalancing:Create*",
"elasticloadbalancing:Delete*",
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:Describe*",
"elasticloadbalancing:DisableAvailabilityZonesForLoadBalancer",
"elasticloadbalancing:EnableAvailabilityZonesForLoadBalancer",
"elasticloadbalancing:Modify*",
"elasticloadbalancing:Register*",
"elasticloadbalancing:Deregister*",
"elasticloadbalancing:Remove*"
],
"Resource": "*"
},

@ -449,8 +449,10 @@ def create_or_update_target_group(connection, module):
changed = False
new_target_group = False
params = dict()
target_type = module.params.get("target_type")
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['Port'] = module.params.get("port")
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")
# Get target type
if module.params.get("target_type") is not None:
params['TargetType'] = module.params.get("target_type")
if params['TargetType'] == 'ip':
fail_if_ip_target_type_not_supported(module)
if target_type == 'ip':
fail_if_ip_target_type_not_supported(module)
# Get target group
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("target_type") != "lambda":
if target_type != "lambda":
params['Targets'] = module.params.get("targets")
# Correct type of target ports
@ -660,7 +660,7 @@ def create_or_update_target_group(connection, module):
module.fail_json_aws(
e, msg="Couldn't register targets")
else:
if module.params.get("target_type") != "lambda":
if target_type != "lambda":
current_instances = current_targets['TargetHealthDescriptions']
@ -701,7 +701,7 @@ def create_or_update_target_group(connection, module):
tg = get_target_group(connection, module)
if module.params.get("targets"):
if module.params.get("target_type") != "lambda":
if target_type != "lambda":
params['Targets'] = module.params.get("targets")
try:
connection.register_targets(TargetGroupArn=tg['TargetGroupArn'], Targets=params['Targets'])

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

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

@ -4,31 +4,38 @@
tasks:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: madeup
aws_secret_key: madeup
security_token: madeup
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 }}"
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)
elb_target_group:
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg"
health_check_port: 80
protocol: http
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
assert:
that:
- elb_target_group_type_ip is failed
- "'msg' in elb_target_group_type_ip"
- name: check that setting up target group with type=ip fails with friendly message
assert:
that:
- elb_target_group_type_ip is failed
- "'msg' in elb_target_group_type_ip"
# In the off-chance that this went (partially) through when it shouldn't...
always:
- name: Remove testing target group (type=ip)
elb_target_group:
state: absent
#name: "{{ resource_shortprefix }}-tg"
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tg"

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

@ -1,20 +1,27 @@
---
- 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:
# ============================================================
- name:
debug: msg="********** Setting up elb_target_info test dependencies **********"
# ============================================================
- name: set up aws connection info
set_fact:
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 }}'
# ============================================================
@ -23,7 +30,6 @@
name: "{{ resource_prefix }}-vpc"
state: present
cidr_block: 20.0.0.0/16
<<: *aws_connection_info
tags:
Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test"
@ -33,7 +39,6 @@
ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}"
state: present
<<: *aws_connection_info
register: igw
- name: set up testing subnet
@ -44,7 +49,6 @@
az: "{{ aws_region }}a"
resource_tags:
Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_1
- name: set up testing subnet
@ -55,7 +59,6 @@
az: "{{ aws_region }}b"
resource_tags:
Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: subnet_2
- name: create routing rules
@ -69,7 +72,6 @@
subnets:
- "{{ subnet_1.subnet.id }}"
- "{{ subnet_2.subnet.id }}"
<<: *aws_connection_info
register: route_table
- name: create testing security group
@ -86,7 +88,6 @@
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: sg
- name: set up testing target group (type=instance)
@ -103,7 +104,6 @@
deregistration_delay_timeout: 30
tags:
Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group (type=ip)
register: nlb_target_group
@ -116,10 +116,9 @@
state: present
# set this to 30 to test polling for changes, instead of having everything go out immediately
deregistration_delay_timeout: 30
target_type: ip
target_type: ip
tags:
Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up testing target group which will not be associated with any load balancers
register: idle_target_group
@ -130,16 +129,15 @@
port: 80
vpc_id: '{{ vpc.vpc.id }}'
state: present
target_type: instance
target_type: instance
tags:
Description: "Created by {{ resource_prefix }}"
<<: *aws_connection_info
- name: set up ec2 instance to use as a target
ec2:
group_id: "{{ sg.group_id }}"
instance_type: t2.micro
image: "{{ ec2_ami_image[aws_region] }}"
image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags:
Name: "{{ resource_prefix }}-inst"
@ -159,7 +157,6 @@
runcmd:
- "service httpd start"
- echo "HELLO ANSIBLE" > /var/www/html/index.html
<<: *aws_connection_info
register: ec2
- name: create an application load balancer
@ -177,7 +174,6 @@
- Type: forward
TargetGroupName: "{{ tg_name }}-inst"
state: present
<<: *aws_connection_info
- name: create a network load balancer
@ -193,23 +189,20 @@
- Type: forward
TargetGroupName: "{{ tg_name }}-ip"
state: present
<<: *aws_connection_info
- name: register with the ALB
elb_target:
target_group_name: "{{ tg_name }}-inst"
target_id: "{{ ec2.instance_ids[0] }}"
state: present
target_status: "initial"
<<: *aws_connection_info
target_status: "initial"
- name: register with the NLB IP target group
elb_target:
target_group_name: "{{ tg_name }}-ip"
target_id: "{{ ec2.instances[0].private_ip }}"
target_id: "{{ ec2.instances[0].private_ip }}"
state: present
target_status: "initial"
<<: *aws_connection_info
# ============================================================
@ -219,7 +212,6 @@
- name: gather facts
elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}"
<<: *aws_connection_info
register: target_facts
- assert:
@ -237,12 +229,10 @@
target_id: "{{ ec2.instance_ids[0]}}"
state: present
target_status: "unused"
<<: *aws_connection_info
- name: gather facts again, including the idle group
elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}"
<<: *aws_connection_info
register: target_facts
- assert:
@ -257,7 +247,6 @@
elb_target_info:
instance_id: "{{ ec2.instance_ids[0]}}"
get_unused_target_groups: false
<<: *aws_connection_info
register: target_facts
- assert:
@ -267,29 +256,27 @@
- "{{ idle_target_group.target_group_arn not in (target_facts.instance_target_groups | map(attribute='target_group_arn')) }}"
- (target_facts.instance_target_groups | length) == 2
msg: "target_facts.instance_target_groups did not gather unused target groups when variable was set"
- name: register twice in the same target group
elb_target:
target_group_name: "{{ tg_name }}-ip"
target_port: 22
target_id: "{{ ec2.instances[0].private_ip }}"
target_id: "{{ ec2.instances[0].private_ip }}"
state: present
target_status: "healthy"
target_status_timeout: 300
<<: *aws_connection_info
target_status_timeout: 400
- name: gather facts
elb_target_info:
instance_id: "{{ ec2.instance_ids[0] }}"
get_unused_target_groups: false
<<: *aws_connection_info
register: target_facts
- assert:
that:
- alb_target_group.target_group_arn in (target_facts.instance_target_groups | map(attribute='target_group_arn'))
- nlb_target_group.target_group_arn in (target_facts.instance_target_groups | map(attribute='target_group_arn'))
- (target_facts.instance_target_groups | length) == 2
- (target_facts.instance_target_groups | length) == 2
- (target_facts.instance_target_groups |
selectattr('target_group_arn', 'equalto', nlb_target_group.target_group_arn) |
map(attribute='targets') |
@ -309,7 +296,6 @@
target_id: "{{ item.1.target_id }}"
state: absent
target_status: "draining"
<<: *aws_connection_info
with_subelements:
- "{{ original_target_groups }}"
- "targets"
@ -318,7 +304,6 @@
elb_target_info:
get_unused_target_groups: false
instance_id: "{{ ec2.instance_ids[0] }}"
<<: *aws_connection_info
register: target_facts
until: (target_facts.instance_target_groups | length) == 0
retries: 60
@ -332,7 +317,6 @@
target_id: "{{ item.1.target_id }}"
state: present
target_status: "initial"
<<: *aws_connection_info
with_subelements:
- "{{ original_target_groups }}"
- "targets"
@ -343,7 +327,6 @@
elb_target_info:
get_unused_target_groups: false
instance_id: "{{ ec2.instance_ids[0] }}"
<<: *aws_connection_info
register: target_facts
until: >
(target_facts.instance_target_groups |
@ -361,7 +344,7 @@
that:
- alb_target_group.target_group_arn in (target_facts.instance_target_groups | map(attribute='target_group_arn'))
- nlb_target_group.target_group_arn in (target_facts.instance_target_groups | map(attribute='target_group_arn'))
- (target_facts.instance_target_groups | length) == 2
- (target_facts.instance_target_groups | length) == 2
- (target_facts.instance_target_groups |
selectattr('target_group_arn', 'equalto', nlb_target_group.target_group_arn) |
map(attribute='targets') |
@ -379,7 +362,7 @@
ec2:
group_id: "{{ sg.group_id }}"
instance_type: t2.micro
image: "{{ ec2_ami_image[aws_region] }}"
image: "{{ ec2_ami_image }}"
vpc_subnet_id: "{{ subnet_2.subnet.id }}"
instance_tags:
Name: "{{ resource_prefix }}-inst"
@ -390,7 +373,6 @@
volumes: []
wait: true
ebs_optimized: false
<<: *aws_connection_info
ignore_errors: true
- name: remove application load balancer
@ -410,7 +392,6 @@
state: absent
wait: true
wait_timeout: 200
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -421,7 +402,6 @@
elb_network_lb:
name: "{{ lb_name }}-nlb"
state: absent
<<: *aws_connection_info
- name: remove testing target groups
elb_target_group:
@ -436,7 +416,6 @@
Description: "Created by {{ resource_prefix }}"
wait: true
wait_timeout: 200
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -461,7 +440,6 @@
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -472,7 +450,6 @@
state: absent
lookup: id
route_table_id: "{{ route_table.route_table.id }}"
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -486,7 +463,6 @@
az: "{{ aws_region }}a"
resource_tags:
Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -500,7 +476,6 @@
az: "{{ aws_region }}b"
resource_tags:
Name: "{{ resource_prefix }}-subnet"
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -510,7 +485,6 @@
ec2_vpc_igw:
vpc_id: "{{ vpc.vpc.id }}"
state: absent
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
@ -524,7 +498,6 @@
tags:
Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test"
<<: *aws_connection_info
register: removed
retries: 10
until: removed is not failed
Loading…
Cancel
Save