Manage EC2
New in version 2015.8.0.
This module provides an interface to the Elastic Compute Cloud (EC2) service from AWS.
The below code creates a key pair:
create-key-pair:
boto_ec2.key_present:
- name: mykeypair
- save_private: /root/
- region: eu-west-1
- keyid: GKTADJGHEIQSXMKKRBJ08H
- key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
import-key-pair:
boto_ec2.key_present:
- name: mykeypair
- upload_public: 'ssh-rsa AAAA'
- keyid: GKTADJGHEIQSXMKKRBJ08H
- key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
You can also use salt:// in order to define the public key.
import-key-pair:
boto_ec2.key_present:
- name: mykeypair
- upload_public: salt://mybase/public_key.pub
- keyid: GKTADJGHEIQSXMKKRBJ08H
- key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
The below code deletes a key pair:
delete-key-pair:
boto_ec2.key_absent:
- name: mykeypair
- region: eu-west-1
- keyid: GKTADJGHEIQSXMKKRBJ08H
- key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
Ensure the EC2 ENI is absent.
New in version 2016.3.0.
Name tag associated with the ENI.
True/False - release any EIP associated with the ENI
Region to connect to.
Secret key to be used.
Access key to be used.
A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Ensure the EC2 ENI exists.
New in version 2016.3.0.
Name tag associated with the ENI.
The VPC subnet ID the ENI will exist within.
The VPC subnet name the ENI will exist within.
The private ip address to use for this ENI. If this is not specified AWS will automatically assign a private IP address to the ENI. Must be specified at creation time; will be ignored afterward.
Description of the key.
A list of security groups to apply to the ENI.
Boolean specifying whether source/destination checking is enabled on the ENI.
allocate and associate an EIP to the ENI. Could be 'standard' to allocate Elastic IP to EC2 region or 'vpc' to get it for a particular VPC
Changed in version 2016.11.0.
A list of arecord dicts with attributes needed for the DNS add_record state. By default the boto_route53.add_record state will be used, which requires: name, zone, ttl, and identifier. See the boto_route53 state for information about these attributes. Other DNS modules can be called by specifying the provider keyword. By default, the private ENI IP address will be used, set 'public: True' in the arecord dict to use the ENI's public IP address
New in version 2016.3.0.
Region to connect to.
Secret key to be used.
Access key to be used.
A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Ensure an EC2 instance does not exist (is stopped and removed).
Changed in version 2016.11.0.
(string) - The name of the state definition.
(string) - The name of the instance.
(string) - The ID of the instance.
(bool) - Release any associated EIPs during termination.
(string) - Region to connect to.
(string) - Secret key to be used.
(string) - Access key to be used.
(variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
(dict) - A dict of additional filters to use in matching the instance to delete.
YAML example fragment:
- filters:
vpc-id: vpc-abcdef12
Ensure an EC2 instance is running with the given attributes and state.
(string) - The name of the state definition. Recommended that this match the instance_name attribute (generally the FQDN of the instance).
(string) - The name of the instance, generally its FQDN. Exclusive with 'instance_id'.
(string) - The ID of the instance (if known). Exclusive with 'instance_name'.
(string) – The ID of the AMI image to run.
(string) – The name of the AMI image to run.
(dict) - Tags to apply to the instance.
(string) – The name of the key pair with which to launch instances.
(list of strings) – The names of the EC2 classic security groups with which to associate instances
(string) – The Base64-encoded MIME user data to be made available to the instance(s) in this reservation.
(string) – The EC2 instance size/type. Note that only certain types are compatible with HVM based AMIs.
(string) – The Availability Zone to launch the instance into.
(string) – The ID of the kernel with which to launch the instances.
(string) – The ID of the RAM disk with which to launch the instances.
(string) - The ID of a VPC to attach the instance to.
(string) - The name of a VPC to attach the instance to.
(bool) – Enable detailed CloudWatch monitoring on the instance.
(string) – The ID of the subnet within which to launch the instances for VPC.
(string) – The name of the subnet within which to launch the instances for VPC.
(string) – If you’re using VPC, you can optionally use this parameter to assign the instance a specific available IP address from the subnet (e.g., 10.0.0.25).
(boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.
(bool) – If True, the instances will be locked and will not be able to be terminated via the API.
(string) – Specifies whether the instance stops or terminates on instance-initiated shutdown. Valid values are:
'stop'
'terminate'
(string) – If specified, this is the name of the placement group in which the instance(s) will be launched.
(string) – Unique, case-sensitive identifier you provide to ensure idempotency of the request. Maximum 64 ASCII characters.
(list of strings) – The IDs of the VPC security groups with which to associate instances.
(list of strings) – The names of the VPC security groups with which to associate instances.
(string) – Specifies additional information to make available to the instance(s).
(string) – The tenancy of the instance you want to launch. An instance with a tenancy of ‘dedicated’ runs on single-tenant hardware and can only be launched into a VPC. Valid values are:”default” or “dedicated”. NOTE: To use dedicated tenancy you MUST specify a VPC subnet-ID as well.
(string) – The Amazon resource name (ARN) of the IAM Instance Profile (IIP) to associate with the instances.
(string) – The name of the IAM Instance Profile (IIP) to associate with the instances.
(bool) – Whether the instance is optimized for EBS I/O. This optimization provides dedicated throughput to Amazon EBS and a tuned configuration stack to provide optimal EBS I/O performance. This optimization isn’t available with all instance types.
(boto.ec2.networkinterface.NetworkInterfaceCollection) – A NetworkInterfaceCollection data structure containing the ENI specifications for the instance.
(string) - The name of Elastic Network Interface to attach
New in version 2016.11.0.
(string) - The id of Elastic Network Interface to attach
New in version 2016.11.0.
(dict) - Instance attributes and value to be applied to the instance. Available options are:
instanceType - A valid instance type (m1.small)
kernel - Kernel ID (None)
ramdisk - Ramdisk ID (None)
userData - Base64 encoded String (None)
disableApiTermination - Boolean (true)
instanceInitiatedShutdownBehavior - stop|terminate
blockDeviceMapping - List of strings - ie: [‘/dev/sda=false’]
sourceDestCheck - Boolean (true)
groupSet - Set of Security Groups or IDs
ebsOptimized - Boolean (false)
sriovNetSupport - String - ie: ‘simple’
(string) - The desired target state of the instance. Available options are:
running
stopped
Note that this option is currently UNIMPLEMENTED.
(string) - The IP of a previously allocated EIP address, which will be attached to the instance. EC2 Classic instances ONLY - for VCP pass in an allocation_id instead.
(string) - The ID of a previously allocated EIP address, which will be attached to the instance. VPC instances ONLY - for Classic pass in a public_ip instead.
(bool) - Allocate and attach an EIP on-the-fly for this instance. Note you'll want to release this address when terminating the instance, either manually or via the 'release_eip' flag to 'instance_absent'.
(string) - Region to connect to.
(string) - Secret key to be used.
(string) - Access key to be used.
(variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
New in version 2016.3.0.
Deletes a key pair
Ensure key pair is present.
Ensure an ENI does not have secondary private ip addresses associated with it
(String) - State definition name
(String) - The EC2 network interface id, example eni-123456789
(List or String) - The secondary private ip address(es) that should be absent on the ENI.
(string) - Region to connect to.
(string) - Secret key to be used.
(string) - Access key to be used.
(variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Ensure an ENI has secondary private ip addresses associated with it
(String) - State definition name
(String) - The EC2 network interface id, example eni-123456789
(List or String) - The secondary private ip address(es) that should be present on the ENI.
(Boolean) - If true, will reassign a secondary private ip address associated with another ENI. If false, state will fail if the secondary private ip address is associated with another ENI.
(string) - Region to connect to.
(string) - Secret key to be used.
(string) - Access key to be used.
(variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Create a snapshot from the given instance
New in version 2016.3.0.
Ensure the EC2 volume is detached and absent.
New in version 2016.11.0.
State definition name.
Name tag associated with the volume. For safety, if this matches more than one volume, the state will refuse to apply.
Resource ID of the volume.
Only remove volume if it is attached to instance with this Name tag. Exclusive with 'instance_id'. Requires 'device'.
Only remove volume if it is attached to this instance. Exclusive with 'instance_name'. Requires 'device'.
Match by device rather than ID. Requires one of 'instance_name' or 'instance_id'.
Region to connect to.
Secret key to be used.
Access key to be used.
A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Ensure the EC2 volume is present and attached.
State definition name.
The Name tag value for the volume. If no volume with that matching name tag is found, a new volume will be created. If multiple volumes are matched, the state will fail.
Resource ID of the volume. Exclusive with 'volume_name'.
Attach volume to instance with this Name tag. Exclusive with 'instance_id'.
Attach volume to instance with this ID. Exclusive with 'instance_name'.
The device on the instance through which the volume is exposed (e.g. /dev/sdh)
The size of the new volume, in GiB. If you're creating the volume from a snapshot and don't specify a volume size, the default is the snapshot size. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.
The snapshot ID from which the new Volume will be created. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.
The type of the volume. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'. Valid volume types for AWS can be found here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
The provisioned IOPS you want to associate with this volume. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.
Specifies whether the volume should be encrypted. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.
If encrypted is True, this KMS Key ID may be specified to encrypt volume with this key. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'. e.g.: arn:aws:kms:us-east-1:012345678910:key/abcd1234-a123-456a-a12b-a123b4cd56ef
Region to connect to.
Secret key to be used.
Access key to be used.
A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.
Ensure EC2 volume(s) matching the given filters have the defined tags.
New in version 2016.11.0.
State definition name.
List of dicts of filters and tags, where 'filters' is a dict suitable for passing to the 'filters' argument of boto_ec2.get_all_volumes(), and 'tags' is a dict of tags to be set on volumes as matched by the given filters. The filter syntax is extended to permit passing either a list of volume_ids or an instance_name (with instance_name being the Name tag of the instance to which the desired volumes are mapped). Each mapping in the list is applied separately, so multiple sets of volumes can be all tagged differently with one call to this function.
YAML example fragment:
- filters:
attachment.instance_id: i-abcdef12
tags:
Name: dev-int-abcdef12.aws-foo.com
- filters:
attachment.device: /dev/sdf
tags:
ManagedSnapshots: true
BillingGroup: bubba.hotep@aws-foo.com
- filters:
instance_name: prd-foo-01.aws-foo.com
tags:
Name: prd-foo-01.aws-foo.com
BillingGroup: infra-team@aws-foo.com
- filters:
volume_ids: [ vol-12345689, vol-abcdef12 ]
tags:
BillingGroup: infra-team@aws-foo.com
Should un-declared tags currently set on matched volumes be deleted? Boolean.
Region to connect to.
Secret key to be used.
Access key to be used.
A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.