azure.azcollection.azure_rm_storageaccountmanagementpolicy 模块 – 管理存储帐户管理策略

注意

此模块是 azure.azcollection 集合(版本 3.1.0)的一部分。

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

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

要在 playbook 中使用它,请指定:azure.azcollection.azure_rm_storageaccountmanagementpolicy

azure.azcollection 2.4.0 中的新增功能

概要

  • 创建、更新或删除存储帐户管理策略。

要求

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

  • python >= 2.7

  • 执行此模块的主机必须通过 galaxy 安装 azure.azcollection 集合

  • 必须通过 pip 在执行来自 azure.azcollection 的模块的主机上安装集合的 requirements.txt 中列出的所有 python 包

  • 完整的安装说明可以在 https://galaxy.ansible.com/azure/azcollection 中找到

参数

参数

注释

ad_user

字符串

Active Directory 用户名。在用 Active Directory 用户而不是服务主体进行身份验证时使用。

adfs_authority_url

字符串

在 azure.azcollection 0.0.1 中添加

Azure AD 授权 URL。在用用户名/密码进行身份验证并且有您自己的 ADFS 授权时使用。

api_profile

字符串

在 azure.azcollection 0.0.1 中添加

选择与 Azure 服务通信时使用的 API 配置文件。默认值 latest 适用于公共云;未来的值将允许与 Azure Stack 一起使用。

默认值: "latest"

auth_source

字符串

在 azure.azcollection 0.0.1 中添加

控制用于身份验证的凭据的来源。

也可以通过 ANSIBLE_AZURE_AUTH_SOURCE 环境变量设置。

当设置为 auto (默认值)时,优先级为模块参数 -> env -> credential_file -> cli

当设置为 env 时,凭据将从环境变量中读取

当设置为 credential_file 时,它将从 ~/.azure/credentials 中读取配置文件。

当设置为 cli 时,凭据将从 Azure CLI 配置文件中获取。subscription_id 或环境变量 AZURE_SUBSCRIPTION_ID 可用于标识订阅 ID,如果存在多个订阅 ID,则使用默认的 az cli 订阅。

当设置为 msi 时,主机必须是启用了 MSI 扩展的 azure 资源。subscription_id 或环境变量 AZURE_SUBSCRIPTION_ID 可用于标识订阅 ID,如果资源被授予对多个订阅的访问权限,否则将选择第一个订阅。

msi 在 Ansible 2.6 中添加。

选项

  • "auto" ← (默认)

  • "cli"

  • "credential_file"

  • "env"

  • "msi"

cert_validation_mode

字符串

在 azure.azcollection 0.0.1 中添加

控制 Azure 端点的证书验证行为。默认情况下,所有模块都会验证服务器证书,但是当使用 HTTPS 代理或针对 Azure Stack 时,可能需要通过传递 ignore 来禁用此行为。也可以通过凭据文件配置文件或 AZURE_CERT_VALIDATION 环境变量设置。

选项

  • "ignore"

  • "validate"

client_id

字符串

Azure 客户端 ID。在使用服务主体或托管标识 (msi) 进行身份验证时使用。

也可以通过 AZURE_CLIENT_ID 环境变量设置。

cloud_environment

字符串

在 azure.azcollection 0.0.1 中添加

对于美国公共云以外的云环境,环境名称(由 Azure Python SDK 定义,例如,AzureChinaCloudAzureUSGovernment),或元数据发现终结点 URL(Azure Stack 所需)。也可以通过凭据文件配置文件或 AZURE_CLOUD_ENVIRONMENT 环境变量设置。

默认值: "AzureCloud"

disable_instance_discovery

布尔值

在 azure.azcollection 2.3.0 中添加

确定在尝试进行身份验证时是否执行实例发现。将其设置为 true 将完全禁用实例发现和授权验证。此功能旨在用于无法访问元数据终结点的情况,例如在私有云或 Azure Stack 中。实例发现的过程需要从 https://login.microsoft.com/ 中检索授权元数据,以验证授权。通过将其设置为 **True**,将禁用授权验证。因此,至关重要的是要确保配置的授权主机有效且值得信赖。

通过凭据文件配置文件或 AZURE_DISABLE_INSTANCE_DISCOVERY 环境变量设置。

选项

  • false ← (默认)

  • true

log_mode

字符串

父参数。

log_path

字符串

父参数。

password

字符串

Active Directory 用户密码。在用 Active Directory 用户而不是服务主体进行身份验证时使用。

profile

字符串

在 ~/.azure/credentials 文件中找到的安全配置文件。

