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

adding uptime parameter to community.aws.ec2_instance_info #316

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelogs/fragments/318-cleanup-vpc_igw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
minor_changes:
- ec2_vpc_igw - Add AWSRetry decorators to improve reliability (https://github.com/ansible-collections/community.aws/pull/318).
- ec2_vpc_igw_info - Add AWSRetry decorators to improve reliability (https://github.com/ansible-collections/community.aws/pull/318).
- ec2_vpc_igw - Add ``purge_tags`` parameter so that tags can be added without purging existing tags to match the collection standard tagging behaviour (https://github.com/ansible-collections/community.aws/pull/318).
- ec2_vpc_igw_info - Add ``convert_tags`` parameter so that tags can be returned in standard dict format rather than the both list of dict format (https://github.com/ansible-collections/community.aws/pull/318).
deprecated_features:
- ec2_vpc_igw_info - After 2022-06-22 the ``convert_tags`` parameter default value will change from ``False`` to ``True`` to match the collection standard behavior (https://github.com/ansible-collections/community.aws/pull/318).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- iam_policy - Added jittered_backoff to handle AWS rate limiting (https://github.com/ansible-collections/community.aws/pull/324).
- iam_policy_info - Added jittered_backoff to handle AWS rate limiting (https://github.com/ansible-collections/community.aws/pull/324).
24 changes: 13 additions & 11 deletions plugins/modules/aws_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
version_added: 1.0.0
short_description: Manage AWS API Gateway APIs
description:
- Allows for the management of API Gateway APIs
- Allows for the management of API Gateway APIs.
- Normally you should give the api_id since there is no other
stable guaranteed unique identifier for the API. If you do
not give api_id then a new API will be created each time
Expand All @@ -40,7 +40,7 @@
swagger_file:
description:
- JSON or YAML file containing swagger definitions for API.
Exactly one of swagger_file, swagger_text or swagger_dict must
Exactly one of I(swagger_file), I(swagger_text) or I(swagger_dict) must
be present.
type: path
aliases: ['src', 'api_file']
Expand All @@ -60,13 +60,13 @@
type: str
deploy_desc:
description:
- Description of the deployment - recorded and visible in the
AWS console.
- Description of the deployment.
- Recorded and visible in the AWS console.
default: Automatic deployment by Ansible.
type: str
cache_enabled:
description:
- Enable API GW caching of backend responses. Defaults to false.
- Enable API GW caching of backend responses.
type: bool
default: false
cache_size:
Expand All @@ -83,20 +83,22 @@
description:
- Canary settings for the deployment of the stage.
- 'Dict with following settings:'
- 'percentTraffic: The percent (0-100) of traffic diverted to a canary deployment.'
- 'deploymentId: The ID of the canary deployment.'
- 'stageVariableOverrides: Stage variables overridden for a canary release deployment.'
- 'useStageCache: A Boolean flag to indicate whether the canary deployment uses the stage cache or not.'
- 'C(percentTraffic): The percent (0-100) of traffic diverted to a canary deployment.'
- 'C(deploymentId): The ID of the canary deployment.'
- 'C(stageVariableOverrides): Stage variables overridden for a canary release deployment.'
- 'C(useStageCache): A Boolean flag to indicate whether the canary deployment uses the stage cache or not.'
- See docs U(https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.create_stage)
type: dict
tracing_enabled:
description:
- Specifies whether active tracing with X-ray is enabled for the API GW stage.
type: bool
default: false
endpoint_type:
description:
- Type of endpoint configuration, use C(EDGE) for an edge optimized API endpoint,
- C(REGIONAL) for just a regional deploy or PRIVATE for a private API.
- Type of endpoint configuration.
- Use C(EDGE) for an edge optimized API endpoint,
C(REGIONAL) for just a regional deploy or C(PRIVATE) for a private API.
- This flag will only be used when creating a new API Gateway setup, not for updates.
choices: ['EDGE', 'REGIONAL', 'PRIVATE']
type: str
Expand Down
15 changes: 8 additions & 7 deletions plugins/modules/aws_application_scaling_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
- for details of the parameters and returns see
U(http://boto3.readthedocs.io/en/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.put_scaling_policy)
description:
- Creates, updates or removes a Scaling Policy
- Creates, updates or removes a Scaling Policy.
author:
- Gustavo Maia (@gurumaia)
- Chen Leibovich (@chenl87)
requirements: [ json, botocore, boto3 ]
options:
state:
description: Whether a policy should be present or absent
description: Whether a policy should be C(present) or C(absent).
required: yes
choices: ['absent', 'present']
type: str
Expand Down Expand Up @@ -57,12 +57,12 @@
choices: ['StepScaling', 'TargetTrackingScaling']
type: str
step_scaling_policy_configuration:
description: A step scaling policy. This parameter is required if you are creating a policy and the policy type is StepScaling.
description: A step scaling policy. This parameter is required if you are creating a policy and I(policy_type=StepScaling).
required: no
type: dict
target_tracking_scaling_policy_configuration:
description:
- A target tracking policy. This parameter is required if you are creating a new policy and the policy type is TargetTrackingScaling.
- A target tracking policy. This parameter is required if you are creating a new policy and I(policy_type=TargetTrackingScaling).
- 'Full documentation of the suboptions can be found in the API documentation:'
- 'U(https://docs.aws.amazon.com/autoscaling/application/APIReference/API_TargetTrackingScalingPolicyConfiguration.html)'
required: no
Expand All @@ -84,7 +84,7 @@
description: The time (in seconds) to wait after scaling-out before another scaling action can occur.
type: int
TargetValue:
description: The target value for the metric
description: The target value for the metric.
type: float
minimum_tasks:
description: The minimum value to scale to in response to a scale in event.
Expand All @@ -97,9 +97,10 @@
required: no
type: int
override_task_capacity:
description: Whether or not to override values of minimum and/or maximum tasks if it's already set.
description:
- Whether or not to override values of minimum and/or maximum tasks if it's already set.
- Defaults to C(false).
required: no
default: no
type: bool
extends_documentation_fragment:
- amazon.aws.aws
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/aws_direct_connect_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@
type: str
forced_update:
description:
- To modify bandwidth or location the connection will need to be deleted and recreated.
By default this will not happen - this option must be set to True.
- To modify I(bandwidth) or I(location) the connection needs to be deleted and recreated.
- By default this will not happen. This option must be explicitly set to C(true) to change I(bandwith) or I(location).
type: bool
default: false
'''

EXAMPLES = """
Expand All @@ -93,7 +94,7 @@
name: ansible-test-connection
location: EqDC2
bandwidth: 10Gbps
forced_update: True
forced_update: true

# delete the connection
- community.aws.aws_direct_connect_connection:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/aws_direct_connect_link_aggregation_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- This allows the minimum number of links to be set to 0, any hosted connections disassociated,
and any virtual interfaces associated to the LAG deleted.
type: bool
default: false
connection_id:
description:
- A connection ID to link with the link aggregation group upon creation.
Expand All @@ -67,12 +68,14 @@
description:
- To be used with I(state=absent) to delete connections after disassociating them with the LAG.
type: bool
default: false
wait:
description:
- Whether or not to wait for the operation to complete.
- May be useful when waiting for virtual interfaces to be deleted.
- The time to wait can be controlled by setting I(wait_timeout).
type: bool
default: false
wait_timeout:
description:
- The duration in seconds to wait if I(wait=true).
Expand Down
24 changes: 12 additions & 12 deletions plugins/modules/cloudfront_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
tags:
description:
- Should be input as a dict of key-value pairs.
- Note that numeric keys or values must be wrapped in quotes. e.g. "Priority:" '1'
- "Note that numeric keys or values must be wrapped in quotes. e.g. C(Priority: '1')"
type: dict

purge_tags:
Expand All @@ -87,7 +87,7 @@

aliases:
description:
- A list) of domain name aliases (CNAMEs) as strings to be used for the distribution.
- A list of domain name aliases (CNAMEs) as strings to be used for the distribution.
- Each alias must be unique across all distribution for the AWS account.
type: list
elements: str
Expand Down Expand Up @@ -141,7 +141,7 @@
description:
- Custom headers you wish to add to the request before passing it to the origin.
- For more information see the CloudFront documentation
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/forward-custom-headers.html)
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/forward-custom-headers.html).
type: list
elements: dict
suboptions:
Expand Down Expand Up @@ -191,7 +191,7 @@
description:
- A dict specifying the default cache behavior of the distribution.
- If not specified, the I(target_origin_id) is defined as the I(target_origin_id) of the first valid
I(cache_behavior) in I(cache_behaviors) with defaults.
cache_behavior in I(cache_behaviors) with defaults.
suboptions:
target_origin_id:
description:
Expand Down Expand Up @@ -492,7 +492,7 @@
enabled:
description:
- A boolean value that specifies whether the distribution is enabled or disabled.
default: false
- Defaults to C(false).
type: bool

viewer_certificate:
Expand All @@ -504,18 +504,18 @@
type: bool
description:
- If you're using the CloudFront domain name for your distribution, such as C(123456789abcde.cloudfront.net)
you should set I(cloudfront_default_certificate=true)
you should set I(cloudfront_default_certificate=true).
- If I(cloudfront_default_certificate=true) do not set I(ssl_support_method).
iam_certificate_id:
type: str
description:
- The ID of a certificate stored in IAM to use for HTTPS connections.
- If I(iam_certificate_id) is set then you must also specify I(ssl_support_method)
- If I(iam_certificate_id) is set then you must also specify I(ssl_support_method).
acm_certificate_arn:
type: str
description:
- The ID of a certificate stored in ACM to use for HTTPS connections.
- If I(acm_certificate_id) is set then you must also specify I(ssl_support_method)
- If I(acm_certificate_id) is set then you must also specify I(ssl_support_method).
ssl_support_method:
type: str
description:
Expand All @@ -541,12 +541,12 @@
type: str
description:
- The method that you want to use to restrict distribution of your content by country.
- Valid values are C(none), C(whitelist), C(blacklist)
- Valid values are C(none), C(whitelist), C(blacklist).
items:
description:
- A list of ISO 3166-1 two letter (Alpha 2) country codes that the
restriction should apply to.
- 'See the ISO website for a full list of codes U(https://www.iso.org/obp/ui/#search/code/)'
- 'See the ISO website for a full list of codes U(https://www.iso.org/obp/ui/#search/code/).'
type: list

web_acl_id:
Expand All @@ -558,14 +558,14 @@
description:
- The version of the http protocol to use for the distribution.
- AWS defaults this to C(http2).
- Valid values are C(http1.1) and C(http2)
- Valid values are C(http1.1) and C(http2).
type: str

ipv6_enabled:
description:
- Determines whether IPv6 support is enabled or not.
- Defaults to C(false).
type: bool
default: false

wait:
description:
Expand Down
10 changes: 6 additions & 4 deletions plugins/modules/ec2_ami_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type: str
name:
description:
- The name of the new AMI to copy. (As of 2.3 the default is 'default', in prior versions it was 'null'.)
- The name of the new AMI to copy. (As of 2.3 the default is C(default), in prior versions it was C(null).)
default: "default"
type: str
description:
Expand All @@ -38,20 +38,22 @@
description:
- Whether or not the destination snapshots of the copied AMI should be encrypted.
type: bool
default: false
kms_key_id:
description:
- KMS key id used to encrypt the image. If not specified, uses default EBS Customer Master Key (CMK) for your account.
type: str
wait:
description:
- Wait for the copied AMI to be in state 'available' before returning.
- Wait for the copied AMI to be in state C(available) before returning.
type: bool
default: 'no'
wait_timeout:
description:
- How long before wait gives up, in seconds. Prior to 2.3 the default was 1200.
- How long before wait gives up, in seconds.
- Prior to 2.3 the default was C(1200).
- From 2.3-2.5 this option was deprecated in favor of boto3 waiter defaults.
This was reenabled in 2.6 to allow timeouts greater than 10 minutes.
- This was reenabled in 2.6 to allow timeouts greater than 10 minutes.
default: 600
type: int
tags:
Expand Down
32 changes: 29 additions & 3 deletions plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
required: false
default: {}
type: dict
uptime:
description:
- minimum running uptime in minutes of instances. For example if uptime is 60, it would return all instances that have run more than 60 minutes.
required: false
type: int

extends_documentation_fragment:
- amazon.aws.aws
Expand Down Expand Up @@ -66,6 +71,15 @@
filters:
instance-state-name: [ "shutting-down", "stopping", "stopped" ]

- name: Gather information about any instance with Name beginning with RHEL and been running at least 60 minutes
community.aws.ec2_instance_info:
region: "{{ ec2_region }}"
uptime: 60
filters:
"tag:Name": "RHEL-*"
instance-state-name: [ "running" ]
register: ec2_node_info

'''

RETURN = r'''
Expand Down Expand Up @@ -492,6 +506,7 @@
'''

import traceback
import datetime

try:
import boto3
Expand All @@ -509,6 +524,7 @@
def list_ec2_instances(connection, module):

instance_ids = module.params.get("instance_ids")
uptime = module.params.get('uptime')
filters = ansible_dict_to_boto3_filter_list(module.params.get("filters"))

try:
Expand All @@ -517,10 +533,19 @@ def list_ec2_instances(connection, module):
except ClientError as e:
module.fail_json_aws(e, msg="Failed to list ec2 instances")

# Get instances from reservations
instances = []
for reservation in reservations['Reservations']:
instances = instances + reservation['Instances']



if uptime:
timedelta = int(uptime) if uptime else 0
oldest_launch_time = datetime.datetime.utcnow() - datetime.timedelta(minutes=timedelta)
# Get instances from reservations
for reservation in reservations['Reservations']:
instances += [instance for instance in reservation['Instances'] if instance['LaunchTime'].replace(tzinfo=None) < oldest_launch_time]
else:
for reservation in reservations['Reservations']:
instances = instances + reservation['Instances']

# Turn the boto3 result in to ansible_friendly_snaked_names
snaked_instances = [camel_dict_to_snake_dict(instance) for instance in instances]
Expand All @@ -535,6 +560,7 @@ def list_ec2_instances(connection, module):
def main():

argument_spec = dict(
uptime=dict(required=False, type='int', default=None),
instance_ids=dict(default=[], type='list', elements='str'),
filters=dict(default={}, type='dict')
)
Expand Down
Loading