ec2-instance-exists
Description
Create an instance on Amazon EC2, if it doesn't exist yet.
For now, the 'instance_name' variable is required, because otherwise the underlying Ansible module errors out if no tags dict (or an empty one) is provided. Need to investigate how to do this best.
Variables
| Name | Type | Default | Description |
|---|---|---|---|
|
string | -- | The Name tag for the instance. Required |
|
string | -- | The AWS region to use. Required |
|
string | -- | The AWS access key. |
|
string | -- | The AWS secret key. |
|
string | ami-08d658f84a6d84a80 | An image to use for the instance. |
|
string | t2.micro | Instance type to use for the instance. |
|
string | -- | Name of the SSH access key to assign to the instance - must exist in the region the instance is created. |
|
string | ec2_instance | The name of the variable to register the result of this frecklet. |
|
list | -- | A list of security group IDs or names (strings). |
|
dict | -- | A hash/dictionary of tags to add to the new instance or to add/remove from an existing one. |
|
boolean | True | Wait for the instance to be created. If set to 'false', no result will be registered as the details of this instance won't be known. |
|
integer | 600 | How long to wait (in seconds) for the instance to finish booting/terminating. |
Code
doc: short_help: Create an instance on Amazon EC2, if it doesn't exist yet. help: | Create an instance on Amazon EC2, if it doesn't exist yet. For now, the 'instance_name' variable is required, because otherwise the underlying Ansible module errors out if no tags dict (or an empty one) is provided. Need to investigate how to do this best. args: instance_name: doc: short_help: The Name tag for the instance. type: string required: true aws_access_key: doc: short_help: The AWS access key. type: string required: false aws_secret_key: doc: short_help: The AWS secret key. type: string secret: true required: false security_groups: doc: short_help: A list of security group IDs or names (strings). type: list schema: type: string empty: true required: false cli: param_decls: - --security-group - -g region: doc: short_help: The AWS region to use. references: AWS region documentation: https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region type: string required: true instance_type: doc: short_help: Instance type to use for the instance. references: AWS instance type documentation: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html type: string default: t2.micro image_id: doc: short_help: An image to use for the instance. required: true type: string default: ami-08d658f84a6d84a80 key_name: doc: short_help: Name of the SSH access key to assign to the instance - must exist in the region the instance is created. type: string required: false register_target: doc: short_help: The name of the variable to register the result of this frecklet. type: string required: false default: ec2_instance cli: metavar: VAR_NAME wait: doc: short_help: Wait for the instance to be created. help: | Wait for the instance to be created. If set to 'false', no result will be registered as the details of this instance won't be known. type: boolean required: false default: true wait_timeout: doc: short_help: How long to wait (in seconds) for the instance to finish booting/terminating. type: integer required: false default: 600 tags: doc: short_help: A hash/dictionary of tags to add to the new instance or to add/remove from an existing one. type: dict required: false empty: false frecklets: - frecklet: name: ec2_instance type: ansible-module properties: elevated: false idempotent: true internet: true register: target: '{{:: register_target ::}}' value: '{{ __result__.instances[0] }}' desc: short: "create EC2 '{{:: instance_type ::}}' instance" resources: python-package: - boto - boto3 - botocore task: include-type: include delegate_to: localhost vars: name: '{{:: instance_name ::}}' aws_access_key: '{{:: aws_access_key ::}}' aws_secret_key: '{{:: aws_secret_key ::}}' security_groups: '{{:: security_groups ::}}' region: '{{:: region ::}}' instance_type: '{{:: instance_type ::}}' image_id: '{{:: image_id ::}}' key_name: '{{:: key_name ::}}' wait: '{{:: wait ::}}' wait_timeout: '{{:: wait_timeout ::}}' state: running tags: '{{:: tags ::}}'
frecklecute --community ec2-instance-exists --help Usage: frecklecute ec2-instance-exists [OPTIONS] Create an instance on Amazon EC2, if it doesn't exist yet. For now, the 'instance_name' variable is required, because otherwise the underlying Ansible module errors out if no tags dict (or an empty one) is provided. Need to investigate how to do this best. Options: --instance-name INSTANCE_NAME The Name tag for the instance. [required] --region REGION The AWS region to use. [required] --aws-access-key AWS_ACCESS_KEY The AWS access key. --aws-secret-key AWS_SECRET_KEY The AWS secret key. --image-id IMAGE_ID An image to use for the instance. --instance-type INSTANCE_TYPE Instance type to use for the instance. --key-name KEY_NAME Name of the SSH access key to assign to the instance - must exist in the region the instance is created. --register-target VAR_NAME The name of the variable to register the result of this frecklet. -g, --security-group SECURITY_GROUPS A list of security group IDs or names (strings). --tags TAGS A hash/dictionary of tags to add to the new instance or to add/remove from an existing one. --wait / --no-wait Wait for the instance to be created. --wait-timeout WAIT_TIMEOUT How long to wait (in seconds) for the instance to finish booting/terminating. --help Show this message and exit.
# -*- coding: utf-8 -*- # # module path: pycklets.ec2_instance_exists.Ec2InstanceExists # from dataclasses import dataclass from pyckles import AutoPycklet from typing import * # noqa @dataclass class Ec2InstanceExists(AutoPycklet): """Create an instance on Amazon EC2, if it doesn't exist yet. For now, the 'instance_name' variable is required, because otherwise the underlying Ansible module errors out if no tags dict (or an empty one) is provided. Need to investigate how to do this best. Args: aws_access_key: The AWS access key. aws_secret_key: The AWS secret key. image_id: An image to use for the instance. instance_name: The Name tag for the instance. instance_type: Instance type to use for the instance. key_name: Name of the SSH access key to assign to the instance - must exist in the region the instance is created. region: The AWS region to use. register_target: The name of the variable to register the result of this frecklet. security_groups: A list of security group IDs or names (strings). tags: A hash/dictionary of tags to add to the new instance or to add/remove from an existing one. wait: Wait for the instance to be created. wait_timeout: How long to wait (in seconds) for the instance to finish booting/terminating. """ FRECKLET_ID = "ec2-instance-exists" aws_access_key: str = None aws_secret_key: str = None image_id: str = None instance_name: str = None instance_type: str = None key_name: str = None region: str = None register_target: str = None security_groups: List = None tags: Dict = None wait: bool = None wait_timeout: int = None def __post_init__(self): super(Ec2InstanceExists, self).__init__(var_names=["aws_access_key", "aws_secret_key", "image_id", "instance_name", "instance_type", "key_name", "region", "register_target", "security_groups", "tags", "wait", "wait_timeout"]) frecklet_class = Ec2InstanceExists
# -*- coding: utf-8 -*- # # module path: pycklets.ec2_instance_exists.Ec2InstanceExists # from pyckles import AutoPycklet class Ec2InstanceExists(AutoPycklet): """Create an instance on Amazon EC2, if it doesn't exist yet. For now, the 'instance_name' variable is required, because otherwise the underlying Ansible module errors out if no tags dict (or an empty one) is provided. Need to investigate how to do this best. Args: aws_access_key: The AWS access key. aws_secret_key: The AWS secret key. image_id: An image to use for the instance. instance_name: The Name tag for the instance. instance_type: Instance type to use for the instance. key_name: Name of the SSH access key to assign to the instance - must exist in the region the instance is created. region: The AWS region to use. register_target: The name of the variable to register the result of this frecklet. security_groups: A list of security group IDs or names (strings). tags: A hash/dictionary of tags to add to the new instance or to add/remove from an existing one. wait: Wait for the instance to be created. wait_timeout: How long to wait (in seconds) for the instance to finish booting/terminating. """ FRECKLET_ID = "ec2-instance-exists" def __init__(self, aws_access_key=None, aws_secret_key=None, image_id="ami-08d658f84a6d84a80", instance_name=None, instance_type="t2.micro", key_name=None, region=None, register_target="ec2_instance", security_groups=None, tags=None, wait=True, wait_timeout=600): super(Ec2InstanceExists, self).__init__(var_names=["aws_access_key", "aws_secret_key", "image_id", "instance_name", "instance_type", "key_name", "region", "register_target", "security_groups", "tags", "wait", "wait_timeout"]) self._aws_access_key = aws_access_key self._aws_secret_key = aws_secret_key self._image_id = image_id self._instance_name = instance_name self._instance_type = instance_type self._key_name = key_name self._region = region self._register_target = register_target self._security_groups = security_groups self._tags = tags self._wait = wait self._wait_timeout = wait_timeout @property def aws_access_key(self): return self._aws_access_key @aws_access_key.setter def aws_access_key(self, aws_access_key): self._aws_access_key = aws_access_key @property def aws_secret_key(self): return self._aws_secret_key @aws_secret_key.setter def aws_secret_key(self, aws_secret_key): self._aws_secret_key = aws_secret_key @property def image_id(self): return self._image_id @image_id.setter def image_id(self, image_id): self._image_id = image_id @property def instance_name(self): return self._instance_name @instance_name.setter def instance_name(self, instance_name): self._instance_name = instance_name @property def instance_type(self): return self._instance_type @instance_type.setter def instance_type(self, instance_type): self._instance_type = instance_type @property def key_name(self): return self._key_name @key_name.setter def key_name(self, key_name): self._key_name = key_name @property def region(self): return self._region @region.setter def region(self, region): self._region = region @property def register_target(self): return self._register_target @register_target.setter def register_target(self, register_target): self._register_target = register_target @property def security_groups(self): return self._security_groups @security_groups.setter def security_groups(self, security_groups): self._security_groups = security_groups @property def tags(self): return self._tags @tags.setter def tags(self, tags): self._tags = tags @property def wait(self): return self._wait @wait.setter def wait(self, wait): self._wait = wait @property def wait_timeout(self): return self._wait_timeout @wait_timeout.setter def wait_timeout(self, wait_timeout): self._wait_timeout = wait_timeout frecklet_class = Ec2InstanceExists