community.aws.cloudformation_stack_set 模块 – 管理 CloudFormation 堆栈组

注意

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

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

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

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

community.aws 1.0.0 中的新增功能

概要

  • 启动/更新/删除 AWS CloudFormation 堆栈集。

要求

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

  • 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 botocore SDK 保持一致,在 5.1.0 版本中添加了 aws_access_key_id 别名。

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

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

accounts

列表 / 元素=字符串

要在其中创建 CloudFormation 堆栈实例的 AWS 账户列表。

必须至少指定一个区域才能创建堆栈集。在更新时,如果指定的区域较少,则只有指定的区域的堆栈实例将被更新。

administration_role_arn

别名:admin_role_arn、admin_role、administration_role

字符串

管理角色的 ARN,即 CloudFormation 堆栈集用于在子账户中承担的角色。

默认为 arn:aws:iam::{{ account ID }}:role/AWSCloudFormationStackSetAdministrationRole,其中 {{ account ID }} 将替换为当前 IAM 角色/用户/STS 凭证的账户编号。

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

capabilities

列表 / 元素=字符串

Capabilities 允许堆栈创建和修改 IAM 资源,这可能包括添加用户或角色。

当前唯一可用的值是“CAPABILITY_IAM”和“CAPABILITY_NAMED_IAM”。可以提供两者之一或两者。

以下资源需要指定这两个参数之一或两者:AWS::IAM::AccessKey、AWS::IAM::Group、AWS::IAM::InstanceProfile、AWS::IAM::Policy、AWS::IAM::Role、AWS::IAM::User、AWS::IAM::UserToGroupAddition

选项

  • "CAPABILITY_IAM"

  • "CAPABILITY_NAMED_IAM"

debug_botocore_endpoint_logs

布尔值

使用 botocore.endpoint 记录器来解析在任务期间进行的唯一(而不是总计)"resource:action" API 调用,并将集合输出到任务结果中的 resource_actions 密钥。使用 aws_resource_action 回调将输出到 playbook 期间进行的总列表。

也可以使用 ANSIBLE_DEBUG_BOTOCORE_LOGS 环境变量。

选项

  • false ← (默认)

  • true

description

字符串

此堆栈集创建内容的描述。

endpoint_url

别名:ec2_url、aws_endpoint_url、s3_url

字符串

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

也可以按优先级递减的顺序使用 AWS_URLEC2_URL 环境变量。

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

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

execution_role_name

别名: exec_role_name, exec_role, execution_role

字符串

执行角色的ARN,指的是 CloudFormation 堆栈集在您的子账户中扮演的角色。

此参数**不能**是ARN,并且角色必须存在于指定的每个子账户中。

执行角色的默认名称为 AWSCloudFormationStackSetExecutionRole

failure_tolerance

字典

设置运行堆栈实例更新时被视为“失败”的条件,以及每次可以执行多少更新。

默认值: {}

fail_count

整数

每个区域中允许此操作失败的账户数量,超过此数量,CloudFormation 将停止该区域中的操作。

您必须指定fail_countfail_percentage 之一。

fail_percentage

整数

每个区域中允许此堆栈操作失败的账户百分比,超过此百分比,CloudFormation 将停止该区域中的操作。

您必须指定fail_countfail_percentage 之一。

parallel_count

整数

同时执行此操作的账户最大数量。

parallel_count 最多比 fail_count 多一个。

您必须指定parallel_countparallel_percentage 之一。

请注意,此设置允许您指定操作的最大值。对于大型部署,在某些情况下,实际数量可能较低。

parallel_percentage

整数

同时执行此操作的账户最大百分比。

您必须指定parallel_countparallel_percentage 之一。

请注意,此设置允许您指定操作的最大值。对于大型部署,在某些情况下,实际百分比可能较低。

name

字符串 / 必需

CloudFormation 堆栈集的名称。

parameters

字典

堆栈所有模板变量的哈希列表。值可以是字符串或字典。

字典可用于设置其他模板参数属性,例如 UsePreviousValue(参见示例)。

默认值: {}

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 选项互斥。

purge_stacks

布尔值

仅在 state=absent 时适用。设置删除堆栈集时是否也应删除堆栈实例。

默认情况下,将删除实例。如果要在删除堆栈集时保留堆栈,请设置 purge_stacks=false

