From 4e1c5dbe47e5fa611d782d4eaea4afb27398d871 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 20 Oct 2021 14:21:52 +0200 Subject: [PATCH] elb_instance - initial integration tests (#768) elb_instance - initial integration tests SUMMARY Rewrite elb_instance (ec2_elb) for boto3 ISSUE TYPE Feature Pull Request COMPONENT NAME elb_instance ADDITIONAL INFORMATION fixes: #384 Reviewed-by: Markus Bergholz Reviewed-by: Alina Buzachis Reviewed-by: None --- .../384-elb_instance-python3-fixups.yml | 2 + plugins/modules/elb_instance.py | 2 +- .../integration/targets/elb_instance/aliases | 1 + .../targets/elb_instance/defaults/main.yml | 17 + .../targets/elb_instance/meta/main.yml | 4 + .../elb_instance/tasks/cleanup_elbs.yml | 16 + .../elb_instance/tasks/cleanup_instances.yml | 23 ++ .../elb_instance/tasks/cleanup_vpc.yml | 26 ++ .../targets/elb_instance/tasks/main.yml | 29 ++ .../elb_instance/tasks/manage_asgs.yml | 110 ++++++ .../elb_instance/tasks/manage_instances.yml | 357 ++++++++++++++++++ .../targets/elb_instance/tasks/setup_elbs.yml | 45 +++ .../elb_instance/tasks/setup_instances.yml | 52 +++ .../targets/elb_instance/tasks/setup_vpc.yml | 65 ++++ .../targets/elb_instance/vars/main.yml | 1 + .../targets/setup_ec2_facts/defaults/main.yml | 6 +- 16 files changed, 753 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/384-elb_instance-python3-fixups.yml create mode 100644 tests/integration/targets/elb_instance/aliases create mode 100644 tests/integration/targets/elb_instance/defaults/main.yml create mode 100644 tests/integration/targets/elb_instance/meta/main.yml create mode 100644 tests/integration/targets/elb_instance/tasks/cleanup_elbs.yml create mode 100644 tests/integration/targets/elb_instance/tasks/cleanup_instances.yml create mode 100644 tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml create mode 100644 tests/integration/targets/elb_instance/tasks/main.yml create mode 100644 tests/integration/targets/elb_instance/tasks/manage_asgs.yml create mode 100644 tests/integration/targets/elb_instance/tasks/manage_instances.yml create mode 100644 tests/integration/targets/elb_instance/tasks/setup_elbs.yml create mode 100644 tests/integration/targets/elb_instance/tasks/setup_instances.yml create mode 100644 tests/integration/targets/elb_instance/tasks/setup_vpc.yml create mode 100644 tests/integration/targets/elb_instance/vars/main.yml diff --git a/changelogs/fragments/384-elb_instance-python3-fixups.yml b/changelogs/fragments/384-elb_instance-python3-fixups.yml new file mode 100644 index 00000000000..f4a3fd7e897 --- /dev/null +++ b/changelogs/fragments/384-elb_instance-python3-fixups.yml @@ -0,0 +1,2 @@ +bugfixes: +- elb_instance - Python 3 compatability fix (https://github.com/ansible-collections/community.aws/issues/384). diff --git a/plugins/modules/elb_instance.py b/plugins/modules/elb_instance.py index 5759b0b2ccc..b234031ee24 100644 --- a/plugins/modules/elb_instance.py +++ b/plugins/modules/elb_instance.py @@ -271,7 +271,7 @@ def _get_instance_lbs(self, ec2_elbs=None): break if ec2_elbs: - lbs = sorted(lb for lb in elbs if lb.name in ec2_elbs) + lbs = sorted([lb for lb in elbs if lb.name in ec2_elbs], key=lambda lb: lb.__repr__()) else: lbs = [] for lb in elbs: diff --git a/tests/integration/targets/elb_instance/aliases b/tests/integration/targets/elb_instance/aliases new file mode 100644 index 00000000000..4ef4b2067d0 --- /dev/null +++ b/tests/integration/targets/elb_instance/aliases @@ -0,0 +1 @@ +cloud/aws diff --git a/tests/integration/targets/elb_instance/defaults/main.yml b/tests/integration/targets/elb_instance/defaults/main.yml new file mode 100644 index 00000000000..65b75091b6b --- /dev/null +++ b/tests/integration/targets/elb_instance/defaults/main.yml @@ -0,0 +1,17 @@ +--- +# defaults file for ec2_elb_lb +elb_name_1: 'ansible-test-{{ tiny_prefix }}-1' +elb_name_2: 'ansible-test-{{ tiny_prefix }}-2' + +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' +subnet_cidr_1: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' +subnet_cidr_2: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' + +availability_zone_a: '{{ ec2_availability_zone_names[0] }}' +availability_zone_b: '{{ ec2_availability_zone_names[1] }}' + +elb_listeners: + - protocol: tcp + load_balancer_port: 80 + instance_port: 80 + instance_protocol: tcp diff --git a/tests/integration/targets/elb_instance/meta/main.yml b/tests/integration/targets/elb_instance/meta/main.yml new file mode 100644 index 00000000000..a0c556a5cb1 --- /dev/null +++ b/tests/integration/targets/elb_instance/meta/main.yml @@ -0,0 +1,4 @@ +dependencies: + - prepare_tests + - setup_ec2 + - setup_ec2_facts diff --git a/tests/integration/targets/elb_instance/tasks/cleanup_elbs.yml b/tests/integration/targets/elb_instance/tasks/cleanup_elbs.yml new file mode 100644 index 00000000000..92f7e31ae6b --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/cleanup_elbs.yml @@ -0,0 +1,16 @@ +--- +- name: remove the public load balancer + elb_classic_lb: + name: "{{ elb_name_1 }}" + state: absent + wait: true + register: result + ignore_errors: true + +- name: remove the private load balancer + elb_classic_lb: + name: "{{ elb_name_2 }}" + state: absent + wait: true + register: result + ignore_errors: true diff --git a/tests/integration/targets/elb_instance/tasks/cleanup_instances.yml b/tests/integration/targets/elb_instance/tasks/cleanup_instances.yml new file mode 100644 index 00000000000..5ad09127084 --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/cleanup_instances.yml @@ -0,0 +1,23 @@ +--- +- name: Delete instance + ec2_instance: + instance_ids: + - '{{ instance_a }}' + - '{{ instance_b }}' + state: absent + wait: true + ignore_errors: true + +- name: Delete ASG + ec2_asg: + name: "ansible-test-{{ tiny_prefix }}-elb" + state: absent + ignore_errors: true + register: ec2_asg_a + +- name: Delete Launch Template + ec2_lc: + name: "ansible-test-{{ tiny_prefix }}-elb" + state: absent + ignore_errors: true + register: ec2_lc_a diff --git a/tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml b/tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml new file mode 100644 index 00000000000..5c79f7adfbe --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml @@ -0,0 +1,26 @@ +--- +- name: delete security groups + ec2_group: + name: '{{ item }}' + state: absent + ignore_errors: true + loop: + - '{{ resource_prefix }}-a' + - '{{ resource_prefix }}-b' + +- name: delete subnets + ec2_vpc_subnet: + vpc_id: '{{ setup_vpc.vpc.id }}' + cidr: '{{ item }}' + state: absent + ignore_errors: true + loop: + - '{{ subnet_cidr_1 }}' + - '{{ subnet_cidr_2 }}' + +- name: delete VPC + ec2_vpc_net: + cidr_block: '{{ vpc_cidr }}' + state: absent + name: '{{ resource_prefix }}' + ignore_errors: true diff --git a/tests/integration/targets/elb_instance/tasks/main.yml b/tests/integration/targets/elb_instance/tasks/main.yml new file mode 100644 index 00000000000..247b6f6b6c1 --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- module_defaults: + group/aws: + region: "{{ aws_region }}" + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + collections: + - community.aws + - amazon.aws + block: + # ============================================================ + + - include_tasks: setup_vpc.yml + - include_tasks: setup_elbs.yml + - include_tasks: setup_instances.yml + + # ============================================================ + + - include_tasks: manage_instances.yml + - include_tasks: manage_asgs.yml + + always: + + # ============================================================ + + - include_tasks: cleanup_elbs.yml + - include_tasks: cleanup_instances.yml + - include_tasks: cleanup_vpc.yml diff --git a/tests/integration/targets/elb_instance/tasks/manage_asgs.yml b/tests/integration/targets/elb_instance/tasks/manage_asgs.yml new file mode 100644 index 00000000000..b4e246ef08c --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/manage_asgs.yml @@ -0,0 +1,110 @@ +--- +- name: Get ASG info + ec2_asg_info: + name: "ansible-test-{{ tiny_prefix }}-elb$" + register: asg_info + +- name: Store Instance ID from ASG + set_fact: + instance_asg: '{{ asg_info.results[0].instances[0].instance_id }}' + +- name: 'Remove an instance from ELB (check_mode)' + elb_instance: + instance_id: '{{ instance_asg }}' + state: 'absent' + wait_timeout: 60 + register: remove_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + # - remove_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in remove_instance' + - '"ec2_elbs" in remove_instance.ansible_facts' + - elb_name_1 in remove_instance.ansible_facts.ec2_elbs + - elb_name_2 in remove_instance.ansible_facts.ec2_elbs + # Check the real state didn't change + - instance_asg in elb_info_1.elbs[0].instances_inservice + - instance_asg in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from ELB' + elb_instance: + instance_id: '{{ instance_asg }}' + state: 'absent' + wait_timeout: 60 + register: remove_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + - remove_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in remove_instance' + - '"ec2_elbs" in remove_instance.ansible_facts' + - elb_name_1 in remove_instance.ansible_facts.ec2_elbs + - elb_name_2 in remove_instance.ansible_facts.ec2_elbs + # Check the real state + - instance_asg not in elb_info_1.elbs[0].instances_inservice + - instance_asg not in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from ELB - idempotency (check_mode)' + elb_instance: + instance_id: '{{ instance_asg }}' + state: 'absent' + wait_timeout: 60 + register: remove_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + - remove_instance is not changed + # Check the real state + - instance_asg not in elb_info_1.elbs[0].instances_inservice + - instance_asg not in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from ELB - idempotency' + elb_instance: + instance_id: '{{ instance_asg }}' + state: 'absent' + wait_timeout: 60 + register: remove_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + # XXX always returns the ELBs the ASG belongs to + # - remove_instance is not changed + # Check the real state + - instance_asg not in elb_info_1.elbs[0].instances_inservice + - instance_asg not in elb_info_2.elbs[0].instances_inservice diff --git a/tests/integration/targets/elb_instance/tasks/manage_instances.yml b/tests/integration/targets/elb_instance/tasks/manage_instances.yml new file mode 100644 index 00000000000..4530b371ede --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/manage_instances.yml @@ -0,0 +1,357 @@ +--- +- name: 'Wait for instances to be OK' + ec2_instance: + instance_ids: + - '{{ instance_a }}' + - '{{ instance_b }}' + state: 'started' + +- name: 'Add an instance to two ELBs (check_mode)' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: add_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - add_instance is successful + # - add_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in add_instance' + - '"ec2_elbs" in add_instance.ansible_facts' + - elb_name_1 in add_instance.ansible_facts.ec2_elbs + - elb_name_2 in add_instance.ansible_facts.ec2_elbs + # Check the real state didn't change + - instance_a not in elb_info_1.elbs[0].instances_inservice + - instance_a not in elb_info_2.elbs[0].instances_inservice + +- name: 'Add an instance to two ELBs' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: add_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - add_instance is successful + - add_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in add_instance' + - '"ec2_elbs" in add_instance.ansible_facts' + - elb_name_1 in add_instance.ansible_facts.ec2_elbs + - elb_name_2 in add_instance.ansible_facts.ec2_elbs + # Check the real state + - instance_a in elb_info_1.elbs[0].instances_inservice + - instance_a in elb_info_2.elbs[0].instances_inservice + +- name: 'Add an instance to two ELBs - idempotency (check_mode)' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: add_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - add_instance is successful + - add_instance is not changed + # Check the real state didn't change + - instance_a in elb_info_1.elbs[0].instances_inservice + - instance_a in elb_info_2.elbs[0].instances_inservice + +- name: 'Add an instance to two ELBs - idempotency' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: add_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - add_instance is successful + - add_instance is not changed + # Check the real state didn't change + - instance_a in elb_info_1.elbs[0].instances_inservice + - instance_a in elb_info_2.elbs[0].instances_inservice + +############################################################################### + +- name: 'Add an instance to an ELB in wrong AZ (check_mode)' + elb_instance: + instance_id: '{{ instance_b }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + wait_timeout: 60 + register: add_instance + check_mode: true + ignore_errors: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 + +- assert: + that: + # - add_instance is failed + # Check the real state didn't change + - instance_b not in elb_info_1.elbs[0].instances_inservice + +- name: 'Add an instance to an ELB in wrong AZ' + elb_instance: + instance_id: '{{ instance_b }}' + state: 'present' + ec2_elbs: + - '{{ elb_name_1 }}' + wait_timeout: 60 + register: add_instance + ignore_errors: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 + +- assert: + that: + - add_instance is failed + - instance_b not in elb_info_1.elbs[0].instances_inservice + +################################################################################ +# Currently doesn't support adding an AZ if you're not using the default VPC +# +# - name: 'Add an instance to an ELB with enable_availability_zone (check_mode)' +# elb_instance: +# instance_id: '{{ instance_b }}' +# state: 'present' +# ec2_elbs: +# - '{{ elb_name_1 }}' +# wait_timeout: 60 +# register: add_instance +# check_mode: true +# ignore_errors: true +# +# - elb_classic_lb_info: +# names: '{{ elb_name_1 }}' +# register: elb_info_1 +# +# - assert: +# that: +# - add_instance is successful +# # - add_instance is changed +# +# - name: 'Add an instance to an ELB with enable_availability_zone' +# elb_instance: +# instance_id: '{{ instance_b }}' +# state: 'present' +# ec2_elbs: +# - '{{ elb_name_1 }}' +# wait_timeout: 60 +# register: add_instance +# ignore_errors: true +# +# - elb_classic_lb_info: +# names: '{{ elb_name_1 }}' +# register: elb_info_1 +# +# - assert: +# that: +# - add_instance is successful +# - add_instance is changed +# +# - name: 'Add an instance to an ELB with enable_availability_zone - idempotency (check_mode)' +# elb_instance: +# instance_id: '{{ instance_b }}' +# state: 'present' +# ec2_elbs: +# - '{{ elb_name_1 }}' +# wait_timeout: 60 +# register: add_instance +# check_mode: true +# ignore_errors: true +# +# - elb_classic_lb_info: +# names: '{{ elb_name_2 }}' +# register: elb_info_1 +# +# - assert: +# that: +# - add_instance is successful +# - add_instance is not changed +# +# - name: 'Add an instance to an ELB with enable_availability_zone - idempotency' +# elb_instance: +# instance_id: '{{ instance_b }}' +# state: 'present' +# ec2_elbs: +# - '{{ elb_name_1 }}' +# wait_timeout: 60 +# register: add_instance +# ignore_errors: true +# +# - elb_classic_lb_info: +# names: '{{ elb_name_1 }}' +# register: elb_info_1 +# +# - assert: +# that: +# - add_instance is successful +# - add_instance is not changed +# +################################################################################ + + +- name: 'Remove an instance from two ELBs (check_mode)' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'absent' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: remove_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + # - remove_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in remove_instance' + - '"ec2_elbs" in remove_instance.ansible_facts' + - elb_name_1 in remove_instance.ansible_facts.ec2_elbs + - elb_name_2 in remove_instance.ansible_facts.ec2_elbs + # Check the real state didn't change + - instance_a in elb_info_1.elbs[0].instances_inservice + - instance_a in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from two ELBs' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'absent' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: remove_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + - remove_instance is changed + # It really shouldn't be returning a fact here + - '"ansible_facts" in remove_instance' + - '"ec2_elbs" in remove_instance.ansible_facts' + - elb_name_1 in remove_instance.ansible_facts.ec2_elbs + - elb_name_2 in remove_instance.ansible_facts.ec2_elbs + # Check the real state + - instance_a not in elb_info_1.elbs[0].instances_inservice + - instance_a not in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from two ELBs - idempotency (check_mode)' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'absent' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: remove_instance + check_mode: true + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + - remove_instance is not changed + # Check the real state didn't change + - instance_a not in elb_info_1.elbs[0].instances_inservice + - instance_a not in elb_info_2.elbs[0].instances_inservice + +- name: 'Remove an instance from two ELBs - idempotency' + elb_instance: + instance_id: '{{ instance_a }}' + state: 'absent' + ec2_elbs: + - '{{ elb_name_1 }}' + - '{{ elb_name_2 }}' + wait_timeout: 60 + register: remove_instance + +- elb_classic_lb_info: + names: '{{ elb_name_1 }}' + register: elb_info_1 +- elb_classic_lb_info: + names: '{{ elb_name_2 }}' + register: elb_info_2 + +- assert: + that: + - remove_instance is successful + - remove_instance is not changed + # Check the real state didn't change + - instance_a not in elb_info_1.elbs[0].instances_inservice + - instance_a not in elb_info_2.elbs[0].instances_inservice diff --git a/tests/integration/targets/elb_instance/tasks/setup_elbs.yml b/tests/integration/targets/elb_instance/tasks/setup_elbs.yml new file mode 100644 index 00000000000..835c7a03600 --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/setup_elbs.yml @@ -0,0 +1,45 @@ +--- + +- name: Create a private load balancer with 1 AZ enabled + elb_classic_lb: + name: "{{ elb_name_1 }}" + state: present + scheme: 'internal' + subnets: ['{{ subnet_a }}'] + listeners: '{{ elb_listeners }}' + wait: true + health_check: + ping_protocol: TCP + ping_port: 22 + healthy_threshold: 2 + unhealthy_threshold: 2 + interval: 5 + timeout: 2 + register: result + +- assert: + that: + - result is changed + - result.elb.status == "created" + +- name: Create a private load balancer with 2 AZs enabled + elb_classic_lb: + name: "{{ elb_name_2 }}" + state: present + scheme: 'internal' + subnets: ['{{ subnet_a }}', '{{ subnet_b }}'] + listeners: '{{ elb_listeners }}' + wait: true + health_check: + ping_protocol: TCP + ping_port: 22 + healthy_threshold: 2 + unhealthy_threshold: 2 + interval: 5 + timeout: 2 + register: result + +- assert: + that: + - result is changed + - result.elb.status == "created" diff --git a/tests/integration/targets/elb_instance/tasks/setup_instances.yml b/tests/integration/targets/elb_instance/tasks/setup_instances.yml new file mode 100644 index 00000000000..2abc348dfca --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/setup_instances.yml @@ -0,0 +1,52 @@ +--- +- name: Create instance a + ec2_instance: + name: "ansible-test-{{ tiny_prefix }}-elb-a" + image_id: "{{ ec2_ami_id }}" + vpc_subnet_id: "{{ subnet_a }}" + instance_type: t3.micro + wait: false + security_group: "{{ sg_a }}" + register: ec2_instance_a + +- name: Create instance b + ec2_instance: + name: "ansible-test-{{ tiny_prefix }}-elb-b" + image_id: "{{ ec2_ami_id }}" + vpc_subnet_id: "{{ subnet_b }}" + instance_type: t3.micro + wait: false + security_group: "{{ sg_a }}" + register: ec2_instance_b + +- name: store the Instance IDs + set_fact: + instance_a: "{{ ec2_instance_a.instance_ids[0] }}" + instance_b: "{{ ec2_instance_b.instance_ids[0] }}" + +- name: Create a Launch Template + ec2_lc: + name: "ansible-test-{{ tiny_prefix }}-elb" + image_id: "{{ ec2_ami_id }}" + security_groups: "{{ sg_a }}" + instance_type: t3.micro + assign_public_ip: no + register: ec2_lc_a + +- name: Create an ASG + ec2_asg: + name: "ansible-test-{{ tiny_prefix }}-elb" + load_balancers: + - "{{ elb_name_1 }}" + - "{{ elb_name_2 }}" + launch_config_name: "ansible-test-{{ tiny_prefix }}-elb" + availability_zones: + - "{{ availability_zone_a }}" + min_size: 0 + max_size: 1 + desired_capacity: 1 + wait_timeout: 600 + health_check_period: 60 + vpc_zone_identifier: + - "{{ subnet_a }}" + register: ec2_asg_a diff --git a/tests/integration/targets/elb_instance/tasks/setup_vpc.yml b/tests/integration/targets/elb_instance/tasks/setup_vpc.yml new file mode 100644 index 00000000000..6edbe7e2c9b --- /dev/null +++ b/tests/integration/targets/elb_instance/tasks/setup_vpc.yml @@ -0,0 +1,65 @@ +--- +# SETUP: vpc, subnet, security group +- name: create a VPC to work in + ec2_vpc_net: + cidr_block: '{{ vpc_cidr }}' + state: present + name: '{{ resource_prefix }}' + resource_tags: + Name: '{{ resource_prefix }}' + register: setup_vpc + +- name: create a subnet + ec2_vpc_subnet: + az: '{{ availability_zone_a }}' + tags: '{{ resource_prefix }}' + vpc_id: '{{ setup_vpc.vpc.id }}' + cidr: '{{ subnet_cidr_1 }}' + state: present + resource_tags: + Name: '{{ resource_prefix }}-a' + register: setup_subnet_1 + +- name: create a subnet + ec2_vpc_subnet: + az: '{{ availability_zone_b }}' + tags: '{{ resource_prefix }}' + vpc_id: '{{ setup_vpc.vpc.id }}' + cidr: '{{ subnet_cidr_2 }}' + state: present + resource_tags: + Name: '{{ resource_prefix }}-b' + register: setup_subnet_2 + +- name: create a security group + ec2_group: + name: '{{ resource_prefix }}-a' + description: 'created by Ansible integration tests' + state: present + vpc_id: '{{ setup_vpc.vpc.id }}' + rules: + - proto: tcp + from_port: 22 + to_port: 22 + cidr_ip: '{{ vpc_cidr }}' + register: setup_sg_1 + +- name: create a security group + ec2_group: + name: '{{ resource_prefix }}-b' + description: 'created by Ansible integration tests' + state: present + vpc_id: '{{ setup_vpc.vpc.id }}' + rules: + - proto: tcp + from_port: 22 + to_port: 22 + cidr_ip: '{{ vpc_cidr }}' + register: setup_sg_2 + +- name: store the IDs + set_fact: + subnet_a: "{{ setup_subnet_1.subnet.id }}" + subnet_b: "{{ setup_subnet_2.subnet.id }}" + sg_a: "{{ setup_sg_1.group_id }}" + sg_b: "{{ setup_sg_2.group_id }}" diff --git a/tests/integration/targets/elb_instance/vars/main.yml b/tests/integration/targets/elb_instance/vars/main.yml new file mode 100644 index 00000000000..ed97d539c09 --- /dev/null +++ b/tests/integration/targets/elb_instance/vars/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/setup_ec2_facts/defaults/main.yml b/tests/integration/targets/setup_ec2_facts/defaults/main.yml index a09e9a53707..e02cb60128a 100644 --- a/tests/integration/targets/setup_ec2_facts/defaults/main.yml +++ b/tests/integration/targets/setup_ec2_facts/defaults/main.yml @@ -1,3 +1,5 @@ -ec2_ami_name: 'Fedora-Cloud-Base-*.x86_64*' ec2_ami_owner_id: '125523088429' -ec2_ami_ssh_user: 'fedora' +#ec2_ami_name: 'Fedora-Cloud-Base-*.x86_64*' +ec2_ami_name: 'CentOS Stream 9 x86_64*' +#ec2_ami_ssh_user: 'fedora' +ec2_ami_ssh_user: 'centos'