Removed nested role for ec2_instance tests
Also moved environment setup and environment cleanup to separate task files Added CI group Updated c4.large instances to t3.nano, use ENA enabled AMI Updated AMIs with Amazon Linux AMI Updated us-east-1 AMI id Specify EBS size typo, volume_size Removed 'state: running', updated AMI with amz ami Also added several wait: false to speed things up Check for instance state, correctly Accept pending as valid state tags_and_vpc_settings do not wait for instance to complete wait for termination protected instance Updated IAM role name to match with policy Skip env cleanup when in CI Do not wait instance in external_resource_attach ENI remove is done in env_cleanup/CI wait some time for instance_profile instnace to be up Updated ebs_optimized_images Corrected task name Added aws_cleanup var in cloud-config-aws typo in runme default aws_cleanup to true
This commit is contained in:
parent
30a7670f36
commit
da1a621bd9
23 changed files with 336 additions and 384 deletions
|
@ -16,6 +16,10 @@ aws_access_key: @ACCESS_KEY
|
||||||
aws_secret_key: @SECRET_KEY
|
aws_secret_key: @SECRET_KEY
|
||||||
security_token: @SECURITY_TOKEN
|
security_token: @SECURITY_TOKEN
|
||||||
aws_region: @REGION
|
aws_region: @REGION
|
||||||
|
# aws_cleanup controls whether the environment is cleaned up after tests have completed
|
||||||
|
# This only applies to tests that have a cleanup stage
|
||||||
|
# Defaults to true when using this template
|
||||||
|
# aws_cleanup: true
|
||||||
# aliases for backwards compatibility with older integration test playbooks
|
# aliases for backwards compatibility with older integration test playbooks
|
||||||
ec2_access_key: {{ aws_access_key }}
|
ec2_access_key: {{ aws_access_key }}
|
||||||
ec2_secret_key: {{ aws_secret_key }}
|
ec2_secret_key: {{ aws_secret_key }}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cloud/aws
|
cloud/aws
|
||||||
unsupported
|
shippable/aws/group2
|
||||||
|
|
23
test/integration/targets/ec2_instance/defaults/main.yml
Normal file
23
test/integration/targets/ec2_instance/defaults/main.yml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
---
|
||||||
|
# defaults file for ec2_instance
|
||||||
|
ec2_instance_name: '{{ resource_prefix }}-node'
|
||||||
|
ec2_instance_owner: 'integration-run-{{ resource_prefix }}'
|
||||||
|
ec2_ami_image:
|
||||||
|
# Amazon Linux - collected 2019-05-10
|
||||||
|
ap-northeast-1: ami-086063d8c95bfa211
|
||||||
|
ap-northeast-2: ami-04a1d511fd8937540
|
||||||
|
ap-south-1: ami-0d1ca7565b637e9a5
|
||||||
|
ap-southeast-1: ami-07dd66a9764fbb937
|
||||||
|
ap-southeast-2: ami-0ca7144d77a93c7a8
|
||||||
|
ca-central-1: ami-0e5e1c6b373fed93b
|
||||||
|
eu-central-1: ami-05ba799ee5fc165db
|
||||||
|
eu-west-1: ami-055ff4f3e62e8e65e
|
||||||
|
eu-west-2: ami-072edd63fd2b95ca7
|
||||||
|
sa-east-1: ami-0c0698b4027cd5931
|
||||||
|
us-east-1: ami-0771c28c5580e5716
|
||||||
|
us-east-2: ami-063225b63017efd17
|
||||||
|
us-west-1: ami-04abfbe0050a1ef1d
|
||||||
|
us-west-2: ami-027c5e2ccf2970def
|
||||||
|
|
||||||
|
# We need to use ENA enabled AMIs to get EBS optimized instances.
|
||||||
|
ec2_ebs_optimized_ami_image: "{{ ec2_ami_image }}"
|
|
@ -1,36 +0,0 @@
|
||||||
---
|
|
||||||
# defaults file for ec2_instance
|
|
||||||
ec2_instance_name: '{{resource_prefix}}-node'
|
|
||||||
ec2_instance_owner: 'integration-run-{{resource_prefix}}'
|
|
||||||
ec2_ami_image:
|
|
||||||
# https://wiki.centos.org/Cloud/AWS collected 2018-01-10
|
|
||||||
ap-northeast-1: ami-571e3c30
|
|
||||||
ap-northeast-2: ami-97cb19f9
|
|
||||||
ap-south-1: ami-11f0837e
|
|
||||||
ap-southeast-1: ami-30318f53
|
|
||||||
ap-southeast-2: ami-24959b47
|
|
||||||
ca-central-1: ami-daeb57be
|
|
||||||
eu-central-1: ami-7cbc6e13
|
|
||||||
eu-west-1: ami-0d063c6b
|
|
||||||
eu-west-2: ami-c22236a6
|
|
||||||
sa-east-1: ami-864f2dea
|
|
||||||
us-east-1: ami-ae7bfdb8
|
|
||||||
us-east-2: ami-9cbf9bf9
|
|
||||||
us-west-1: ami-7c280d1c
|
|
||||||
us-west-2: ami-0c2aba6c
|
|
||||||
# We need to use ENA enabled AMIs to get EBS optimized instances.
|
|
||||||
ec2_ebs_optimized_ami_image:
|
|
||||||
ap-northeast-1: ami-00f9d04b3b3092052
|
|
||||||
ap-northeast-2: ami-0c764df09c35858b8
|
|
||||||
ap-south-1: ami-00796998f258969fd
|
|
||||||
ap-southeast-1: ami-085fd1bd447be68e8
|
|
||||||
ap-southeast-2: ami-0b8dea0e70b969adc
|
|
||||||
ca-central-1: ami-05cac140c6a1fb960
|
|
||||||
eu-central-1: ami-02ea8f348fa28c108
|
|
||||||
eu-west-1: ami-0a5e707736615003c
|
|
||||||
eu-west-2: ami-017b0e29fac27906b
|
|
||||||
sa-east-1: ami-0160a8b6087883cb6
|
|
||||||
us-east-1: ami-013be31976ca2c322
|
|
||||||
us-east-2: ami-0350c5670171b5391
|
|
||||||
us-west-1: ami-01beb64058d271bc4
|
|
||||||
us-west-2: ami-061e7ebbc234015fe
|
|
|
@ -1,208 +0,0 @@
|
||||||
---
|
|
||||||
# A Note about ec2 environment variable name preference:
|
|
||||||
# - EC2_URL -> AWS_URL
|
|
||||||
# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY
|
|
||||||
# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY
|
|
||||||
# - EC2_REGION -> AWS_REGION
|
|
||||||
#
|
|
||||||
|
|
||||||
# - include: ../../../../../setup_ec2/tasks/common.yml module_name: ec2_instance
|
|
||||||
|
|
||||||
- block:
|
|
||||||
|
|
||||||
# ============================================================
|
|
||||||
- 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
|
|
||||||
|
|
||||||
- name: Create VPC for use in testing
|
|
||||||
ec2_vpc_net:
|
|
||||||
name: "{{ resource_prefix }}-vpc"
|
|
||||||
cidr_block: 10.22.32.0/23
|
|
||||||
tags:
|
|
||||||
Name: Ansible ec2_instance Testing VPC
|
|
||||||
tenancy: default
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: testing_vpc
|
|
||||||
|
|
||||||
- name: Create internet gateway for use in testing
|
|
||||||
ec2_vpc_igw:
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
state: present
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: igw
|
|
||||||
|
|
||||||
- name: Create default subnet in zone A
|
|
||||||
ec2_vpc_subnet:
|
|
||||||
state: present
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
cidr: 10.22.32.0/24
|
|
||||||
az: "{{ aws_region }}a"
|
|
||||||
resource_tags:
|
|
||||||
Name: "{{ resource_prefix }}-subnet-a"
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: testing_subnet_a
|
|
||||||
|
|
||||||
- name: Create secondary subnet in zone B
|
|
||||||
ec2_vpc_subnet:
|
|
||||||
state: present
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
cidr: 10.22.33.0/24
|
|
||||||
az: "{{ aws_region }}b"
|
|
||||||
resource_tags:
|
|
||||||
Name: "{{ resource_prefix }}-subnet-b"
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: testing_subnet_b
|
|
||||||
|
|
||||||
- name: create routing rules
|
|
||||||
ec2_vpc_route_table:
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
tags:
|
|
||||||
created: "{{ resource_prefix }}-route"
|
|
||||||
routes:
|
|
||||||
- dest: 0.0.0.0/0
|
|
||||||
gateway_id: "{{ igw.gateway_id }}"
|
|
||||||
subnets:
|
|
||||||
- "{{ testing_subnet_a.subnet.id }}"
|
|
||||||
- "{{ testing_subnet_b.subnet.id }}"
|
|
||||||
<<: *aws_connection_info
|
|
||||||
|
|
||||||
- name: create a security group with the vpc
|
|
||||||
ec2_group:
|
|
||||||
name: "{{ resource_prefix }}-sg"
|
|
||||||
description: a security group for ansible tests
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
rules:
|
|
||||||
- proto: tcp
|
|
||||||
from_port: 22
|
|
||||||
to_port: 22
|
|
||||||
cidr_ip: 0.0.0.0/0
|
|
||||||
- proto: tcp
|
|
||||||
from_port: 80
|
|
||||||
to_port: 80
|
|
||||||
cidr_ip: 0.0.0.0/0
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: sg
|
|
||||||
|
|
||||||
- include_tasks: cpu_options.yml
|
|
||||||
- include_tasks: termination_protection.yml
|
|
||||||
- include_tasks: tags_and_vpc_settings.yml
|
|
||||||
- include_tasks: external_resource_attach.yml
|
|
||||||
- include_tasks: block_devices.yml
|
|
||||||
- include_tasks: default_vpc_tests.yml
|
|
||||||
- include_tasks: iam_instance_role.yml
|
|
||||||
- include_tasks: checkmode_tests.yml
|
|
||||||
- include_tasks: ebs_optimized.yml
|
|
||||||
- include_tasks: instance_no_wait.yml
|
|
||||||
|
|
||||||
# ============================================================
|
|
||||||
|
|
||||||
always:
|
|
||||||
- name: remove any instances in the test VPC
|
|
||||||
ec2_instance:
|
|
||||||
filters:
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
state: absent
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove ENIs
|
|
||||||
ec2_eni_info:
|
|
||||||
filters:
|
|
||||||
vpc-id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: enis
|
|
||||||
|
|
||||||
- name: delete all ENIs
|
|
||||||
ec2_eni:
|
|
||||||
eni_id: "{{ item.id }}"
|
|
||||||
state: absent
|
|
||||||
<<: *aws_connection_info
|
|
||||||
until: removed is not failed
|
|
||||||
with_items: "{{ enis.network_interfaces }}"
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove the security group
|
|
||||||
ec2_group:
|
|
||||||
name: "{{ resource_prefix }}-sg"
|
|
||||||
description: a security group for ansible tests
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
state: absent
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove routing rules
|
|
||||||
ec2_vpc_route_table:
|
|
||||||
state: absent
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
tags:
|
|
||||||
created: "{{ resource_prefix }}-route"
|
|
||||||
routes:
|
|
||||||
- dest: 0.0.0.0/0
|
|
||||||
gateway_id: "{{ igw.gateway_id }}"
|
|
||||||
subnets:
|
|
||||||
- "{{ testing_subnet_a.subnet.id }}"
|
|
||||||
- "{{ testing_subnet_b.subnet.id }}"
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove internet gateway
|
|
||||||
ec2_vpc_igw:
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
state: absent
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove subnet A
|
|
||||||
ec2_vpc_subnet:
|
|
||||||
state: absent
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
cidr: 10.22.32.0/24
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove subnet B
|
|
||||||
ec2_vpc_subnet:
|
|
||||||
state: absent
|
|
||||||
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
||||||
cidr: 10.22.33.0/24
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
- name: remove the VPC
|
|
||||||
ec2_vpc_net:
|
|
||||||
name: "{{ resource_prefix }}-vpc"
|
|
||||||
cidr_block: 10.22.32.0/23
|
|
||||||
state: absent
|
|
||||||
tags:
|
|
||||||
Name: Ansible Testing VPC
|
|
||||||
tenancy: default
|
|
||||||
<<: *aws_connection_info
|
|
||||||
register: removed
|
|
||||||
until: removed is not failed
|
|
||||||
ignore_errors: yes
|
|
||||||
retries: 10
|
|
|
@ -15,16 +15,16 @@
|
||||||
region: "{{ aws_region }}"
|
region: "{{ aws_region }}"
|
||||||
no_log: True
|
no_log: True
|
||||||
|
|
||||||
- name: Include vars file in roles/ec2_instance/defaults/main.yml
|
- name: Include vars file in {{ playbook_dir }}../defaults/main.yml
|
||||||
include_vars:
|
include_vars:
|
||||||
file: 'roles/ec2_instance/defaults/main.yml'
|
file: '{{ playbook_dir }}/../defaults/main.yml'
|
||||||
|
|
||||||
- name: create c4.large with cpu options (fails gracefully)
|
- name: create t3.nano with cpu options (fails gracefully)
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
state: present
|
state: present
|
||||||
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-ec2"
|
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-ec2"
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
instance_type: c4.large
|
instance_type: t3.nano
|
||||||
cpu_options:
|
cpu_options:
|
||||||
core_count: 1
|
core_count: 1
|
||||||
threads_per_core: 1
|
threads_per_core: 1
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
export ANSIBLE_ROLES_PATH=../
|
export ANSIBLE_ROLES_PATH=../../targets/
|
||||||
|
|
||||||
# Test graceful failure for older versions of botocore
|
# Test graceful failure for older versions of botocore
|
||||||
source virtualenv.sh
|
source virtualenv.sh
|
||||||
pip install 'botocore<1.10.16' 'boto3<1.7.16'
|
pip install 'botocore<1.10.16' 'boto3<1.7.16'
|
||||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -v playbooks/version_fail.yml "$@"
|
ansible-playbook -v playbooks/version_fail.yml "$@"
|
||||||
|
|
||||||
# Run full test suite
|
# Run full test suite
|
||||||
source virtualenv.sh
|
source virtualenv.sh
|
||||||
pip install 'botocore>=1.10.16' boto3
|
pip install 'botocore>=1.10.16' boto3
|
||||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -v playbooks/full_test.yml "$@"
|
ansible-playbook -v playbooks/full_test.yml "$@"
|
||||||
|
|
|
@ -12,9 +12,6 @@
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
volumes:
|
volumes:
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
- device_name: /dev/sdb
|
- device_name: /dev/sdb
|
||||||
ebs:
|
ebs:
|
||||||
volume_size: 20
|
volume_size: 20
|
||||||
|
@ -23,15 +20,24 @@
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: in_test_vpc
|
register: in_test_vpc
|
||||||
|
|
||||||
|
- name: Gather instance facts
|
||||||
|
ec2_instance_facts:
|
||||||
|
filters:
|
||||||
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: in_test_vpc_instance
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- in_test_vpc is not failed
|
- in_test_vpc is not failed
|
||||||
- in_test_vpc is changed
|
- in_test_vpc is changed
|
||||||
- in_test_vpc.instances[0].block_device_mappings[0]
|
- in_test_vpc_instance.instances[0].block_device_mappings[0]
|
||||||
- in_test_vpc.instances[0].block_device_mappings[1]
|
- in_test_vpc_instance.instances[0].block_device_mappings[1]
|
||||||
- in_test_vpc.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
|
- in_test_vpc_instance.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
|
||||||
|
|
||||||
- name: New instance with an extra block device(check mode)
|
- name: New instance with an extra block device(check mode)
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
|
@ -39,9 +45,6 @@
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
volumes:
|
volumes:
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
- device_name: /dev/sdb
|
- device_name: /dev/sdb
|
||||||
ebs:
|
ebs:
|
||||||
volume_size: 20
|
volume_size: 20
|
||||||
|
@ -57,7 +60,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -65,7 +67,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
|
@ -15,10 +15,7 @@
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||||
volumes:
|
wait: false
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: basic_instance
|
register: basic_instance
|
||||||
|
|
||||||
|
@ -29,10 +26,6 @@
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
|
@ -40,7 +33,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
|
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -48,7 +40,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-checkmode-comparison-checkmode"
|
"tag:Name": "{{ resource_prefix }}-checkmode-comparison-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -78,12 +69,16 @@
|
||||||
that:
|
that:
|
||||||
- '"{{ confirm_checkmode_stopinstance_fact.instances[0].state.name }}" != "stopped"'
|
- '"{{ confirm_checkmode_stopinstance_fact.instances[0].state.name }}" != "stopped"'
|
||||||
|
|
||||||
- name: Stop instance in normaly.
|
- name: Stop instance.
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
name: "{{ resource_prefix }}-checkmode-comparison"
|
name: "{{ resource_prefix }}-checkmode-comparison"
|
||||||
state: stopped
|
state: stopped
|
||||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
|
register: instance_stop
|
||||||
|
until: not instance_stop.failed
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
|
||||||
- name: fact stopped ec2 instance
|
- name: fact stopped ec2 instance
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
|
@ -95,7 +90,7 @@
|
||||||
- name: Verify that it was stopped.
|
- name: Verify that it was stopped.
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- '"{{ confirm_stopinstance_fact.instances[0].state.name }}" == "stopped"'
|
- '"{{ confirm_stopinstance_fact.instances[0].state.name }}" in ["stopped", "stopping"]'
|
||||||
|
|
||||||
- name: Running instance in check mode.
|
- name: Running instance in check mode.
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
|
@ -117,7 +112,7 @@
|
||||||
that:
|
that:
|
||||||
- '"{{ confirm_checkmode_runninginstance_fact.instances[0].state.name }}" != "running"'
|
- '"{{ confirm_checkmode_runninginstance_fact.instances[0].state.name }}" != "running"'
|
||||||
|
|
||||||
- name: Running instance in normaly.
|
- name: Running instance.
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
name: "{{ resource_prefix }}-checkmode-comparison"
|
name: "{{ resource_prefix }}-checkmode-comparison"
|
||||||
state: running
|
state: running
|
||||||
|
@ -156,7 +151,7 @@
|
||||||
that:
|
that:
|
||||||
- '"{{ confirm_checkmode_terminatedinstance_fact.instances[0].state.name }}" != "terminated"'
|
- '"{{ confirm_checkmode_terminatedinstance_fact.instances[0].state.name }}" != "terminated"'
|
||||||
|
|
||||||
- name: Terminate instance in check mode.
|
- name: Terminate instance.
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
name: "{{ resource_prefix }}-checkmode-comparison"
|
name: "{{ resource_prefix }}-checkmode-comparison"
|
||||||
state: absent
|
state: absent
|
|
@ -7,21 +7,18 @@
|
||||||
region: "{{ aws_region }}"
|
region: "{{ aws_region }}"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- name: create c4.large instance with cpu_options
|
- name: create t3.nano instance with cpu_options
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
name: "{{ resource_prefix }}-test-c4large-1-threads-per-core"
|
name: "{{ resource_prefix }}-test-t3nano-1-threads-per-core"
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||||
instance_type: c4.large
|
instance_type: t3.nano
|
||||||
cpu_options:
|
cpu_options:
|
||||||
core_count: 1
|
core_count: 1
|
||||||
threads_per_core: 1
|
threads_per_core: 1
|
||||||
volumes:
|
wait: false
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: instance_creation
|
register: instance_creation
|
||||||
|
|
||||||
|
@ -30,25 +27,20 @@
|
||||||
that:
|
that:
|
||||||
- instance_creation is success
|
- instance_creation is success
|
||||||
- instance_creation is changed
|
- instance_creation is changed
|
||||||
- "instance_creation.instances[0].cpu_options.core_count == 1"
|
|
||||||
- "instance_creation.instances[0].cpu_options.threads_per_core == 1"
|
|
||||||
|
|
||||||
- name: modify cpu_options on existing instance (warning displayed)
|
- name: modify cpu_options on existing instance (warning displayed)
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
state: present
|
state: present
|
||||||
name: "{{ resource_prefix }}-test-c4large-1-threads-per-core"
|
name: "{{ resource_prefix }}-test-t3nano-1-threads-per-core"
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||||
instance_type: c4.large
|
instance_type: t3.nano
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
cpu_options:
|
cpu_options:
|
||||||
core_count: 1
|
core_count: 1
|
||||||
threads_per_core: 2
|
threads_per_core: 2
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: cpu_options_update
|
register: cpu_options_update
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
@ -59,37 +51,31 @@
|
||||||
- cpu_options_update is success
|
- cpu_options_update is success
|
||||||
- cpu_options_update is not changed
|
- cpu_options_update is not changed
|
||||||
|
|
||||||
- name: create c4.large instance with cpu_options(check mode)
|
- name: create t3.nano instance with cpu_options(check mode)
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
name: "{{ resource_prefix }}-test-c4large-1-threads-per-core-checkmode"
|
name: "{{ resource_prefix }}-test-t3nano-1-threads-per-core-checkmode"
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||||
instance_type: c4.large
|
instance_type: t3.nano
|
||||||
cpu_options:
|
cpu_options:
|
||||||
core_count: 1
|
core_count: 1
|
||||||
threads_per_core: 1
|
threads_per_core: 1
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
- name: "fact presented ec2 instance"
|
- name: "fact presented ec2 instance"
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-c4large-1-threads-per-core"
|
"tag:Name": "{{ resource_prefix }}-test-t3nano-1-threads-per-core"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
- name: "fact checkmode ec2 instance"
|
- name: "fact checkmode ec2 instance"
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-c4large-1-threads-per-core-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-t3nano-1-threads-per-core-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -97,4 +83,7 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "{{ presented_instance_fact.instances | length }} > 0"
|
- "{{ presented_instance_fact.instances | length }} > 0"
|
||||||
|
- "'{{ presented_instance_fact.instances.0.state.name }}' in ['running','pending']"
|
||||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||||
|
- "{{ presented_instance_fact.instances.0.cpu_options.core_count }} == 1"
|
||||||
|
- "{{ presented_instance_fact.instances.0.cpu_options.threads_per_core }} == 1"
|
|
@ -14,10 +14,7 @@
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
wait: false
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: in_default_vpc
|
register: in_default_vpc
|
||||||
|
|
||||||
|
@ -29,10 +26,6 @@
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
|
@ -40,7 +33,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-default-vpc"
|
"tag:Name": "{{ resource_prefix }}-test-default-vpc"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -48,7 +40,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-default-vpc-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-default-vpc-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
|
@ -17,18 +17,18 @@
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
ebs_optimized: true
|
ebs_optimized: true
|
||||||
instance_type: t3.nano
|
instance_type: t3.nano
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: ebs_opt_in_vpc
|
register: ebs_opt_in_vpc
|
||||||
|
|
||||||
- name: Get ec2 instance facts
|
- name: Get ec2 instance info
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: ebs_opt_instance_fact
|
register: ebs_opt_instance_info
|
||||||
|
|
||||||
- name: Assert instance is ebs_optimized
|
- name: Assert instance is ebs_optimized
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "{{ ebs_opt_instance_fact.instances.0.ebs_optimized }}"
|
- "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}"
|
112
test/integration/targets/ec2_instance/tasks/env_cleanup.yml
Normal file
112
test/integration/targets/ec2_instance/tasks/env_cleanup.yml
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- name: remove any instances in the test VPC
|
||||||
|
ec2_instance:
|
||||||
|
filters:
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
state: absent
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove ENIs
|
||||||
|
ec2_eni_info:
|
||||||
|
filters:
|
||||||
|
vpc-id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: enis
|
||||||
|
|
||||||
|
- name: delete all ENIs
|
||||||
|
ec2_eni:
|
||||||
|
eni_id: "{{ item.id }}"
|
||||||
|
state: absent
|
||||||
|
<<: *aws_connection_info
|
||||||
|
until: removed is not failed
|
||||||
|
with_items: "{{ enis.network_interfaces }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove the security group
|
||||||
|
ec2_group:
|
||||||
|
name: "{{ resource_prefix }}-sg"
|
||||||
|
description: a security group for ansible tests
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
state: absent
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove routing rules
|
||||||
|
ec2_vpc_route_table:
|
||||||
|
state: absent
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
tags:
|
||||||
|
created: "{{ resource_prefix }}-route"
|
||||||
|
routes:
|
||||||
|
- dest: 0.0.0.0/0
|
||||||
|
gateway_id: "{{ igw.gateway_id }}"
|
||||||
|
subnets:
|
||||||
|
- "{{ testing_subnet_a.subnet.id }}"
|
||||||
|
- "{{ testing_subnet_b.subnet.id }}"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove internet gateway
|
||||||
|
ec2_vpc_igw:
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
state: absent
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove subnet A
|
||||||
|
ec2_vpc_subnet:
|
||||||
|
state: absent
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
cidr: 10.22.32.0/24
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove subnet B
|
||||||
|
ec2_vpc_subnet:
|
||||||
|
state: absent
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
cidr: 10.22.33.0/24
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
- name: remove the VPC
|
||||||
|
ec2_vpc_net:
|
||||||
|
name: "{{ resource_prefix }}-vpc"
|
||||||
|
cidr_block: 10.22.32.0/23
|
||||||
|
state: absent
|
||||||
|
tags:
|
||||||
|
Name: Ansible Testing VPC
|
||||||
|
tenancy: default
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: removed
|
||||||
|
until: removed is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
77
test/integration/targets/ec2_instance/tasks/env_setup.yml
Normal file
77
test/integration/targets/ec2_instance/tasks/env_setup.yml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- name: Create VPC for use in testing
|
||||||
|
ec2_vpc_net:
|
||||||
|
name: "{{ resource_prefix }}-vpc"
|
||||||
|
cidr_block: 10.22.32.0/23
|
||||||
|
tags:
|
||||||
|
Name: Ansible ec2_instance Testing VPC
|
||||||
|
tenancy: default
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: testing_vpc
|
||||||
|
|
||||||
|
- name: Create internet gateway for use in testing
|
||||||
|
ec2_vpc_igw:
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
state: present
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: igw
|
||||||
|
|
||||||
|
- name: Create default subnet in zone A
|
||||||
|
ec2_vpc_subnet:
|
||||||
|
state: present
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
cidr: 10.22.32.0/24
|
||||||
|
az: "{{ aws_region }}a"
|
||||||
|
resource_tags:
|
||||||
|
Name: "{{ resource_prefix }}-subnet-a"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: testing_subnet_a
|
||||||
|
|
||||||
|
- name: Create secondary subnet in zone B
|
||||||
|
ec2_vpc_subnet:
|
||||||
|
state: present
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
cidr: 10.22.33.0/24
|
||||||
|
az: "{{ aws_region }}b"
|
||||||
|
resource_tags:
|
||||||
|
Name: "{{ resource_prefix }}-subnet-b"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: testing_subnet_b
|
||||||
|
|
||||||
|
- name: create routing rules
|
||||||
|
ec2_vpc_route_table:
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
tags:
|
||||||
|
created: "{{ resource_prefix }}-route"
|
||||||
|
routes:
|
||||||
|
- dest: 0.0.0.0/0
|
||||||
|
gateway_id: "{{ igw.gateway_id }}"
|
||||||
|
subnets:
|
||||||
|
- "{{ testing_subnet_a.subnet.id }}"
|
||||||
|
- "{{ testing_subnet_b.subnet.id }}"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
|
||||||
|
- name: create a security group with the vpc
|
||||||
|
ec2_group:
|
||||||
|
name: "{{ resource_prefix }}-sg"
|
||||||
|
description: a security group for ansible tests
|
||||||
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
||||||
|
rules:
|
||||||
|
- proto: tcp
|
||||||
|
from_port: 22
|
||||||
|
to_port: 22
|
||||||
|
cidr_ip: 0.0.0.0/0
|
||||||
|
- proto: tcp
|
||||||
|
from_port: 80
|
||||||
|
to_port: 80
|
||||||
|
cidr_ip: 0.0.0.0/0
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: sg
|
|
@ -44,18 +44,22 @@
|
||||||
availability_zone: '{{ aws_region }}b'
|
availability_zone: '{{ aws_region }}b'
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: in_test_vpc
|
register: in_test_vpc
|
||||||
|
|
||||||
|
- name: "Gather {{ resource_prefix }}-test-eni-vpc facts"
|
||||||
|
ec2_instance_facts:
|
||||||
|
filters:
|
||||||
|
"tag:Name": '{{ resource_prefix }}-test-eni-vpc'
|
||||||
|
<<: *aws_connection_info
|
||||||
|
register: in_test_vpc_instance
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- 'in_test_vpc.instances[0].key_name == "{{ resource_prefix }}_test_key"'
|
- 'in_test_vpc_instance.instances.0.key_name == "{{ resource_prefix }}_test_key"'
|
||||||
- '(in_test_vpc.instances[0].network_interfaces | length) == 1'
|
- '(in_test_vpc_instance.instances.0.network_interfaces | length) == 1'
|
||||||
|
|
||||||
- name: Add a second interface
|
- name: Add a second interface
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
|
@ -68,7 +72,12 @@
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
|
register: add_interface
|
||||||
|
until: add_interface is not failed
|
||||||
|
ignore_errors: yes
|
||||||
|
retries: 10
|
||||||
|
|
||||||
- name: Make instance in the testing subnet created in the test VPC(check mode)
|
- name: Make instance in the testing subnet created in the test VPC(check mode)
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
|
@ -81,10 +90,6 @@
|
||||||
availability_zone: '{{ aws_region }}b'
|
availability_zone: '{{ aws_region }}b'
|
||||||
tags:
|
tags:
|
||||||
TestId: "{{ resource_prefix }}"
|
TestId: "{{ resource_prefix }}"
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
@ -93,7 +98,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-eni-vpc"
|
"tag:Name": "{{ resource_prefix }}-test-eni-vpc"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -101,7 +105,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-eni-vpc-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-eni-vpc-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@
|
||||||
filters:
|
filters:
|
||||||
tag:TestId: "{{ resource_prefix }}"
|
tag:TestId: "{{ resource_prefix }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: result
|
register: result
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -125,6 +129,7 @@
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: result
|
register: result
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -133,13 +138,4 @@
|
||||||
- ec2_key:
|
- ec2_key:
|
||||||
name: "{{ resource_prefix }}_test_key"
|
name: "{{ resource_prefix }}_test_key"
|
||||||
state: absent
|
state: absent
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
|
|
||||||
- ec2_eni:
|
|
||||||
eni_id: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
<<: *aws_connection_info
|
|
||||||
with_items:
|
|
||||||
- "{{ eni_a.interface.id }}"
|
|
||||||
- "{{ eni_b.interface.id }}"
|
|
||||||
- "{{ eni_c.interface.id }}"
|
|
|
@ -10,7 +10,7 @@
|
||||||
- block:
|
- block:
|
||||||
- name: Create IAM role for test
|
- name: Create IAM role for test
|
||||||
iam_role:
|
iam_role:
|
||||||
name: "{{ resource_prefix }}-test-policy"
|
name: "ansible-test-sts-{{ resource_prefix }}-test-policy"
|
||||||
assume_role_policy_document: "{{ lookup('file','assume-role-policy.json') }}"
|
assume_role_policy_document: "{{ lookup('file','assume-role-policy.json') }}"
|
||||||
state: present
|
state: present
|
||||||
create_instance_profile: yes
|
create_instance_profile: yes
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
- name: Create second IAM role for test
|
- name: Create second IAM role for test
|
||||||
iam_role:
|
iam_role:
|
||||||
name: "{{ resource_prefix }}-test-policy-2"
|
name: "ansible-test-sts-{{ resource_prefix }}-test-policy-2"
|
||||||
assume_role_policy_document: "{{ lookup('file','assume-role-policy.json') }}"
|
assume_role_policy_document: "{{ lookup('file','assume-role-policy.json') }}"
|
||||||
state: present
|
state: present
|
||||||
create_instance_profile: yes
|
create_instance_profile: yes
|
||||||
|
@ -36,11 +36,7 @@
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
instance_role: "{{ resource_prefix }}-test-policy"
|
instance_role: "ansible-test-sts-{{ resource_prefix }}-test-policy"
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: instance_with_role
|
register: instance_with_role
|
||||||
|
|
||||||
|
@ -54,11 +50,7 @@
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
instance_role: "{{ resource_prefix }}-test-policy"
|
instance_role: "ansible-test-sts-{{ resource_prefix }}-test-policy"
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
|
@ -66,7 +58,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-instance-role"
|
"tag:Name": "{{ resource_prefix }}-test-instance-role"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -74,7 +65,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-instance-role-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-instance-role-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -90,9 +80,11 @@
|
||||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||||
security_groups: "{{ sg.group_id }}"
|
security_groups: "{{ sg.group_id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
instance_role: "{{ resource_prefix }}-test-policy-2"
|
instance_role: "ansible-test-sts-{{ resource_prefix }}-test-policy-2"
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: instance_with_updated_role
|
register: instance_with_updated_role
|
||||||
|
until: instance_with_updated_role is not failed
|
||||||
|
retries: 10
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
|
@ -120,8 +112,8 @@
|
||||||
- AmazonEC2ContainerServiceRole
|
- AmazonEC2ContainerServiceRole
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
loop:
|
loop:
|
||||||
- "{{ resource_prefix }}-test-policy"
|
- "ansible-test-sts-{{ resource_prefix }}-test-policy"
|
||||||
- "{{ resource_prefix }}-test-policy-2"
|
- "ansible-test-sts-{{ resource_prefix }}-test-policy-2"
|
||||||
register: removed
|
register: removed
|
||||||
until: removed is not failed
|
until: removed is not failed
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
|
@ -43,7 +43,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: real_instance_fact
|
register: real_instance_fact
|
||||||
until: real_instance_fact.instances | length > 0
|
until: real_instance_fact.instances | length > 0
|
||||||
|
@ -53,7 +52,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
27
test/integration/targets/ec2_instance/tasks/main.yml
Normal file
27
test/integration/targets/ec2_instance/tasks/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
---
|
||||||
|
# A Note about ec2 environment variable name preference:
|
||||||
|
# - EC2_URL -> AWS_URL
|
||||||
|
# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY
|
||||||
|
# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY
|
||||||
|
# - EC2_REGION -> AWS_REGION
|
||||||
|
#
|
||||||
|
|
||||||
|
# - include: ../../../../../setup_ec2/tasks/common.yml module_name: ec2_instance
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- include_tasks: env_setup.yml
|
||||||
|
- include_tasks: cpu_options.yml
|
||||||
|
- include_tasks: termination_protection.yml
|
||||||
|
- include_tasks: tags_and_vpc_settings.yml
|
||||||
|
- include_tasks: external_resource_attach.yml
|
||||||
|
- include_tasks: block_devices.yml
|
||||||
|
- include_tasks: default_vpc_tests.yml
|
||||||
|
- include_tasks: iam_instance_role.yml
|
||||||
|
- include_tasks: checkmode_tests.yml
|
||||||
|
- include_tasks: ebs_optimized.yml
|
||||||
|
- include_tasks: instance_no_wait.yml
|
||||||
|
|
||||||
|
always:
|
||||||
|
- include_tasks: env_cleanup.yml
|
||||||
|
when: aws_cleanup
|
|
@ -22,10 +22,7 @@
|
||||||
source_dest_check: false
|
source_dest_check: false
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
wait: false
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: in_test_vpc
|
register: in_test_vpc
|
||||||
|
|
||||||
|
@ -45,10 +42,6 @@
|
||||||
source_dest_check: false
|
source_dest_check: false
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
|
@ -82,7 +75,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create"
|
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -90,7 +82,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -135,10 +126,12 @@
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
|
|
||||||
- ec2_instance_info:
|
- ec2_instance_info:
|
||||||
instance_ids: "{{ add_another_tag.instance_ids }}"
|
instance_ids: "{{ add_another_tag.instance_ids }}"
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: check_tags
|
register: check_tags
|
||||||
|
|
||||||
- name: "Remaking the same instance resulted in no changes"
|
- name: "Remaking the same instance resulted in no changes"
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -149,6 +142,7 @@
|
||||||
filters:
|
filters:
|
||||||
tag:TestId: "{{ resource_prefix }}"
|
tag:TestId: "{{ resource_prefix }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: result
|
register: result
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -156,8 +150,9 @@
|
||||||
|
|
||||||
- name: Terminate instance
|
- name: Terminate instance
|
||||||
ec2_instance:
|
ec2_instance:
|
||||||
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
instance_ids: "{{ add_another_tag.instance_ids }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: result
|
register: result
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -166,11 +161,11 @@
|
||||||
- name: check that subnet-default public IP rule was followed
|
- name: check that subnet-default public IP rule was followed
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- in_test_vpc.instances[0].public_dns_name == ""
|
- check_tags.instances[0].public_dns_name == ""
|
||||||
- in_test_vpc.instances[0].private_ip_address.startswith("10.22.33")
|
- check_tags.instances[0].private_ip_address.startswith("10.22.33")
|
||||||
- in_test_vpc.instances[0].subnet_id == testing_subnet_b.subnet.id
|
- check_tags.instances[0].subnet_id == testing_subnet_b.subnet.id
|
||||||
- name: check that tags were applied
|
- name: check that tags were applied
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- in_test_vpc.instances[0].tags.Name.startswith(resource_prefix)
|
- check_tags.instances[0].tags.Name.startswith(resource_prefix)
|
||||||
- in_test_vpc.instances[0].state.name == 'running'
|
- "'{{ check_tags.instances[0].state.name }}' in ['pending', 'running']"
|
|
@ -16,10 +16,7 @@
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
termination_protection: true
|
termination_protection: true
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
state: running
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: in_test_vpc
|
register: in_test_vpc
|
||||||
|
|
||||||
|
@ -33,10 +30,6 @@
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
termination_protection: true
|
termination_protection: true
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
ebs:
|
|
||||||
delete_on_termination: true
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
|
@ -44,7 +37,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-protected-instance-in-vpc"
|
"tag:Name": "{{ resource_prefix }}-test-protected-instance-in-vpc"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: presented_instance_fact
|
register: presented_instance_fact
|
||||||
|
|
||||||
|
@ -52,7 +44,6 @@
|
||||||
ec2_instance_info:
|
ec2_instance_info:
|
||||||
filters:
|
filters:
|
||||||
"tag:Name": "{{ resource_prefix }}-test-protected-instance-in-vpc-checkmode"
|
"tag:Name": "{{ resource_prefix }}-test-protected-instance-in-vpc-checkmode"
|
||||||
"instance-state-name": "running"
|
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: checkmode_instance_fact
|
register: checkmode_instance_fact
|
||||||
|
|
||||||
|
@ -60,6 +51,7 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "{{ presented_instance_fact.instances | length }} > 0"
|
- "{{ presented_instance_fact.instances | length }} > 0"
|
||||||
|
- "'{{ presented_instance_fact.instances.0.state.name }}' in ['running', 'pending']"
|
||||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||||
|
|
||||||
- name: Try to terminate the instance
|
- name: Try to terminate the instance
|
||||||
|
@ -95,6 +87,7 @@
|
||||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||||
instance_type: t2.micro
|
instance_type: t2.micro
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
register: terminate_results
|
register: terminate_results
|
||||||
- assert:
|
- assert:
|
|
@ -99,6 +99,9 @@ class AwsCloudEnvironment(CloudEnvironment):
|
||||||
|
|
||||||
ansible_vars.update(dict(parser.items('default')))
|
ansible_vars.update(dict(parser.items('default')))
|
||||||
|
|
||||||
|
if 'aws_cleanup' not in ansible_vars:
|
||||||
|
ansible_vars['aws_cleanup'] = not self.managed
|
||||||
|
|
||||||
env_vars = {'ANSIBLE_DEBUG_BOTOCORE_LOGS': 'True'}
|
env_vars = {'ANSIBLE_DEBUG_BOTOCORE_LOGS': 'True'}
|
||||||
|
|
||||||
return CloudEnvironmentConfig(
|
return CloudEnvironmentConfig(
|
||||||
|
|
Loading…
Reference in a new issue