选项

  • false

  • true ← (默认)

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 月 1 日后的版本中删除。

EC2_REGION 环境变量的支持已弃用,将在 2024 年 12 月 1 日后的版本中删除。

regions

列表 / 元素=字符串

要在其中创建堆栈实例的 AWS 区域列表。region 参数选择创建堆栈集的位置,而 regions 指定堆栈实例的区域。

必须至少指定一个区域才能创建堆栈集。在更新时,如果指定的区域较少,则只有指定的区域的堆栈实例将被更新。

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 月 1 日后的版本中删除。

EC2_SECRET_KEY 环境变量的支持已弃用,将在 2024 年 12 月 1 日后的版本中删除。

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 月 1 日后的版本中删除。

EC2_SECRET_KEYAWS_SECURITY_TOKEN 环境变量的支持已弃用,将在 2024 年 12 月 1 日后的版本中删除。

state

字符串

如果 state=present,则创建堆栈。如果 state=present 并且堆栈存在且模板已更改,则将其更新。如果 state=absent,则删除堆栈。

选项

  • "present" ← (默认)

  • "absent"

tags

字典

要在堆栈创建期间与堆栈及其资源关联的标签字典。

稍后可以更新,更新标签会删除以前的条目。

template

路径

CloudFormation 模板的本地路径。

这必须是相对于工作目录的文件的完整路径。如果使用角色,这可能类似于 roles/cloudformation/files/cloudformation-example.json

如果 state=present 且堆栈尚不存在,则必须指定 templatetemplate_bodytemplate_url 之一(但只能指定其中一个)。

如果 state=present,堆栈存在,并且未指定 templatetemplate_bodytemplate_url,则将重用以前的模板。

template_body

字符串

模板正文。使用此参数传入 CloudFormation 模板的实际正文。

如果 state=present 且堆栈尚不存在,则必须指定 templatetemplate_bodytemplate_url 之一(但只能指定其中一个)。

如果 state=present,堆栈存在,并且未指定 templatetemplate_bodytemplate_url,则将重用以前的模板。

template_url

字符串

包含模板正文的文件位置。

URL 必须指向位于与堆栈相同区域的 S3 存储桶中的模板(最大大小为 307,200 字节)。

如果 state=present 且堆栈尚不存在,则必须指定 templatetemplate_bodytemplate_url 之一(但只能指定其中一个)。

如果 state=present,堆栈存在,并且未指定 templatetemplate_bodytemplate_url,则将重用以前的模板。

validate_certs

布尔值

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

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

选项

  • false

  • true ← (默认)

wait

布尔值

是否等待堆栈操作完成。这包括等待堆栈实例达到 UPDATE_COMPLETE 状态。

如果您选择不等待,则此模块不会在堆栈操作失败时发出通知,因为它不会等待它们完成。

选项

  • false ← (默认)

  • true

wait_timeout

整数

等待堆栈完成创建/更新/删除操作的时间(以秒为单位)。

默认值: 900

备注

注意

  • 要创建单个堆栈,您需要 amazon.aws.cloudformation 模块。

  • 警告:对于模块,环境变量和配置文件是从 Ansible 的“主机”上下文而不是“控制器”上下文读取的。因此,可能需要将文件显式复制到“主机”。对于查找和连接插件,环境变量和配置文件是从 Ansible 的“控制器”上下文而不是“主机”上下文读取的。

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

示例

- name: Create a stack set with instances in two accounts
  community.aws.cloudformation_stack_set:
    name: my-stack
    description: Test stack in two accounts
    state: present
    template_url: https://s3.amazonaws.com/my-bucket/cloudformation.template
    accounts:
      - 123456789012
      - 234567890123
    regions:
      - us-east-1

- name: on subsequent calls, templates are optional but parameters and tags can be altered
  community.aws.cloudformation_stack_set:
    name: my-stack
    state: present
    parameters:
      InstanceName: my_stacked_instance
    tags:
      foo: bar
      test: stack
    accounts:
      - 123456789012
      - 234567890123
    regions:
      - us-east-1

