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
|
cloud/aws
|
||||||
shippable/aws/group2
|
#shippable/aws/group2
|
||||||
unstable
|
unsupported
|
||||||
|
@ -1,79 +1,80 @@
|
|||||||
- name: set connection information for all tasks
|
- block:
|
||||||
set_fact:
|
- name: New instance with an extra block device
|
||||||
aws_connection_info: &aws_connection_info
|
ec2_instance:
|
||||||
aws_access_key: "{{ aws_access_key }}"
|
name: "{{ resource_prefix }}-test-ebs-vols"
|
||||||
aws_secret_key: "{{ aws_secret_key }}"
|
image_id: "{{ ec2_ami_image }}"
|
||||||
security_token: "{{ security_token }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
region: "{{ aws_region }}"
|
volumes:
|
||||||
no_log: true
|
- 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
|
- name: Gather instance info
|
||||||
ec2_instance:
|
ec2_instance_info:
|
||||||
name: "{{ resource_prefix }}-test-ebs-vols"
|
filters:
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
register: in_test_vpc_instance
|
||||||
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
|
- assert:
|
||||||
ec2_instance_info:
|
that:
|
||||||
filters:
|
- in_test_vpc is not failed
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
- in_test_vpc is changed
|
||||||
<<: *aws_connection_info
|
- in_test_vpc_instance.instances[0].block_device_mappings[0]
|
||||||
register: in_test_vpc_instance
|
- 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:
|
- name: New instance with an extra block device(check mode)
|
||||||
that:
|
ec2_instance:
|
||||||
- in_test_vpc is not failed
|
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||||
- in_test_vpc is changed
|
image_id: "{{ ec2_ami_image }}"
|
||||||
- in_test_vpc_instance.instances[0].block_device_mappings[0]
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
- in_test_vpc_instance.instances[0].block_device_mappings[1]
|
volumes:
|
||||||
- in_test_vpc_instance.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
|
- 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)
|
- name: "fact presented ec2 instance"
|
||||||
ec2_instance:
|
ec2_instance_info:
|
||||||
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
filters:
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
"instance-state-name": "running"
|
||||||
volumes:
|
register: presented_instance_fact
|
||||||
- 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"
|
- name: "fact checkmode ec2 instance"
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||||
"instance-state-name": "running"
|
register: checkmode_instance_fact
|
||||||
<<: *aws_connection_info
|
|
||||||
register: presented_instance_fact
|
|
||||||
|
|
||||||
- name: "fact checkmode ec2 instance"
|
- name: "Confirm whether the check mode is working normally."
|
||||||
ec2_instance_info:
|
assert:
|
||||||
filters:
|
that:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
- "{{ presented_instance_fact.instances | length }} > 0"
|
||||||
<<: *aws_connection_info
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||||
register: checkmode_instance_fact
|
|
||||||
|
|
||||||
- name: "Confirm whether the check mode is working normally."
|
- name: Terminate instances
|
||||||
assert:
|
ec2_instance:
|
||||||
that:
|
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
||||||
- "{{ presented_instance_fact.instances | length }} > 0"
|
state: absent
|
||||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
|
||||||
|
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
|
- block:
|
||||||
set_fact:
|
- name: Make EBS optimized instance in the testing subnet of the test VPC
|
||||||
aws_connection_info: &aws_connection_info
|
ec2_instance:
|
||||||
aws_access_key: "{{ aws_access_key }}"
|
name: "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||||
aws_secret_key: "{{ aws_secret_key }}"
|
image_id: "{{ ec2_ami_image }}"
|
||||||
security_token: "{{ security_token }}"
|
tags:
|
||||||
region: "{{ aws_region }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
no_log: true
|
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
|
- name: Get ec2 instance info
|
||||||
ec2_instance:
|
ec2_instance_info:
|
||||||
name: "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
filters:
|
||||||
image_id: "{{ ec2_ebs_optimized_ami_image[aws_region] }}"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||||
tags:
|
register: ebs_opt_instance_info
|
||||||
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
|
- name: Assert instance is ebs_optimized
|
||||||
ec2_instance_info:
|
assert:
|
||||||
filters:
|
that:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
- "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}"
|
||||||
<<: *aws_connection_info
|
|
||||||
register: ebs_opt_instance_info
|
|
||||||
|
|
||||||
- name: Assert instance is ebs_optimized
|
- name: Terminate instances
|
||||||
assert:
|
ec2_instance:
|
||||||
that:
|
instance_ids: "{{ ebs_opt_in_vpc.instance_ids }}"
|
||||||
- "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}"
|
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
|
- block:
|
||||||
set_fact:
|
- name: New instance and don't wait for it to complete
|
||||||
aws_connection_info: &aws_connection_info
|
ec2_instance:
|
||||||
aws_access_key: "{{ aws_access_key }}"
|
name: "{{ resource_prefix }}-test-no-wait"
|
||||||
aws_secret_key: "{{ aws_secret_key }}"
|
image_id: "{{ ec2_ami_image }}"
|
||||||
security_token: "{{ security_token }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
region: "{{ aws_region }}"
|
tags:
|
||||||
no_log: true
|
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
|
- assert:
|
||||||
ec2_instance:
|
that:
|
||||||
name: "{{ resource_prefix }}-test-no-wait"
|
- in_test_vpc is not failed
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
- in_test_vpc is changed
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
- in_test_vpc.instances is not defined
|
||||||
tags:
|
- in_test_vpc.instance_ids is defined
|
||||||
TestId: "{{ resource_prefix }}"
|
- in_test_vpc.instance_ids | length > 0
|
||||||
wait: false
|
|
||||||
instance_type: t2.micro
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: in_test_vpc
|
|
||||||
|
|
||||||
- assert:
|
- name: New instance and don't wait for it to complete ( check mode )
|
||||||
that:
|
ec2_instance:
|
||||||
- in_test_vpc is not failed
|
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||||
- in_test_vpc is changed
|
image_id: "{{ ec2_ami_image }}"
|
||||||
- in_test_vpc.instances is not defined
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
- in_test_vpc.instance_ids is defined
|
tags:
|
||||||
- in_test_vpc.instance_ids | length > 0
|
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 )
|
- name: Facts for ec2 test instance
|
||||||
ec2_instance:
|
ec2_instance_info:
|
||||||
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
filters:
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
register: real_instance_fact
|
||||||
tags:
|
until: real_instance_fact.instances | length > 0
|
||||||
TestId: "{{ resource_prefix }}"
|
retries: 10
|
||||||
wait: false
|
|
||||||
instance_type: t2.micro
|
|
||||||
<<: *aws_connection_info
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: Facts for ec2 test instance
|
- name: Facts for checkmode ec2 test instance
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||||
<<: *aws_connection_info
|
register: checkmode_instance_fact
|
||||||
register: real_instance_fact
|
|
||||||
until: real_instance_fact.instances | length > 0
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: Facts for checkmode ec2 test instance
|
- name: "Confirm whether the check mode is working normally."
|
||||||
ec2_instance_info:
|
assert:
|
||||||
filters:
|
that:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
- "{{ real_instance_fact.instances | length }} > 0"
|
||||||
<<: *aws_connection_info
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||||
register: checkmode_instance_fact
|
|
||||||
|
|
||||||
- name: "Confirm whether the check mode is working normally."
|
- name: Terminate instances
|
||||||
assert:
|
ec2_instance:
|
||||||
that:
|
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
||||||
- "{{ real_instance_fact.instances | length }} > 0"
|
state: absent
|
||||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
|
||||||
|
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