resource_group

别名: resource_group_name

字符串 / 必需

要使用的资源组的名称。

rules

列表 / 元素=字典

存储帐户管理策略规则。

定义

字典 / 必需

是否启用该规则

actions

字典 / 必需

一个定义操作集的对象。

base_blob

字典

基本 Blob 的管理策略操作。

delete

字典

删除 Blob 的功能。

days_after_last_access_time_greater_than

浮点数

此属性只能与上次访问时间跟踪策略结合使用。

days_after_modification_greater_than

浮点数

表示上次修改后天数的年龄的值。

enable_auto_tier_to_hot_from_cool

布尔值

此属性启用 Blob 在被访问时从冷层自动分层到热层。

选项

  • false

  • true

tier_to_archive

字典

将 Blob 分层到存档存储的功能。

支持当前位于热层或冷层的 Blob。

days_after_last_access_time_greater_than

浮点数

此属性只能与上次访问时间跟踪策略结合使用。

days_after_modification_greater_than

浮点数

表示上次修改后天数的年龄的值。

tier_to_cool

字典

将 Blob 分层到冷存储的功能。

支持当前位于热层的 Blob。

days_after_last_access_time_greater_than

浮点数

此属性只能与上次访问时间跟踪策略结合使用。

days_after_modification_greater_than

浮点数

表示上次修改后天数的年龄的值。

snapshot

字典

快照的管理策略操作。

delete

字典

删除 Blob 快照的功能。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

tier_to_archive

字典

将 Blob 快照分层到存档存储的功能。

支持当前位于热层或冷层的 Blob 快照。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

tier_to_cool

字典

将 Blob 快照分层到冷存储的功能。

支持位于热层的 Blob 快照。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

version

字典

版本的管理策略操作。

delete

字典

删除 Blob 版本的功能。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

tier_to_archive

字典

将 Blob 版本分层到存档存储的功能。

支持当前位于热层或冷层的 Blob 版本。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

tier_to_cool

字典

将 Blob 版本分层到冷存储的功能。

支持当前位于热层的 Blob 版本。

days_after_creation_greater_than

浮点数 / 必需

表示创建后天数的年龄的值。

filters

字典

一个定义筛选器集的对象。

blob_index_match

列表 / 元素=字典

基于 Blob 索引标记的筛选器数组,最多可以有 10 个标记筛选器。

name

字符串 / 必需

这是筛选器标记名称,它可以有 1 - 128 个字符。

op

字符串 / 必需

这是用于对象比较和筛选的比较运算符。

目前仅支持 ==(相等运算符)。

value

字符串 / 必需

这是用于基于标记筛选的筛选器标记值字段。

它可以有 0-256 个字符。

blob_types

列表 / 元素=字符串 / 必需

一个预定义枚举值的数组。

目前,blockBlob 支持所有分层和删除操作。 appendBlob 仅支持删除操作。

选项

  • "blockBlob"

  • "appendBlob"

prefix_match

列表 / 元素=字符串

要匹配的前缀字符串数组。

enabled

布尔值

是否启用该规则

选项

  • false

  • true

name

字符串 / 必需

策略规则的名称。

规则名称可以包含字母数字字符的任意组合。

type

字符串 / 必需

策略规则的类型。

选项

  • "Lifecycle"

secret

字符串

Azure 客户端密钥。使用服务主体进行身份验证时使用。

state

字符串

存储帐户管理策略的状态。使用 present 添加或更新策略规则。

使用 absent 删除所有策略规则。

选项

  • "absent"

  • "present" ← (默认)

storage_account_name

字符串 / 必需

存储帐户的名称。

subscription_id

字符串

您的 Azure 订阅 ID。

tenant

字符串

Azure 租户 ID。使用服务主体进行身份验证时使用。

thumbprint

字符串

在 azure.azcollection 1.14.0 中添加

x509_certificate_path 中指定的私钥的指纹。

使用服务主体进行身份验证时使用。

如果定义了 x509_certificate_path,则为必需。

x509_certificate_path

路径

在 azure.azcollection 1.14.0 中添加

用于以 PEM 格式创建服务主体的 X509 证书的路径。

证书必须附加到私钥。

使用服务主体进行身份验证时使用。

注释