- name: The same type of update, but wait for the update to complete in all stacks
  community.aws.cloudformation_stack_set:
    name: my-stack
    state: present
    wait: true
    parameters:
      InstanceName: my_restacked_instance
    tags:
      foo: bar
      test: stack
    accounts:
      - 123456789012
      - 234567890123
    regions:
      - us-east-1

- name: Register new accounts (create new stack instances) with an existing stack set.
  community.aws.cloudformation_stack_set:
    name: my-stack
    state: present
    wait: true
    parameters:
      InstanceName: my_restacked_instance
    tags:
      foo: bar
      test: stack
    accounts:
      - 123456789012
      - 234567890123
      - 345678901234
    regions:
      - us-east-1

返回值

常见返回值已在此处记录 此处,以下是此模块特有的字段

描述

operations

列表 / 元素=字符串

此 cloudformation_stack_set 模块运行启动的所有操作

返回:始终

示例: [{"action": "CREATE", "administration_role_arn": "arn:aws:iam::1234567890:role/AWSCloudFormationStackSetAdministrationRole", "creation_timestamp": "2018-06-18T17:40:46.372000+00:00", "end_timestamp": "2018-06-18T17:41:24.560000+00:00", "execution_role_name": "AWSCloudFormationStackSetExecutionRole", "operation_id": "Ansible-StackInstance-Create-0ff2af5b-251d-4fdb-8b89-1ee444eba8b8", "operation_preferences": {"region_order": ["us-east-1", "us-east-2"]}, "stack_set_id": "TestStackPrime:19f3f684-aae9-4e67-ba36-e09f92cf5929", "status": "FAILED"}]

operations_log

列表 / 元素=字符串

CloudFormation 事件日志中的最新事件。在某些情况下,这可能是先前运行的事件。

返回:始终

示例: [{"action": "CREATE", "creation_timestamp": "2018-06-18T17:40:46.372000+00:00", "end_timestamp": "2018-06-18T17:41:24.560000+00:00", "operation_id": "Ansible-StackInstance-Create-0ff2af5b-251d-4fdb-8b89-1ee444eba8b8", "stack_instances": [{"account": "1234567890", "region": "us-east-1", "stack_set_id": "TestStackPrime:19f3f684-aae9-4e67-ba36-e09f92cf5929", "status": "OUTDATED", "status_reason": "Account 1234567890 should have 'AWSCloudFormationStackSetAdministrationRole' role with trust relationship to CloudFormation service."}], "status": "FAILED"}]

stack_instances

列表 / 元素=字符串

属于此堆栈集的 CloudFormation 堆栈实例。这还包括它们的区域和账户 ID。

返回: state == present

示例: [{"account": "1234567890", "region": "us-east-1", "stack_set_id": "TestStackPrime:19f3f684-aae9-4e67-ba36-e09f92cf5929", "status": "OUTDATED", "status_reason": "Account 1234567890 should have 'AWSCloudFormationStackSetAdministrationRole' role with trust relationship to CloudFormation service.\n"}, {"account": "1234567890", "region": "us-east-2", "stack_set_id": "TestStackPrime:19f3f684-aae9-4e67-ba36-e09f92cf5929", "status": "OUTDATED", "status_reason": "Cancelled since failure tolerance has exceeded"}]

stack_set

字典

关于当前部署的堆栈集、其参数及其标签的事实信息。

返回: state == present

示例: {"administration_role_arn": "arn:aws:iam::1234567890:role/AWSCloudFormationStackSetAdministrationRole", "capabilities": [], "description": "test stack PRIME", "execution_role_name": "AWSCloudFormationStackSetExecutionRole", "parameters": [], "stack_set_arn": "arn:aws:cloudformation:us-east-1:1234567890:stackset/TestStackPrime:19f3f684-aae9-467-ba36-e09f92cf5929", "stack_set_id": "TestStackPrime:19f3f684-aae9-4e67-ba36-e09f92cf5929", "stack_set_name": "TestStackPrime", "status": "ACTIVE", "tags": {"Some": "Thing", "an": "other"}, "template_body": "AWSTemplateFormatVersion: \"2010-09-09\"\nParameters: {}\nResources:\n  Bukkit:\n    Type: \"AWS::S3::Bucket\"\n    Properties: {}\n  other:\n    Type: \"AWS::SNS::Topic\"\n    Properties: {}\n"}

作者

  • Ryan Scott Brown (@ryansb)