community / community.aws / 5.1.0 / module / autoscaling_policy Create or delete AWS scaling policies for Autoscaling groups | "added in version" 1.0.0 of community.aws" Authors: Zacharie Eakin (@zeekin), Will Thames (@willthames)community.aws.autoscaling_policy (5.1.0) — module
Install with ansible-galaxy collection install community.aws:==5.1.0
collections: - name: community.aws version: 5.1.0
Can create or delete scaling policies for autoscaling groups.
Referenced autoscaling groups must already exist.
Prior to release 5.0.0 this module was called C(community.aws.ec2_scaling_policy). The usage did not change.
- name: Simple Scale Down policy community.aws.autoscaling_policy: state: present region: US-XXX name: "scaledown-policy" adjustment_type: "ChangeInCapacity" asg_name: "application-asg" scaling_adjustment: -1 min_adjustment_step: 1 cooldown: 300
# For an alarm with a breach threshold of 20, the # following creates a stepped policy: # From 20-40 (0-20 above threshold), increase by 50% of existing capacity # From 41-infinity, increase by 100% of existing capacity - community.aws.autoscaling_policy: state: present region: US-XXX name: "step-scale-up-policy" policy_type: StepScaling metric_aggregation: Maximum step_adjustments: - upper_bound: 20 scaling_adjustment: 50 - lower_bound: 20 scaling_adjustment: 100 adjustment_type: "PercentChangeInCapacity" asg_name: "application-asg"
- name: create TargetTracking predefined policy ec2_scaling_policy: name: "predefined-policy-1" policy_type: TargetTrackingScaling target_tracking_config: predefined_metric_spec: predefined_metric_type: ASGAverageCPUUtilization target_value: 98.0 asg_name: "asg-test-1" register: result
- name: create TargetTracking predefined policy with resource_label ec2_scaling_policy: name: "predefined-policy-1" policy_type: TargetTrackingScaling target_tracking_config: predefined_metric_spec: predefined_metric_type: ALBRequestCountPerTarget resource_label: app/my-alb/778d41231d141a0f/targetgroup/my-alb-target-group/942f017f100becff target_value: 98.0 asg_name: "asg-test-1" register: result
- name: create TargetTrackingScaling custom policy ec2_scaling_policy: name: "custom-policy-1" policy_type: TargetTrackingScaling target_tracking_config: customized_metric_spec: metric_name: metric_1 namespace: namespace_1 statistic: Minimum unit: Gigabits dimensions: [{'Name': 'dimension1', 'Value': 'value1'}] disable_scalein: true target_value: 98.0 asg_name: asg-test-1 register: result
name: description: - Unique name for the scaling policy. required: true type: str state: choices: - present - absent default: present description: - Register or deregister the policy. type: str region: aliases: - aws_region - ec2_region description: - The AWS region to use. - For global services such as IAM, Route53 and CloudFront, I(region) is ignored. - The C(AWS_REGION) or C(EC2_REGION) environment variables may also be used. - See the Amazon AWS documentation for more information U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region). - The C(ec2_region) alias has been deprecated and will be removed in a release after 2024-12-01 - Support for the C(EC2_REGION) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str profile: aliases: - aws_profile description: - A named AWS profile to use for authentication. - See the AWS documentation for more information about named profiles U(https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html). - The C(AWS_PROFILE) environment variable may also be used. - The I(profile) option is mutually exclusive with the I(aws_access_key), I(aws_secret_key) and I(security_token) options. type: str asg_name: description: - Name of the associated autoscaling group. - Required if I(state) is C(present). type: str cooldown: description: - The minimum period of time (in seconds) between which autoscaling actions can take place. - Only used when I(policy_type) is C(SimpleScaling). type: int access_key: aliases: - aws_access_key_id - aws_access_key - ec2_access_key description: - AWS access key ID. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY) or C(EC2_ACCESS_KEY) environment variables may also be used in decreasing order of preference. - The I(aws_access_key) and I(profile) options are mutually exclusive. - The I(aws_access_key_id) alias was added in release 5.1.0 for consistency with the AWS botocore SDK. - The I(ec2_access_key) alias has been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_ACCESS_KEY) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str aws_config: description: - A dictionary to modify the botocore configuration. - Parameters can be found in the AWS documentation U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config). type: dict secret_key: aliases: - aws_secret_access_key - aws_secret_key - ec2_secret_key description: - AWS secret access key. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY), or C(EC2_SECRET_KEY) environment variables may also be used in decreasing order of preference. - The I(secret_key) and I(profile) options are mutually exclusive. - The I(aws_secret_access_key) alias was added in release 5.1.0 for consistency with the AWS botocore SDK. - The I(ec2_secret_key) alias has been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_SECRET_KEY) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str policy_type: choices: - StepScaling - SimpleScaling - TargetTrackingScaling default: SimpleScaling description: - Auto scaling adjustment policy. type: str endpoint_url: aliases: - ec2_url - aws_endpoint_url - s3_url description: - URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. - The C(AWS_URL) or C(EC2_URL) environment variables may also be used, in decreasing order of preference. - The I(ec2_url) and I(s3_url) aliases have been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_URL) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str aws_ca_bundle: description: - The location of a CA Bundle to use when validating SSL certificates. - The C(AWS_CA_BUNDLE) environment variable may also be used. type: path session_token: aliases: - aws_session_token - security_token - aws_security_token - access_token description: - AWS STS session token for use with temporary credentials. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_SESSION_TOKEN), C(AWS_SECURITY_TOKEN) or C(EC2_SECURITY_TOKEN) environment variables may also be used in decreasing order of preference. - The I(security_token) and I(profile) options are mutually exclusive. - Aliases I(aws_session_token) and I(session_token) were added in release 3.2.0, with the parameter being renamed from I(security_token) to I(session_token) in release 6.0.0. - The I(security_token), I(aws_security_token), and I(access_token) aliases have been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_SECRET_KEY) and C(AWS_SECURITY_TOKEN) environment variables has been deprecated and will be removed in a release after 2024-12-01. type: str validate_certs: default: true description: - When set to C(false), SSL certificates will not be validated for communication with the AWS APIs. - Setting I(validate_certs=false) is strongly discouraged, as an alternative, consider setting I(aws_ca_bundle) instead. type: bool adjustment_type: choices: - ChangeInCapacity - ExactCapacity - PercentChangeInCapacity description: - The type of change in capacity of the autoscaling group. - Required if I(state) is C(present). type: str step_adjustments: description: - List of dicts containing I(lower_bound), I(upper_bound) and I(scaling_adjustment). - Intervals must not overlap or have a gap between them. - At most, one item can have an undefined I(lower_bound). If any item has a negative lower_bound, then there must be a step adjustment with an undefined I(lower_bound). - At most, one item can have an undefined I(upper_bound). If any item has a positive upper_bound, then there must be a step adjustment with an undefined I(upper_bound). - The bounds are the amount over the alarm threshold at which the adjustment will trigger. This means that for an alarm threshold of 50, triggering at 75 requires a lower bound of 25. See U(http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_StepAdjustment.html). elements: dict suboptions: lower_bound: description: - The lower bound for the difference between the alarm threshold and the CloudWatch metric. type: int scaling_adjustment: description: - The amount by which to scale. required: true type: int upper_bound: description: - The upper bound for the difference between the alarm threshold and the CloudWatch metric. type: int type: list metric_aggregation: choices: - Minimum - Maximum - Average default: Average description: - The aggregation type for the CloudWatch metrics. - Only used when I(policy_type) is not C(SimpleScaling). type: str scaling_adjustment: description: - The amount by which the autoscaling group is adjusted by the policy. - A negative number has the effect of scaling down the ASG. - Units are numbers of instances for C(ExactCapacity) or C(ChangeInCapacity) or percent of existing instances for C(PercentChangeInCapacity). - Required when I(policy_type) is C(SimpleScaling). type: int min_adjustment_step: description: - Minimum amount of adjustment when policy is triggered. - Only used when I(adjustment_type) is C(PercentChangeInCapacity). type: int target_tracking_config: description: - Allows you to specify a I(target_tracking_config) for autoscaling policies in AWS. - I(target_tracking_config) can accept nested dicts for I(customized_metric_spec) or I(predefined_metric_spec). Each specification aligns with their boto3 equivalent. - Required when I(TargetTrackingScaling) policy is specified. suboptions: customized_metric_spec: description: - Specify a dict will be passed in as a call for C(TargetTrackingConfiguration). suboptions: dimensions: description: - The dimensions of the metric. The element of the list should be a dict. elements: dict type: list metric_name: description: - The name of the metric. required: true type: str namespace: description: - The namespace of the metric. required: true type: str statistic: choices: - Average - Minimum - Maximum - SampleCount - Sum description: - The statistic of the metric. required: true type: str unit: description: - The unit of the metric. Reference AmazonCloudWatch API for valid Units. type: str type: dict disable_scalein: description: - Indicate whether scaling in by the target tracking scaling policy is disabled. type: bool predefined_metric_spec: description: - Specify a dict will be passed in as a call for I(TargetTrackingConfiguration). suboptions: predefined_metric_type: choices: - ASGAverageCPUUtilization - ASGAverageNetworkIn - ASGAverageNetworkOut - ALBRequestCountPerTarget description: - Required if C(predefined_metric_spec) is used. required: true type: str resource_label: description: - Uniquely identifies a specific ALB target group from which to determine the average request count served by your Auto Scaling group. - You can't specify a resource label unless the target group is attached to the Auto Scaling group. type: str type: dict target_value: description: - Specify a float number for target utilization. - Required when I(target_tracking_config) is specified. required: true type: float type: dict version_added: 4.1.0 version_added_collection: community.aws estimated_instance_warmup: description: - The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. type: int debug_botocore_endpoint_logs: default: false description: - Use a C(botocore.endpoint) logger to parse the unique (rather than total) C("resource:action") API calls made during a task, outputing the set to the resource_actions key in the task results. Use the C(aws_resource_action) callback to output to total list made during a playbook. - The C(ANSIBLE_DEBUG_BOTOCORE_LOGS) environment variable may also be used. type: bool
adjustment_type: description: Scaling policy adjustment type. returned: always sample: PercentChangeInCapacity type: str alarms: contains: alarm_arn: description: ARN of the Cloudwatch alarm. returned: always sample: arn:aws:cloudwatch:us-east-2:1234567890:alarm:cpu-very-high type: str alarm_name: description: Name of the Cloudwatch alarm. returned: always sample: cpu-very-high type: str description: Cloudwatch alarms related to the policy. returned: always type: complex arn: description: ARN of the scaling policy. Provided for backward compatibility, value is the same as I(policy_arn). returned: always sample: arn:aws:autoscaling:us-east-2:123456789012:scalingPolicy:59e37526-bd27-42cf-adca-5cd3d90bc3b9:autoScalingGroupName/app-asg:policyName/app-policy type: str as_name: description: Auto Scaling Group name. Provided for backward compatibility, value is the same as I(auto_scaling_group_name). returned: always sample: app-asg type: str auto_scaling_group_name: description: Name of Auto Scaling Group. returned: always sample: app-asg type: str metric_aggregation_type: description: Method used to aggregate metrics. returned: when I(policy_type) is C(StepScaling) sample: Maximum type: str name: description: Name of the scaling policy. Provided for backward compatibility, value is the same as I(policy_name). returned: always sample: app-policy type: str policy_arn: description: ARN of scaling policy. returned: always sample: arn:aws:autoscaling:us-east-2:123456789012:scalingPolicy:59e37526-bd27-42cf-adca-5cd3d90bc3b9:autoScalingGroupName/app-asg:policyName/app-policy type: str policy_name: description: Name of scaling policy. returned: always sample: app-policy type: str policy_type: description: Type of auto scaling policy. returned: always sample: StepScaling type: str scaling_adjustment: description: Adjustment to make when alarm is triggered. returned: When I(policy_type) is C(SimpleScaling) sample: 1 type: int step_adjustments: contains: metric_interval_lower_bound: description: Lower bound for metric interval. returned: if step has a lower bound sample: 20.0 type: float metric_interval_upper_bound: description: Upper bound for metric interval. returned: if step has an upper bound sample: 40.0 type: float scaling_adjustment: description: Adjustment to make if this step is reached. returned: always sample: 50 type: int description: List of step adjustments. returned: always type: complex