azure.azcollection.azure_rm_deployment 模块 – 创建或销毁 Azure 资源管理器模板部署
注意
此模块是 azure.azcollection 集合(版本 3.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install azure.azcollection
。您需要进一步的要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:azure.azcollection.azure_rm_deployment
。
azure.azcollection 0.1.0 中的新增功能
概要
通过 Azure SDK for Python 创建或销毁 Azure 资源管理器模板部署。
您可以在 GitHub 上找到一些快速入门模板,请访问 https://github.com/azure/azure-quickstart-templates。
有关 Azure 资源管理器模板的更多信息,请参阅 https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-deploy/。
要求
执行此模块的主机上需要满足以下要求。
python >= 2.7
执行此模块的主机必须通过 galaxy 安装 azure.azcollection 集合
必须通过 pip 在执行来自 azure.azcollection 模块的主机上安装集合的 requirements.txt 中列出的所有 python 包
完整的安装说明可在 https://galaxy.ansible.com/azure/azcollection 中找到
参数
参数 |
注释 |
---|---|
Active Directory 用户名。当使用 Active Directory 用户而不是服务主体进行身份验证时使用。 |
|
Azure AD 授权 URL。当使用用户名/密码进行身份验证,并且有自己的 ADFS 授权时使用。 |
|
选择与 Azure 服务通信时使用的 API 配置文件。默认值 默认值: |
|
用于控制标签字段是规范的还是仅附加到现有标签。 当为规范时,任何在标签参数中未找到的标签将从对象的元数据中删除。 选项
|
|
控制用于身份验证的凭据来源。 也可以通过 当设置为 当设置为 当设置为 当设置为 当设置为
选项
|
|
控制 Azure 端点的证书验证行为。默认情况下,所有模块都将验证服务器证书,但是当使用 HTTPS 代理时,或者针对 Azure Stack 时,可能需要通过传递 选项
|
|
Azure 客户端 ID。当使用服务主体或托管标识 (msi) 进行身份验证时使用。 也可以通过 |
|
对于美国公共云以外的云环境,需要指定环境名称(由 Azure Python SDK 定义,例如 默认值: |
|
在增量模式下,部署资源时不会删除模板中未包含的现有资源。 在完整模式下,部署资源时会删除资源组中模板未包含的现有资源。 选项
|
|
确定在尝试进行身份验证时是否执行实例发现。将其设置为 true 将完全禁用实例发现和授权验证。此功能旨在用于无法访问元数据终结点的情况,例如在私有云或 Azure Stack 中。实例发现的过程包括从 https://login.microsoft.com/ 检索授权元数据以验证授权。通过将此设置为 **True**,将禁用授权的验证。因此,至关重要的是要确保配置的授权主机是有效且可信的。 通过凭据文件配置文件或 选项
|
|
资源组所在的地理位置。 默认值: |
|
父参数。 |
|
父参数。 |
|
要在资源组部署历史记录中跟踪的部署名称。 重用部署名称将覆盖资源组部署历史记录中的先前值。 默认值: |
|
部署模板所需的所有模板变量的哈希值。此参数与 *parameters_link* 互斥。 如果 *state=present*,则需要 *parameters_link* 或 *parameters*。 |
|
包含参数主体的文件的 URI。此参数与 *parameters* 互斥。 如果 *state=present*,则需要 *parameters_link* 或 *parameters*。 |
|
Active Directory 用户密码。在通过 Active Directory 用户而非服务主体进行身份验证时使用。 |
|
在 ~/.azure/credentials 文件中找到的安全配置文件。 |
|
要使用或创建以托管已部署模板的资源组名称。 |
|
Azure 客户端密钥。在通过服务主体进行身份验证时使用。 |
|
如果 *state=present*,将创建模板。 如果 *state=present* 且部署已存在,则会更新它。 如果 *state=absent*,将删除部署资源。 选项
|
|
您的 Azure 订阅 ID。 |
|
要作为元数据分配给对象的字符串:字符串对的字典。 对象上的元数据标签将使用任何提供的值进行更新。 要删除标签,请将 append_tags 选项设置为 false。 目前,Azure DNS 区域和流量管理器服务也不允许在标签中使用空格。 Azure Front Door 不支持使用 Azure Automation 和 Azure CDN 仅支持资源上的 15 个标签。 |
|
包含模板内联的哈希值。此参数与 *template_link* 互斥。 如果 *state=present*,则需要 *template* 或 *template_link*。 |
|
包含模板主体的文件的 URI。此参数与 *template* 互斥。 如果 *state=present*,则需要 *template* 或 *template_link*。 |
|
Azure 租户 ID。在通过服务主体进行身份验证时使用。 |
|
在 *x509_certificate_path* 中指定的私钥的指纹。 在通过服务主体进行身份验证时使用。 如果定义了 *x509_certificate_path*,则为必需项。 |
|
是否阻塞直到部署完成。 选项
|
|
等待部署完成时,轮询之间等待的时间(以秒为单位)。 默认值: |
|
用于以 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
命令进行身份验证。
示例
# Destroy a template deployment
- name: Destroy Azure Deploy
azure_rm_deployment:
resource_group: myResourceGroup
name: myDeployment
state: absent
# Create or update a template deployment based on uris using parameter and template links
- name: Create Azure Deploy
azure_rm_deployment:
resource_group: myResourceGroup
name: myDeployment
template_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.json'
parameters_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.parameters.json'
# Create or update a template deployment based on a uri to the template and parameters specified inline.
# This deploys a VM with SSH support for a given public key, then stores the result in 'azure_vms'. The result is then
# used to create a new host group. This host group is then used to wait for each instance to respond to the public IP SSH.
- name: Create Azure Deploy
azure_rm_deployment:
resource_group: myResourceGroup
name: myDeployment
parameters:
newStorageAccountName:
value: devopsclestorage1
adminUsername:
value: devopscle
dnsNameForPublicIP:
value: devopscleazure
location:
value: West US
vmSize:
value: Standard_A2
vmName:
value: ansibleSshVm
sshKeyData:
value: YOUR_SSH_PUBLIC_KEY
template_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-sshkey/azuredeploy.json'
register: azure
- name: Add new instance to host group
add_host:
hostname: "{{ item['ips'][0].public_ip }}"
groupname: azure_vms
loop: "{{ azure.deployment.instances }}"
# Deploy an Azure WebApp running a hello world'ish node app
- name: Create Azure WebApp Deployment at http://devopscleweb.azurewebsites.net/hello.js
azure_rm_deployment:
resource_group: myResourceGroup
name: myDeployment
parameters:
repoURL:
value: 'https://github.com/devigned/az-roadshow-oss.git'
siteName:
value: devopscleweb
hostingPlanName:
value: someplan
siteLocation:
value: westus
sku:
value: Standard
template_link: 'https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-web-app-github-deploy/azuredeploy.json'
# Create or update a template deployment based on an inline template and parameters
- name: Create Azure Deploy
azure_rm_deployment:
resource_group: myResourceGroup
name: myDeployment
template:
$schema: "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
contentVersion: "1.0.0.0"
parameters:
newStorageAccountName:
type: "string"
metadata:
description: "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed."
adminUsername:
type: "string"
metadata:
description: "User name for the Virtual Machine."
adminPassword:
type: "securestring"
metadata:
description: "Password for the Virtual Machine."
dnsNameForPublicIP:
type: "string"
metadata:
description: "Unique DNS Name for the Public IP used to access the Virtual Machine."
ubuntuOSVersion:
type: "string"
defaultValue: "14.04.2-LTS"
allowedValues:
- "12.04.5-LTS"
- "14.04.2-LTS"
- "15.04"
metadata:
description: >
The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version.
Allowed values: 12.04.5-LTS, 14.04.2-LTS, 15.04."
variables:
location: "West US"
imagePublisher: "Canonical"
imageOffer: "UbuntuServer"
OSDiskName: "osdiskforlinuxsimple"
nicName: "myVMNic"
addressPrefix: "192.0.2.0/24"
subnetName: "Subnet"
subnetPrefix: "10.0.0.0/24"
storageAccountType: "Standard_LRS"
publicIPAddressName: "myPublicIP"
publicIPAddressType: "Dynamic"
vmStorageAccountContainerName: "vhds"
vmName: "MyUbuntuVM"
vmSize: "Standard_D1"
virtualNetworkName: "MyVNET"
vnetID: "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]"
subnetRef: "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]"
resources:
- type: "Microsoft.Storage/storageAccounts"
name: "[parameters('newStorageAccountName')]"
apiVersion: "2015-05-01-preview"
location: "[variables('location')]"
properties:
accountType: "[variables('storageAccountType')]"
- apiVersion: "2015-05-01-preview"
type: "Microsoft.Network/publicIPAddresses"
name: "[variables('publicIPAddressName')]"
location: "[variables('location')]"
properties:
publicIPAllocationMethod: "[variables('publicIPAddressType')]"
dnsSettings:
domainNameLabel: "[parameters('dnsNameForPublicIP')]"
- type: "Microsoft.Network/virtualNetworks"
apiVersion: "2015-05-01-preview"
name: "[variables('virtualNetworkName')]"
location: "[variables('location')]"
properties:
addressSpace:
addressPrefixes:
- "[variables('addressPrefix')]"
subnets:
-
name: "[variables('subnetName')]"
properties:
addressPrefix: "[variables('subnetPrefix')]"
- type: "Microsoft.Network/networkInterfaces"
apiVersion: "2015-05-01-preview"
name: "[variables('nicName')]"
location: "[variables('location')]"
dependsOn:
- "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
- "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
properties:
ipConfigurations:
-
name: "ipconfig1"
properties:
privateIPAllocationMethod: "Dynamic"
publicIPAddress:
id: "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
subnet:
id: "[variables('subnetRef')]"
- type: "Microsoft.Compute/virtualMachines"
apiVersion: "2015-06-15"
name: "[variables('vmName')]"
location: "[variables('location')]"
dependsOn:
- "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]"
- "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
properties:
hardwareProfile:
vmSize: "[variables('vmSize')]"
osProfile:
computername: "[variables('vmName')]"
adminUsername: "[parameters('adminUsername')]"
adminPassword: "[parameters('adminPassword')]"
storageProfile:
imageReference:
publisher: "[variables('imagePublisher')]"
offer: "[variables('imageOffer')]"
sku: "[parameters('ubuntuOSVersion')]"
version: "latest"
osDisk:
name: "osdisk"
vhd:
uri: >
[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',
variables('OSDiskName'),'.vhd')]
caching: "ReadWrite"
createOption: "FromImage"
networkProfile:
networkInterfaces:
-
id: "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
diagnosticsProfile:
bootDiagnostics:
enabled: "true"
storageUri: "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net')]"
parameters:
newStorageAccountName:
value: devopsclestorage
adminUsername:
value: devopscle
adminPassword:
value: Password1!
dnsNameForPublicIP:
value: devopscleazure
返回值
通用返回值记录在 此处,以下是此模块特有的字段
键 |
描述 |
---|---|
部署详细信息。 已返回: 总是 |
|
资源组的名称。 已返回: 总是 示例: |
|
部署的 Azure ID。 已返回: 总是 示例: |
|
为每个 VM 实例提供公共 IP 地址。 已返回: 总是 |
|
公共 IP 地址列表。 已返回: 总是 |
|
DNS 设置。 已返回: 总是 |
|
域名标签。 已返回: 总是 示例: |
|
完全限定域名。 已返回: 总是 示例: |
|
公共 IP 资源 ID。 已返回: 总是 示例: |
|
公共 IP 资源名称。 已返回: 总是 示例: |
|
公共 IP 地址值。 已返回: 总是 示例: |
|
公共 IP 分配方法。 已返回: 总是 示例: |
|
虚拟机名称。 已返回: 总是 示例: |
|
部署的名称。 已返回: 总是 示例: |
|
从部署收到的输出的字典。 已返回: 总是 示例: |