Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_instance test cleanup #63708

Merged
merged 14 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
132 changes: 110 additions & 22 deletions lib/ansible/modules/cloud/amazon/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
instance_ids:
description:
- If you specify one or more instance IDs, only instances that have the specified IDs are returned.
type: list
state:
description:
- Goal state for the instances.
choices: [present, terminated, running, started, stopped, restarted, rebooted, absent]
default: present
type: str
wait:
description:
- Whether or not to wait for the desired state (use wait_timeout to customize this).
Expand All @@ -38,33 +40,41 @@
description:
- How long to wait (in seconds) for the instance to finish booting/terminating.
default: 600
type: int
instance_type:
description:
- Instance type to use for the instance, see U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html)
Only required when instance is not already present.
default: t2.micro
type: str
user_data:
description:
- Opaque blob of data which is made available to the ec2 instance
type: str
tower_callback:
description:
- Preconfigured user-data to enable an instance to perform a Tower callback (Linux only).
- Mutually exclusive with I(user_data).
- For Windows instances, to enable remote access via Ansible set I(tower_callback.windows) to true, and optionally set an admin password.
- If using 'windows' and 'set_password', callback to Tower will not be performed but the instance will be ready to receive winrm connections from Ansible.
type: dict
suboptions:
tower_address:
description:
- IP address or DNS name of Tower server. Must be accessible via this address from the VPC that this instance will be launched in.
type: str
job_template_id:
description:
- Either the integer ID of the Tower Job Template, or the name (name supported only for Tower 3.2+).
type: str
host_config_key:
description:
- Host configuration secret key generated by the Tower job template.
type: str
tags:
description:
- A hash/dictionary of tags to add to the new instance or to add/remove from an existing one.
type: dict
purge_tags:
description:
- Delete any tags not specified in the task that are on the instance.
Expand All @@ -75,65 +85,136 @@
description:
- An image to use for the instance. The M(ec2_ami_info) module may be used to retrieve images.
One of I(image) or I(image_id) are required when instance is not already present.
- Complex object containing I(image.id), I(image.ramdisk), and I(image.kernel).
- I(image.id) is the AMI ID.
- I(image.ramdisk) overrides the AMI's default ramdisk ID.
- I(image.kernel) is a string AKI to override the AMI kernel.
type: dict
suboptions:
id:
description:
- The AMI ID.
type: str
ramdisk:
description:
- Overrides the AMI's default ramdisk ID.
type: str
kernel:
description:
- a string AKI to override the AMI kernel.
image_id:
description:
- I(ami) ID to use for the instance. One of I(image) or I(image_id) are required when instance is not already present.
- This is an alias for I(image.id).
type: str
security_groups:
description:
- A list of security group IDs or names (strings). Mutually exclusive with I(security_group).
type: list
security_group:
description:
- A security group ID or name. Mutually exclusive with I(security_groups).
type: str
name:
description:
- The Name tag for the instance.
type: str
vpc_subnet_id:
description:
- The subnet ID in which to launch the instance (VPC)
If none is provided, ec2_instance will chose the default zone of the default VPC.
aliases: ['subnet_id']
type: str
network:
description:
- Either a dictionary containing the key 'interfaces' corresponding to a list of network interface IDs or
containing specifications for a single network interface.
- If specifications for a single network are given, accepted keys are assign_public_ip (bool),
private_ip_address (str), ipv6_addresses (list), source_dest_check (bool), description (str),
delete_on_termination (bool), device_index (int), groups (list of security group IDs),
private_ip_addresses (list), subnet_id (str).
- I(network.interfaces) should be a list of ENI IDs (strings) or a list of objects containing the key I(id).
- Use the ec2_eni to create ENIs with special settings.
- Use the ec2_eni module to create ENIs with special settings.
type: dict
suboptions:
interfaces:
tremble marked this conversation as resolved.
Show resolved Hide resolved
description:
- a list of ENI IDs (strings) or a list of objects containing the key I(id).
type: list
assign_public_ip:
description:
- when true assigns a public IP address to the interface
type: bool
private_ip_address:
description:
- an IPv4 address to assign to the interface
type: str
ipv6_addresses:
description:
- a list of IPv6 addresses to assign to the network interface
type: list
source_dest_check:
description:
- controls whether source/destination checking is enabled on the interface
type: bool
description:
description:
- a description for the network interface
type: str
private_ip_addresses:
description:
- a list of IPv4 addresses to assign to the network interface
type: list
subnet_id:
description:
- the subnet to connect the network interface to
type: str
delete_on_termination:
description:
- Delete the interface when the instance it is attached to is
terminated.
type: bool
device_index:
description:
- The index of the interface to modify
type: int
groups:
description:
- a list of security group IDs to attach to the interface
type: list
volumes:
description:
- A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage.
- A mapping contains the (optional) keys device_name, virtual_name, ebs.volume_type, ebs.volume_size, ebs.kms_key_id,
ebs.iops, and ebs.delete_on_termination.
- For more information about each parameter, see U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html).
type: list
launch_template:
description:
- The EC2 launch template to base instance configuration on.
- I(launch_template.id) the ID or the launch template (optional if name is specified).
- I(launch_template.name) the pretty name of the launch template (optional if id is specified).
- I(launch_template.version) the specific version of the launch template to use. If unspecified, the template default is chosen.
type: dict
suboptions:
id:
description:
- the ID of the launch template (optional if name is specified).
type: str
name:
description:
- the pretty name of the launch template (optional if id is specified).
type: str
version:
description:
- the specific version of the launch template to use. If unspecified, the template default is chosen.
key_name:
description:
- Name of the SSH access key to assign to the instance - must exist in the region the instance is created.
type: str
availability_zone:
description:
- Specify an availability zone to use the default subnet it. Useful if not specifying the I(vpc_subnet_id) parameter.
- If no subnet, ENI, or availability zone is provided, the default subnet in the default VPC will be used in the first AZ (alphabetically sorted).
type: str
instance_initiated_shutdown_behavior:
description:
- Whether to stop or terminate an instance upon shutdown.
choices: ['stop', 'terminate']
type: str
tenancy:
description:
- What type of tenancy to allow an instance to use. Default is shared tenancy. Dedicated tenancy will incur additional charges.
choices: ['dedicated', 'default']
type: str
termination_protection:
description:
- Whether to enable termination protection.
Expand All @@ -143,24 +224,28 @@
description:
- For T2 series instances, choose whether to allow increased charges to buy CPU credits if the default pool is depleted.
- Choose I(unlimited) to enable buying additional CPU credits.
choices: [unlimited, standard]
choices: ['unlimited', 'standard']
type: str
cpu_options:
description:
- Reduce the number of vCPU exposed to the instance.
- Those parameters can only be set at instance launch. The two suboptions threads_per_core and core_count are mandatory.
- See U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html) for combinations available.
- Requires botocore >= 1.10.16
version_added: 2.7
type: dict
suboptions:
threads_per_core:
description:
- Select the number of threads per core to enable. Disable or Enable Intel HT.
choices: [1, 2]
required: true
type: int
core_count:
description:
- Set the number of core to enable.
required: true
type: int
detailed_monitoring:
description:
- Whether to allow detailed cloudwatch metrics to be collected, enabling more detailed alerting.
Expand All @@ -175,19 +260,21 @@
consists of a filter key and a filter value. See
U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html).
for possible filters. Filter names and values are case sensitive.
By default, instances are filtered for counting by their "Name" tag, base AMI, state (running, by default), and
- By default, instances are filtered for counting by their "Name" tag, base AMI, state (running, by default), and
subnet ID. Any queryable filter can be used. Good candidates are specific tags, SSH keys, or security groups.
default: {"tag:Name": "<provided-Name-attribute>", "subnet-id": "<provided-or-default subnet>"}
type: dict
instance_role:
description:
- The ARN or name of an EC2-enabled instance role to be used. If a name is not provided in arn format
then the ListInstanceProfiles permission must also be granted.
U(https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfiles.html) If no full ARN is provided,
the role with a matching name will be used from the active AWS account.
type: str
placement_group:
description:
- The placement group that needs to be assigned to the instance
version_added: 2.8
type: str

