mirror of https://github.com/ansible/ansible.git
ec2_instance test cleanup (#63708)
* ec2_instance/ec2_instance_info : Fixup sanity test errors * Move ec2_instance integration tests to use aws_defaults * Search for the AMI instead of hardcoding an AMI * Make our VPC CIDR variable * Remove AZ assumptions - no guarantees about specific AZs being available * Make sure we terminate instances when we're done with them. * Add a 10 second pause for IAM roles to become available before using them * Wait on instance changes by default * Switch out t2 instances for t3 they're cheaper and have more CPU available * Pull t3.nano instance info a little earlier * rework vpc_name and vpc_cidr a little * Mark ec2_instance tests unsupported for now, they take too longpull/63856/head
parent
aa671be28b
commit
145b79ef0e
@ -1,3 +1,4 @@
|
||||
ec2_instance_info
|
||||
cloud/aws
|
||||
shippable/aws/group2
|
||||
unstable
|
||||
#shippable/aws/group2
|
||||
unsupported
|
||||
|
@ -1,79 +1,80 @@
|
||||
- name: set connection information for all tasks
|
||||
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: true
|
||||
- block:
|
||||
- name: New instance with an extra block device
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-vols"
|
||||
image_id: "{{ ec2_ami_image }}"
|
||||
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: "{{ resource_prefix }}"
|
||||
instance_type: "{{ ec2_instance_type }}"
|
||||
wait: true
|
||||
register: in_test_vpc
|
||||
|
||||
- name: New instance with an extra block device
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-vols"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
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: "{{ resource_prefix }}"
|
||||
instance_type: t2.micro
|
||||
wait: true
|
||||
<<: *aws_connection_info
|
||||
register: in_test_vpc
|
||||
- name: Gather instance info
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||
register: in_test_vpc_instance
|
||||
|
||||
- name: Gather instance info
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||
<<: *aws_connection_info
|
||||
register: in_test_vpc_instance
|
||||
- assert:
|
||||
that:
|
||||
- in_test_vpc is not failed
|
||||
- in_test_vpc is changed
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[0]
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[1]
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- in_test_vpc is not failed
|
||||
- in_test_vpc is changed
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[0]
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[1]
|
||||
- in_test_vpc_instance.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
|
||||
- name: New instance with an extra block device(check mode)
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||
image_id: "{{ ec2_ami_image }}"
|
||||
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: "{{ resource_prefix }}"
|
||||
instance_type: "{{ ec2_instance_type }}"
|
||||
check_mode: yes
|
||||
|
||||
- name: New instance with an extra block device(check mode)
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
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: "{{ resource_prefix }}"
|
||||
instance_type: t2.micro
|
||||
<<: *aws_connection_info
|
||||
check_mode: yes
|
||||
- name: "fact presented ec2 instance"
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||
"instance-state-name": "running"
|
||||
register: presented_instance_fact
|
||||
|
||||
- name: "fact presented ec2 instance"
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||
"instance-state-name": "running"
|
||||
<<: *aws_connection_info
|
||||
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"
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||
<<: *aws_connection_info
|
||||
register: checkmode_instance_fact
|
||||
- name: "Confirm whether the check mode is working normally."
|
||||
assert:
|
||||
that:
|
||||
- "{{ presented_instance_fact.instances | length }} > 0"
|
||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||
|
||||
- name: "Confirm whether the check mode is working normally."
|
||||
assert:
|
||||
that:
|
||||
- "{{ presented_instance_fact.instances | length }} > 0"
|
||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||
- name: Terminate instances
|
||||
ec2_instance:
|
||||
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
||||
state: absent
|
||||
|
||||
always:
|
||||
- name: Terminate test-ebs-vols instances
|
||||
ec2_instance:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||
state: absent
|
||||
wait: false
|
||||
ignore_errors: yes
|
||||
|
@ -1,34 +1,38 @@
|
||||
- name: set connection information for all tasks
|
||||
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: true
|
||||
- block:
|
||||
- name: Make EBS optimized instance in the testing subnet of the test VPC
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||
image_id: "{{ ec2_ami_image }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
security_groups: "{{ sg.group_id }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
ebs_optimized: true
|
||||
instance_type: t3.nano
|
||||
wait: false
|
||||
register: ebs_opt_in_vpc
|
||||
|
||||
- name: Make EBS optimized instance in the testing subnet of the test VPC
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||
image_id: "{{ ec2_ebs_optimized_ami_image[aws_region] }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
security_groups: "{{ sg.group_id }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
ebs_optimized: true
|
||||
instance_type: t3.nano
|
||||
wait: false
|
||||
<<: *aws_connection_info
|
||||
register: ebs_opt_in_vpc
|
||||
- name: Get ec2 instance info
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||
register: ebs_opt_instance_info
|
||||
|
||||
- name: Get ec2 instance info
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||
<<: *aws_connection_info
|
||||
register: ebs_opt_instance_info
|
||||
- name: Assert instance is ebs_optimized
|
||||
assert:
|
||||
that:
|
||||
- "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}"
|
||||
|
||||
- name: Assert instance is ebs_optimized
|
||||
assert:
|
||||
that:
|
||||
- "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}"
|
||||
- name: Terminate instances
|
||||
ec2_instance:
|
||||
instance_ids: "{{ ebs_opt_in_vpc.instance_ids }}"
|
||||
state: absent
|
||||
|
||||
always:
|
||||
- name: Terminate test-ebs-vols instances
|
||||
ec2_instance:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||
state: absent
|
||||
wait: false
|
||||
ignore_errors: yes
|
||||
|
@ -1,62 +1,64 @@
|
||||
- name: set connection information for all tasks
|
||||
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: true
|
||||
- block:
|
||||
- name: New instance and don't wait for it to complete
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait"
|
||||
image_id: "{{ ec2_ami_image }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: "{{ ec2_instance_type }}"
|
||||
register: in_test_vpc
|
||||
|
||||
- name: New instance and don't wait for it to complete
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: t2.micro
|
||||
<<: *aws_connection_info
|
||||
register: in_test_vpc
|
||||
- assert:
|
||||
that:
|
||||
- in_test_vpc is not failed
|
||||
- in_test_vpc is changed
|
||||
- in_test_vpc.instances is not defined
|
||||
- in_test_vpc.instance_ids is defined
|
||||
- in_test_vpc.instance_ids | length > 0
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- in_test_vpc is not failed
|
||||
- in_test_vpc is changed
|
||||
- in_test_vpc.instances is not defined
|
||||
- in_test_vpc.instance_ids is defined
|
||||
- in_test_vpc.instance_ids | length > 0
|
||||
- name: New instance and don't wait for it to complete ( check mode )
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
image_id: "{{ ec2_ami_image }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: "{{ ec2_instance_type }}"
|
||||
check_mode: yes
|
||||
|
||||
- name: New instance and don't wait for it to complete ( check mode )
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: t2.micro
|
||||
<<: *aws_connection_info
|
||||
check_mode: yes
|
||||
- name: Facts for ec2 test instance
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
||||
register: real_instance_fact
|
||||
until: real_instance_fact.instances | length > 0
|
||||
retries: 10
|
||||
|
||||
- name: Facts for ec2 test instance
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
||||
<<: *aws_connection_info
|
||||
register: real_instance_fact
|
||||
until: real_instance_fact.instances | length > 0
|
||||
retries: 10
|
||||
- name: Facts for checkmode ec2 test instance
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
register: checkmode_instance_fact
|
||||
|
||||
- name: Facts for checkmode ec2 test instance
|
||||
ec2_instance_info:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
<<: *aws_connection_info
|
||||
register: checkmode_instance_fact
|
||||
- name: "Confirm whether the check mode is working normally."
|
||||
assert:
|
||||
that:
|
||||
- "{{ real_instance_fact.instances | length }} > 0"
|
||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||
|
||||
- name: "Confirm whether the check mode is working normally."
|
||||
assert:
|
||||
that:
|
||||
- "{{ real_instance_fact.instances | length }} > 0"
|
||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||
- name: Terminate instances
|
||||
ec2_instance:
|
||||
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
||||
state: absent
|
||||
|
||||
always:
|
||||
- name: Terminate test-ebs-vols instances
|
||||
ec2_instance:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
state: absent
|
||||
wait: no
|
||||
ignore_errors: yes
|
||||
|
@ -0,0 +1,27 @@
|
||||
---
|
||||
- set_fact:
|
||||
virtualenv: "{{ remote_tmp_dir }}/virtualenv"
|
||||
virtualenv_command: "{{ ansible_python_interpreter }} -m virtualenv"
|
||||
|
||||
- set_fact:
|
||||
virtualenv_interpreter: "{{ virtualenv }}/bin/python"
|
||||
|
||||
- pip:
|
||||
name: virtualenv
|
||||
|
||||
- pip:
|
||||
name:
|
||||
- 'botocore<1.10.16'
|
||||
- boto3
|
||||
- coverage
|
||||
virtualenv: "{{ virtualenv }}"
|
||||
virtualenv_command: "{{ virtualenv_command }}"
|
||||
virtualenv_site_packages: no
|
||||
|
||||
- include_tasks: version_fail.yml
|
||||
vars:
|
||||
ansible_python_interpreter: "{{ virtualenv_interpreter }}"
|
||||
|
||||
- file:
|
||||
path: "{{ virtualenv }}"
|
||||
state: absent
|
Loading…
Reference in New Issue