community.aws.autoscaling_scheduled_action 模块 – 创建、修改和删除 ASG 定时扩展操作

注意

此模块是 community.aws 集合(版本 9.0.0)的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.aws。您需要进一步的要求才能使用此模块,有关详细信息,请参阅要求

要在 playbook 中使用它,请指定:community.aws.autoscaling_scheduled_action

community.aws 2.2.0 中的新功能

概要

  • state=present 且未找到给定操作时,该模块将创建新的定时操作。

  • state=present 且找到给定操作时,该模块将更新新的定时操作。

  • state=absent 且找到给定操作时,该模块将删除新的定时操作。

  • 在 5.0.0 版本之前,此模块名为 community.aws.ec2_asg_scheduled_action。用法没有改变。

别名:ec2_asg_scheduled_action

要求

执行此模块的主机上需要以下要求。

  • python >= 3.6

  • boto3 >= 1.28.0

  • botocore >= 1.31.0

参数

参数

注释

access_key

别名:aws_access_key_id,aws_access_key,ec2_access_key

字符串

AWS 访问密钥 ID。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以按优先级降序使用 AWS_ACCESS_KEY_IDAWS_ACCESS_KEYEC2_ACCESS_KEY 环境变量。

aws_access_keyprofile 选项互斥。

aws_access_key_id 别名已在 5.1.0 版本中添加,以与 AWS botocore SDK 保持一致。

ec2_access_key 别名已被弃用,将在 2024-12-01 之后的版本中删除。

EC2_ACCESS_KEY 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中删除。

autoscaling_group_name

字符串 / 必需

要向其添加定时操作的自动缩放组的名称。

aws_ca_bundle

路径

用于验证 SSL 证书的 CA 捆绑包的位置。

也可以使用 AWS_CA_BUNDLE 环境变量。

aws_config

字典

用于修改 botocore 配置的字典。

可以在 AWS 文档中找到参数 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config

debug_botocore_endpoint_logs

布尔值

使用 botocore.endpoint 记录器来解析任务期间发出的唯一(而不是总共)"resource:action" API 调用,将集合输出到任务结果中的 resource_actions 键。使用 aws_resource_action 回调输出到 playbook 期间生成的总列表。

也可以使用 ANSIBLE_DEBUG_BOTOCORE_LOGS 环境变量。

选择

  • false ← (默认)

  • true

desired_capacity

整数

ASG 期望容量。

end_time

字符串

操作的结束时间。

endpoint_url

别名:ec2_url,aws_endpoint_url,s3_url

字符串

连接的 URL,而不是默认的 AWS 终端节点。虽然这可以用于连接其他与 AWS 兼容的服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行了测试。

也可以使用 AWS_URLEC2_URL 环境变量,优先级依次降低。

ec2_urls3_url 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_URL 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

max_size

整数

ASG 最大容量。

min_size

整数

ASG 最小容量。

profile

别名: aws_profile

字符串

用于身份验证的命名 AWS 配置文件。

有关命名配置文件的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

也可以使用 AWS_PROFILE 环境变量。

profile 选项与 aws_access_keyaws_secret_keysecurity_token 选项互斥。

recurrence

字符串

重复执行操作的 Cron 样式计划。

state=present 时为必填项。

region

别名: aws_region, ec2_region

字符串

要使用的 AWS 区域。

对于诸如 IAM、Route53 和 CloudFront 等全局服务,region 会被忽略。

也可以使用 AWS_REGIONEC2_REGION 环境变量。

有关更多信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

ec2_region 别名已被弃用,将在 2024-12-01 之后的版本中移除

EC2_REGION 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

scheduled_action_name

字符串 / 必需

计划操作的名称。

secret_key

别名: aws_secret_access_key, aws_secret_key, ec2_secret_key

字符串

AWS 秘密访问密钥。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以使用 AWS_SECRET_ACCESS_KEYAWS_SECRET_KEYEC2_SECRET_KEY 环境变量,优先级依次降低。

