Skip to content

Commit

Permalink
ansible-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Nov 15, 2023
1 parent 8435113 commit e539479
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
192 changes: 98 additions & 94 deletions tests/integration/targets/ec2_instance_block_devices/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e539479

Please sign in to comment.