azure_rm_autoscale – Manage Azure autoscale setting.

New in version 2.7.

Synopsis

  • Create, delete an autoscale setting.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.7
  • azure >= 2.0.0

Parameters

Parameter Choices/Defaults Comments
ad_user
-
Active Directory username. Use when authenticating with an Active Directory user rather than service principal.
adfs_authority_url
-
added in 2.6
Default:
null
Azure AD authority url. Use when authenticating with Username/password, and has your own ADFS authority.
api_profile
-
added in 2.5
Default:
"latest"
Selects an API profile to use when communicating with Azure services. Default value of latest is appropriate for public clouds; future values will allow use with Azure Stack.
append_tags
boolean
    Choices:
  • no
  • yes ←
Use to control if tags field is canonical or just appends to existing tags. When canonical, any tags not found in the tags parameter will be removed from the object's metadata.
auth_source
-
added in 2.5
    Choices:
  • auto
  • cli
  • credential_file
  • env
  • msi
Controls the source of the credentials to use for authentication.
If not specified, ANSIBLE_AZURE_AUTH_SOURCE environment variable will be used and default to auto if variable is not defined.
auto will follow the default precedence of module parameters -> environment variables -> default profile in credential file ~/.azure/credentials.
When set to cli, the credentials will be sources from the default Azure CLI profile.
Can also be set via the ANSIBLE_AZURE_AUTH_SOURCE environment variable.
When set to msi, the host machine must be an azure resource with an enabled MSI extension. subscription_id or the environment variable AZURE_SUBSCRIPTION_ID can be used to identify the subscription ID if the resource is granted access to more than one subscription, otherwise the first subscription is chosen.
The msi was added in Ansible 2.6.
cert_validation_mode
-
added in 2.5
    Choices:
  • validate
  • ignore
Controls the certificate validation behavior for Azure endpoints. By default, all modules will validate the server certificate, but when an HTTPS proxy is in use, or against Azure Stack, it may be necessary to disable this behavior by passing ignore. Can also be set via credential file profile or the AZURE_CERT_VALIDATION environment variable.
client_id
-
Azure client ID. Use when authenticating with a Service Principal.
cloud_environment
-
added in 2.4
Default:
"AzureCloud"
For cloud environments other than the US public cloud, the environment name (as defined by Azure Python SDK, eg, AzureChinaCloud, AzureUSGovernment), or a metadata discovery endpoint URL (required for Azure Stack). Can also be set via credential file profile or the AZURE_CLOUD_ENVIRONMENT environment variable.
enabled
boolean
    Choices:
  • no
  • yes ←
Specifies whether automatic scaling is enabled for the resource.
location
-
location of the resource.
name
- / required
name of the resource.
notifications
-
the collection of notifications.
custom_emails
-
the custom e-mails list. This value can be null or empty, in which case this attribute will be ignored.
send_to_subscription_administrator
boolean
    Choices:
  • no
  • yes
A value indicating whether to send email to subscription administrator.
send_to_subscription_co_administrators
boolean
    Choices:
  • no
  • yes
A value indicating whether to send email to subscription co-administrators.
webhooks
-
The list of webhook notifications service uri.
password
-
Active Directory user password. Use when authenticating with an Active Directory user rather than service principal.
profile
-
Security profile found in ~/.azure/credentials file.
profiles
-
The collection of automatic scaling profiles that specify different scaling parameters for different time periods.
A maximum of 20 profiles can be specified.
count
- / required
The number of instances that will be set if metrics are not available for evaluation.
The default is only used if the current instance count is lower than the default.
fixed_date_end
-
The specific date-time end for the profile.
This element is not used if the Recurrence element is used.
fixed_date_start
-
The specific date-time start for the profile.
This element is not used if the Recurrence element is used.
fixed_date_timezone
-
The specific date-time timezone for the profile.
This element is not used if the Recurrence element is used.
max_count
-
the maximum number of instances for the resource.
min_count
-
the minimum number of instances for the resource.
name
- / required
the name of the profile.
recurrence_days
-
The days of repeating times at which this profile begins.
This element is not used if the FixedDate element is used.
recurrence_frequency
-
    Choices:
  • None ←
  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month
  • Year
How often the schedule profile should take effect.
If this value is Week, meaning each week will have the same set of profiles.
This element is not used if the FixedDate element is used.
recurrence_hours
-
The hours of repeating times at which this profile begins.
This element is not used if the FixedDate element is used.
recurrence_mins
-
The mins of repeating times at which this profile begins.
This element is not used if the FixedDate element is used.
recurrence_timezone
-
The timezone of repeating times at which this profile begins.
This element is not used if the FixedDate element is used.
rules
-
The collection of rules that provide the triggers and parameters for the scaling action.
A maximum of 10 rules can be specified.
cooldown
-
The amount of time (minutes) to wait since the last scaling action before this action occurs.
It must be between 1 ~ 10080.
direction
-
    Choices:
  • Increase
  • Decrease
Whether the scaling action increases or decreases the number of instances.
metric_name
- / required
The name of the metric that defines what the rule monitors.
metric_resource_uri
-
The resource identifier of the resource the rule monitors.
operator
-
    Choices:
  • Equals
  • NotEquals
  • GreaterThan ←
  • GreaterThanOrEqual
  • LessThan
  • LessThanOrEqual
The operator that is used to compare the metric data and the threshold.
statistic
-
    Choices:
  • Average ←
  • Min
  • Max
  • Sum
