From e5394794a3a7f6fb80039218250ba54364a93e89 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 10 Nov 2023 08:31:48 +0100 Subject: [PATCH] ansible-lint --- .../defaults/main.yml | 4 +- .../ec2_instance_block_devices/meta/main.yml | 9 +- .../ec2_instance_block_devices/tasks/main.yml | 192 +++++++++--------- 3 files changed, 105 insertions(+), 100 deletions(-) diff --git a/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml b/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml index 364c37f8226..251a9bcb35b 100644 --- a/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml +++ b/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml @@ -1,4 +1,4 @@ --- # defaults file for ec2_instance_block_devices -ec2_instance_type: 't3.micro' -ec2_instance_tag_TestId: '{{ resource_prefix }}-block-devices' +ec2_instance_type: t3.micro +ec2_instance_tag_TestId: "{{ resource_prefix }}-block-devices" diff --git a/tests/integration/targets/ec2_instance_block_devices/meta/main.yml b/tests/integration/targets/ec2_instance_block_devices/meta/main.yml index 3207286058e..88e38b91b9c 100644 --- a/tests/integration/targets/ec2_instance_block_devices/meta/main.yml +++ b/tests/integration/targets/ec2_instance_block_devices/meta/main.yml @@ -1,6 +1,7 @@ +--- # this just makes sure they're in the right place dependencies: -- role: setup_ec2_facts -- role: setup_ec2_instance_env - vars: - ec2_instance_test_name: block_devices + - role: setup_ec2_facts + - role: setup_ec2_instance_env + vars: + ec2_instance_test_name: block_devices diff --git a/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml b/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml index 2a4f1cabac1..d01eff43131 100644 --- a/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml +++ b/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml @@ -1,110 +1,114 @@ -- module_defaults: +--- +- name: Wrap tests in block to set module defaults + module_defaults: group/aws: access_key: "{{ aws_access_key }}" secret_key: "{{ aws_secret_key }}" session_token: "{{ security_token | default(omit) }}" region: "{{ aws_region }}" block: - - name: "New instance with an extra block device" - ec2_instance: - state: running - name: "{{ resource_prefix }}-test-ebs-vols" - image_id: "{{ ec2_ami_id }}" - vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" - volumes: - - device_name: /dev/sdb - ebs: - volume_size: 20 - delete_on_termination: true - volume_type: standard - tags: - TestId: "{{ ec2_instance_tag_TestId }}" - instance_type: "{{ ec2_instance_type }}" - wait: true - register: block_device_instances + - name: New instance with an extra block device + amazon.aws.ec2_instance: + state: running + name: "{{ resource_prefix }}-test-ebs-vols" + image_id: "{{ ec2_ami_id }}" + vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" + volumes: + - device_name: /dev/sdb + ebs: + volume_size: 20 + delete_on_termination: true + volume_type: standard + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + instance_type: "{{ ec2_instance_type }}" + wait: true + register: block_device_instances - - name: "Gather instance info" - ec2_instance_info: - filters: - "tag:Name": "{{ resource_prefix }}-test-ebs-vols" - register: block_device_instances_info + - name: Gather instance info + amazon.aws.ec2_instance_info: + filters: + tag:Name: "{{ resource_prefix }}-test-ebs-vols" + register: block_device_instances_info - - assert: - that: - - block_device_instances is not failed - - block_device_instances is changed - - block_device_instances_info.instances[0].block_device_mappings[0] - - block_device_instances_info.instances[0].block_device_mappings[1] - - block_device_instances_info.instances[0].block_device_mappings[1].device_name == '/dev/sdb' + - name: Check device name + ansible.builtin.assert: + that: + - block_device_instances is not failed + - block_device_instances is changed + - block_device_instances_info.instances[0].block_device_mappings[0] + - block_device_instances_info.instances[0].block_device_mappings[1] + - block_device_instances_info.instances[0].block_device_mappings[1].device_name == '/dev/sdb' - - name: "New instance with an extra block device (check mode)" - ec2_instance: - state: present - name: "{{ resource_prefix }}-test-ebs-vols-checkmode" - image_id: "{{ ec2_ami_id }}" - vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" - volumes: - - device_name: /dev/sdb - ebs: - volume_size: 20 - delete_on_termination: true - volume_type: standard - tags: - TestId: "{{ ec2_instance_tag_TestId }}" - instance_type: "{{ ec2_instance_type }}" - check_mode: yes + - name: New instance with an extra block device (check mode) + amazon.aws.ec2_instance: + state: present + name: "{{ resource_prefix }}-test-ebs-vols-checkmode" + image_id: "{{ ec2_ami_id }}" + vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" + volumes: + - device_name: /dev/sdb + ebs: + volume_size: 20 + delete_on_termination: true + volume_type: standard + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + instance_type: "{{ ec2_instance_type }}" + check_mode: true - - name: "fact presented ec2 instance" - ec2_instance_info: - filters: - "tag:Name": "{{ resource_prefix }}-test-ebs-vols" - register: presented_instance_fact + - name: Fact presented ec2 instance + amazon.aws.ec2_instance_info: + filters: + tag:Name: "{{ resource_prefix }}-test-ebs-vols" + register: presented_instance_fact - - name: "fact checkmode ec2 instance" - ec2_instance_info: - filters: - "tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode" - register: checkmode_instance_fact + - name: Fact checkmode ec2 instance + amazon.aws.ec2_instance_info: + filters: + tag:Name: "{{ resource_prefix }}-test-ebs-vols-checkmode" + register: checkmode_instance_fact - - name: "Confirm instance was created without check mode" - assert: - that: - - "{{ presented_instance_fact.instances | length }} > 0" + - name: Confirm instance was created without check mode + ansible.builtin.assert: + that: + - "{{ presented_instance_fact.instances | length }} > 0" - - name: "Confirm instance was not created with check mode" - assert: - that: - - "{{ checkmode_instance_fact.instances | length }} == 0" + - name: Confirm instance was not created with check mode + ansible.builtin.assert: + that: + - "{{ checkmode_instance_fact.instances | length }} == 0" - - name: "Terminate instances" - ec2_instance: - state: absent - instance_ids: "{{ block_device_instances.instance_ids }}" + - name: Terminate instances + amazon.aws.ec2_instance: + state: absent + instance_ids: "{{ block_device_instances.instance_ids }}" - - name: "New instance with an extra block device - gp3 volume_type and throughput" - ec2_instance: - state: running - name: "{{ resource_prefix }}-test-ebs-vols-gp3" - image_id: "{{ ec2_ami_id }}" - vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" - volumes: - - device_name: /dev/sdb - ebs: - volume_size: 20 - delete_on_termination: true - volume_type: gp3 - throughput: 500 - tags: - TestId: "{{ ec2_instance_tag_TestId }}" - instance_type: "{{ ec2_instance_type }}" - wait: true - register: block_device_instances_gp3 + - name: New instance with an extra block device - gp3 volume_type and throughput + amazon.aws.ec2_instance: + state: running + name: "{{ resource_prefix }}-test-ebs-vols-gp3" + image_id: "{{ ec2_ami_id }}" + vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" + volumes: + - device_name: /dev/sdb + ebs: + volume_size: 20 + delete_on_termination: true + volume_type: gp3 + throughput: 500 + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + instance_type: "{{ ec2_instance_type }}" + wait: true + register: block_device_instances_gp3 - - assert: - that: - - block_device_instances_gp3 is not failed - - block_device_instances_gp3 is changed - - block_device_instances_gp3.spec.BlockDeviceMappings[0].DeviceName == '/dev/sdb' - - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3' - - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20 - - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500 + - name: Check updated device configuration + ansible.builtin.assert: + that: + - block_device_instances_gp3 is not failed + - block_device_instances_gp3 is changed + - block_device_instances_gp3.spec.BlockDeviceMappings[0].DeviceName == '/dev/sdb' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20 + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500