secret_keyprofile 选项互斥。

aws_secret_access_key 别名在 5.1.0 版本中添加,以与 AWS botocore SDK 保持一致。

ec2_secret_key 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_SECRET_KEY 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

session_token

别名: aws_session_token, security_token, aws_security_token, access_token

字符串

用于临时凭证的 AWS STS 会话令牌。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以使用 AWS_SESSION_TOKENAWS_SECURITY_TOKENEC2_SECURITY_TOKEN 环境变量,优先级依次降低。

security_tokenprofile 选项互斥。

别名 aws_session_tokensession_token 在 3.2.0 版本中添加,参数在 6.0.0 版本中从 security_token 重命名为 session_token

security_tokenaws_security_tokenaccess_token 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_SECRET_KEYAWS_SECURITY_TOKEN 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

start_time

字符串

操作的开始时间。

state

字符串

创建/更新或删除计划操作。

选择

  • "present" ← (默认)

  • "absent"

time_zone

字符串

要运行的时区。

validate_certs

布尔值

设置为 false 时,与 AWS API 通信时将不验证 SSL 证书。

强烈建议不要设置 validate_certs=false,作为替代方案,请考虑设置 aws_ca_bundle

选择

  • false

  • true ← (默认)

注意事项

注意

  • 注意: 对于模块,环境变量和配置文件是从 Ansible 'host' 上下文读取的,而不是从 'controller' 上下文读取的。因此,可能需要将文件显式复制到 'host'。对于查找和连接插件,环境变量和配置文件是从 Ansible 'controller' 上下文读取的,而不是从 'host' 上下文读取的。

  • Ansible 使用的 AWS SDK (boto3) 也可能从 Ansible 'host' 上下文(通常是 ~/.aws/credentials)中的配置文件读取凭证和其他设置(例如区域)的默认值。有关更多信息,请参阅 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

示例

# Create a scheduled action for a autoscaling group.
- name: Create a minimal scheduled action for autoscaling group
  community.aws.autoscaling_scheduled_action:
    region: eu-west-1
    autoscaling_group_name: test_asg
    scheduled_action_name: test_scheduled_action
    start_time: 2021 October 25 08:00 UTC
    recurrence: 40 22 * * 1-5
    desired_capacity: 10
    state: present
  register: scheduled_action

- name: Create a scheduled action for autoscaling group
  community.aws.autoscaling_scheduled_action:
    region: eu-west-1
    autoscaling_group_name: test_asg
    scheduled_action_name: test_scheduled_action
    start_time: 2021 October 25 08:00 UTC
    end_time: 2021 October 25 08:00 UTC
    time_zone: Europe/London
    recurrence: 40 22 * * 1-5
    min_size: 10
    max_size: 15
    desired_capacity: 10
    state: present
  register: scheduled_action

- name: Delete scheduled action
  community.aws.autoscaling_scheduled_action:
    region: eu-west-1
    autoscaling_group_name: test_asg
    scheduled_action_name: test_scheduled_action
    state: absent

返回值

通用返回值已在此处记录 这里,以下是此模块特有的字段

描述

desired_capacity

整数

ASG 期望容量。

返回:state=present

示例: 1

end_time

字符串

操作的结束时间。

返回:state=present

示例: "2021 October 25 08:00 UTC"

max_size

整数

ASG 最大容量。

返回:state=present

示例: 2

min_size

整数

ASG 最小容量。

返回:state=present

示例: 1

recurrence

字符串

重复执行操作的 Cron 样式计划。

返回:state=present

示例: "40 22 * * 1-5"

scheduled_action_name

字符串

计划操作的名称。

返回:state=present

示例: "test_scheduled_action"

start_time

字符串

操作的开始时间。

返回:state=present

示例: "2021 October 25 08:00 UTC"

time_zone

字符串

启动配置使用的 Amazon 系统映像的 ID。

返回:state=present

示例: "Europe/London"

作者

  • Mark Woolley(@marknet15)