How the metrics from multiple instances are combined.
threshold
-
Default:
70
The threshold of the metric that triggers the scale action.
time_aggregation
-
    Choices:
  • Average ←
  • Minimum
  • Maximum
  • Total
  • Count
How the data that is collected should be combined over time.
time_grain
- / required
The granularity(minutes) of metrics the rule monitors.
Must be one of the predefined values returned from metric definitions for the metric.
Must be between 1 ~ 720.
time_window
- / required
The range of time(minutes) in which instance data is collected.
This value must be greater than the delay in metric collection, which can vary from resource-to-resource.
Must be between 5 ~ 720.
type
-
    Choices:
  • PercentChangeCount
  • ExactCount
  • ChangeCount
The type of action that should occur when the scale rule fires.
value
-
The number of instances that are involved in the scaling action.
This value must be 1 or greater.
resource_group
- / required
resource group of the resource.
secret
-
Azure client secret. Use when authenticating with a Service Principal.
state
-
    Choices:
  • present ←
  • absent
Assert the state of the virtual network. Use 'present' to create or update and 'absent' to delete.
subscription_id
-
Your Azure subscription Id.
tags
-
Dictionary of string:string pairs to assign as metadata to the object. Metadata tags on the object will be updated with any provided values. To remove tags set append_tags option to false.
target
-
The identifier of the resource to apply autoscale setting.
It could be the resource id string.
It also could be a dict contains the name, subscription_id, namespace, types, resource_group of the resource.
tenant
-
Azure tenant ID. Use when authenticating with a Service Principal.

Notes

Note

  • For authentication with Azure you can pass parameters, set environment variables or use a profile stored in ~/.azure/credentials. Authentication is possible using a service principal or Active Directory user. To authenticate via service principal, pass subscription_id, client_id, secret and tenant or set environment variables AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_SECRET and AZURE_TENANT.
  • To authenticate via Active Directory user, pass ad_user and password, or set AZURE_AD_USER and AZURE_PASSWORD in the environment.
  • Alternatively, credentials can be stored in ~/.azure/credentials. This is an ini file containing a [default] section and the following keys: subscription_id, client_id, secret and tenant or subscription_id, ad_user and password. It is also possible to add additional profiles. Specify the profile by passing profile or setting AZURE_PROFILE in the environment.

Examples

- name: Create an auto scale
  azure_rm_autoscale:
      target: "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/foo/providers/Microsoft.Compute/virtualMachineScaleSets/vmss"
      enabled: true
      profiles:
      - count: '1'
        recurrence_days:
        - Monday
        name: Auto created scale condition
        recurrence_timezone: China Standard Time
        recurrence_mins:
        - '0'
        min_count: '1'
        max_count: '1'
        recurrence_frequency: Week
        recurrence_hours:
        - '18'
      name: scale
      resource_group: foo

- name: Create an auto scale with compicated profile
  azure_rm_autoscale:
      target: "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/foo/providers/Microsoft.Compute/virtualMachineScaleSets/vmss"
      enabled: true
      profiles:
      - count: '1'
        recurrence_days:
        - Monday
        name: Auto created scale condition 0
        rules:
        - Time_aggregation: Average
          time_window: 10
          direction: Increase
          metric_name: Percentage CPU
          metric_resource_uri: "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/foo/providers/Microsoft.Compute/virtualMachineScaleSets/vmss"
          value: '1'
          threshold: 70
          cooldown: 5
          time_grain: 1
          statistic: Average
          operator: GreaterThan
          type: ChangeCount
        max_count: '1'
        recurrence_mins:
        - '0'
        min_count: '1'
        recurrence_timezone: China Standard Time
        recurrence_frequency: Week
        recurrence_hours:
        - '6'
      notifications:
      - email_admin: True
        email_co_admin: False
        custom_emails:
        - [email protected]
      name: scale
      resource_group: foo

- name: Delete an Azure Auto Scale Setting
  azure_rm_autoscale:
    state: absent
    resource_group: foo
    name: scale

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
state
dictionary
always
Current state of the resource.

Sample:
{'changed': False, 'enabled': True, 'id': '/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/foo/providers/microsoft.insights/autoscalesettings/scale', 'location': 'eastus', 'name': 'scale', 'notifications': [{'custom_emails': ['[email protected]'], 'send_to_subscription_administrator': True, 'send_to_subscription_co_administrators': False, 'webhooks': []}], 'profiles': [{'count': '1', 'max_count': '1', 'min_count': '1', 'name': 'Auto created scale condition 0', 'recurrence_days': ['Monday'], 'recurrence_frequency': 'Week', 'recurrence_hours': ['6'], 'recurrence_mins': ['0'], 'recurrence_timezone': 'China Standard Time', 'rules': [{'cooldown': 5.0, 'direction': 'Increase', 'metric_name': 'Percentage CPU', 'metric_resource_uri': '/subscriptions/X/resourceGroups/foo/providers/Microsoft.Compute/virtualMachineScaleSets/vmss', 'operator': 'GreaterThan', 'statistic': 'Average', 'threshold': 70.0, 'time_aggregation': 'Average', 'time_grain': 1.0, 'time_window': 10.0, 'type': 'ChangeCount', 'value': '1'}]}], 'target': '/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/foo/providers/Microsoft.Compute/virtualMachineScaleSets/vmss'}


Status

Authors

  • Yuwei Zhou (@yuwzho)

Hint

If you notice any issues in this documentation you can edit this document to improve it.