extends_documentation_fragment:
- aws
Expand Down Expand Up @@ -493,13 +580,14 @@
ipv6_addresses:
description: One or more IPv6 addresses associated with the network interface.
returned: always
type: complex
type: list
elements: dict
contains:
- ipv6_address:
description: The IPv6 address.
returned: always
type: str
sample: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
ipv6_address:
description: The IPv6 address.
returned: always
type: str
sample: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
mac_address:
description: The MAC address.
returned: always
Expand Down
15 changes: 9 additions & 6 deletions lib/ansible/modules/cloud/amazon/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
- If you specify one or more instance IDs, only instances that have the specified IDs are returned.
required: false
version_added: 2.4
type: list
filters:
description:
- A dict of filters to apply. Each dict item consists of a filter key and a filter value. See
U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html) for possible filters. Filter
names and values are case sensitive.
required: false
default: {}
type: dict

extends_documentation_fragment:
- aws
Expand Down Expand Up @@ -279,13 +281,14 @@
ipv6_addresses:
description: One or more IPv6 addresses associated with the network interface.
returned: always
type: complex
type: list
elements: dict
contains:
- ipv6_address:
description: The IPv6 address.
returned: always
type: str
sample: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
ipv6_address:
description: The IPv6 address.
returned: always
type: str
sample: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
mac_address:
description: The MAC address.
returned: always
Expand Down
5 changes: 3 additions & 2 deletions test/integration/targets/ec2_instance/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ec2_instance_info
cloud/aws
shippable/aws/group2
unstable
#shippable/aws/group2
unsupported
27 changes: 9 additions & 18 deletions test/integration/targets/ec2_instance/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@
# 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
ec2_instance_type: 't3.micro'
ec2_ami_name: 'amzn2-ami-hvm-2.*-x86_64-gp2'

# We need to use ENA enabled AMIs to get EBS optimized instances.
ec2_ebs_optimized_ami_image: "{{ ec2_ami_image }}"
vpc_name: '{{ resource_prefix }}-vpc'
vpc_seed: '{{ resource_prefix }}'
vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.0.0/16'
subnet_a_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.32.0/24'
subnet_a_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.32.'
subnet_b_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.33.0/24'
subnet_b_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.33.'