注意

  • 要使用 Azure 进行身份验证,您可以传递参数、设置环境变量、使用存储在 ~/.azure/credentials 中的配置文件,或者在使用 az login 运行任务或剧本之前登录。

  • 也可以使用服务主体或 Active Directory 用户进行身份验证。

  • 要通过服务主体进行身份验证,请传递 subscription_id、client_id、secret 和 tenant,或者设置环境变量 AZURE_SUBSCRIPTION_ID、AZURE_CLIENT_ID、AZURE_SECRET 和 AZURE_TENANT。

  • 要通过 Active Directory 用户进行身份验证,请传递 ad_user 和 password,或者在环境中设置 AZURE_AD_USER 和 AZURE_PASSWORD。

  • 或者,凭据可以存储在 ~/.azure/credentials 中。这是一个 ini 文件,包含 [default] 部分和以下键:subscription_id、client_id、secret 和 tenant 或 subscription_id、ad_user 和 password。还可以添加其他配置文件。通过传递 profile 或在环境中设置 AZURE_PROFILE 来指定配置文件。

另请参阅

另请参阅

使用 Azure CLI 登录

如何使用 az login 命令进行身份验证。

示例

- name: Create storage account management policy with multi parameters
  azure_rm_storageaccountmanagementpolicy:
    resource_group: testRG
    storage_account_name: testaccount
    rules:
      - name: olcmtest5
        type: Lifecycle
        enabled: false
        definition:
          actions:
            base_blob:
              enable_auto_tier_to_hot_from_cool: true
              delete:
                days_after_modification_greater_than: 33
                days_after_last_access_time_greater_than: 33
              tier_to_cool:
                days_after_modification_greater_than: 33
                days_after_last_access_time_greater_than: 33
              tier_to_archive:
                days_after_modification_greater_than: 33
                days_after_last_access_time_greater_than: 33
            snapshot:
              tier_to_cool:
                days_after_creation_greater_than: 33
              tier_to_archive:
                days_after_creation_greater_than: 33
              delete:
                days_after_creation_greater_than: 33
            version:
              tier_to_archive:
                days_after_creation_greater_than: 33
              tier_to_cool:
                days_after_creation_greater_than: 33
              delete:
                days_after_creation_greater_than: 33
          filters:
            prefix_match:
              - olcmtestcontainer2
            blob_types:
              - blockBlob
              - appendBlob
            blob_index_match:
              - name: tags3
                op: '=='
                value: value3

- name: Delete management policy rules
  azure_rm_storageaccountmanagementpolicy:
    resource_group: "{{ resource_group }}"
    storage_account_name: "st{{ rpfx }}"
    state: absent

返回值

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

Key

描述

state

complex

与指定存储帐户关联的数据策略规则。

返回:始终

id

字符串

数据策略的 ID。

返回:始终

示例: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Storage/storageAccounts/sttest/managementPolicies/default"

last_modified_time

字符串

返回 ManagementPolicies 上次修改的日期和时间。

返回:始终

示例: "2024-04-12T11:40:10.376465+00:00"

name

字符串

资源的名称。

返回:始终

示例: "DefaultManagementPolicy"

policy

complex

存储帐户 ManagementPolicy。

返回:始终

rules

列表 / 元素=字符串

存储帐户管理策略规则。

返回:始终

示例: [{"definition": {"actions": {"base_blob": {"delete": {"days_after_last_access_time_greater_than": 33.0, "days_after_modification_greater_than": 33.0}, "enable_auto_tier_to_hot_from_cool": true, "tier_to_archive": {"days_after_last_access_time_greater_than": 33.0, "days_after_modification_greater_than": 33.0}, "tier_to_cool": {"days_after_last_access_time_greater_than": 33.0, "days_after_modification_greater_than": 33.0}}, "snapshot": {"delete": {"days_after_creation_greater_than": 33.0}, "tier_to_archive": {"days_after_creation_greater_than": 33.0}, "tier_to_cool": {"days_after_creation_greater_than": 33.0}}, "version": {"delete": {"days_after_creation_greater_than": 33.0}, "tier_to_archive": {"days_after_creation_greater_than": 33.0}, "tier_to_cool": {"days_after_creation_greater_than": 33.0}}}, "filters": {"blob_index_match": [{"name": "tags3", "op": "==", "value": "value3"}], "blob_types": ["blockBlob", "appendBlob"], "prefix_match": ["olcmtestcontainer2"]}}, "enabled": false, "name": "olcmtest5", "type": "Lifecycle"}]

resource_group

字符串

资源组名称。

返回:始终

示例: "testRG"

storage_account_name

字符串

存储帐户名称。

返回:始终

示例: "teststname"

type

字符串

资源的类型。

返回:始终

示例: "Microsoft.Storage/storageAccounts/managementPolicies"

作者

  • xuzhang3 (@xuzhang3)

  • Fred-sun (@Fred-sun)