azure - Runbook 模块部署失败,因为它达到了终端预配状态 'Failed'

标签 azure azure-resource-manager azure-automation azure-bicep azure-runbook

我想使用二头肌在 Azure 上使用 PowerShell 创建一些自动化 Runbook。为此,我需要下面列出的一些自定义模块。

var modules = [
    'Microsoft.Graph.Authentication'
    'Microsoft.Graph.Groups'
    'Microsoft.Graph.Mail'
    'Microsoft.Graph.Planner'
    'Microsoft.Graph.Teams'
    'Microsoft.Graph.Users'
    'Microsoft.Graph.Users.Actions'
]

以下是我创建模块的方法:

resource automationResource 'Microsoft.Automation/automationAccounts@2022-08-08' = {
    // Some other properties

    resource moduleResources 'modules' = [for module in modules: {
        name: module
        properties: {
            contentLink: {
                uri: 'https://www.powershellgallery.com/api/v2/'
            }
        }
    }]
}

当我将其部署到 Azure 时,所有模块都出现下一个错误:

{
    "status": "Failed",
    "error": {
        "code": "ResourceDeploymentFailure",
        "target": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Automation/automationAccounts/xxx/modules/Microsoft.Graph.Teams",
        "message": "The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'."
    }
}

为什么模块不会添加到自动化帐户中?

最佳答案

这里有一些事情:

  1. 您需要包的完整 URL:名称 + 版本
  2. 如果包有一些依赖项,则需要先导入依赖项。

这里,所有包都依赖于 Microsoft.Graph.Authentication 包。

实现这一点的最简单方法是按顺序部署模块,但速度会很慢:

var modules = [
  {
    name: 'Microsoft.Graph.Authentication'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Groups'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Mail'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Planner'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Teams'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Users'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Users.Actions'
    version: '2.0.0-preview8'
  }
]

resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
  name: automationAccountName
}

@batchSize(1)
resource automationAccountModules 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = [for module in modules: {
  parent: automationAccount
  name: module.name
  properties: {
    contentLink: {
      uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${module.name}.${module.version}.nupkg')
    }
  }
}]

或者您可以在导入其他模块之前导入 Microsoft.Graph.Authentication:

var modules = [
  {
    name: 'Microsoft.Graph.Authentication'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Groups'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Mail'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Planner'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Teams'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Users'
    version: '2.0.0-preview8'
  }
  {
    name: 'Microsoft.Graph.Users.Actions'
    version: '2.0.0-preview8'
  }
]

resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
  name: automationAccountName
}

var authPackage = first(modules)
resource authModule 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = {
  parent: automationAccount
  name: authPackage.name
  properties: {
    contentLink: {
      uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${authPackage.name}.${authPackage.version}.nupkg')
    }
  }
}

var otherPackages = skip(modules, 1)
resource automationAccountModules 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = [for module in otherPackages: {
  dependsOn: [ authModule ]
  parent: automationAccount
  name: module.name
  properties: {
    contentLink: {
      uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${module.name}.${module.version}.nupkg')
    }
  }
}]

关于azure - Runbook 模块部署失败,因为它达到了终端预配状态 'Failed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76155998/

相关文章:

c# - PowerShell 脚本上的 Git 命令 - 授权

azure - 使用 ARM 模板创建 Microsoft.Web/serverfarms 资源

azure - 如何以编程方式在 Azure AD 中添加自定义域名?

azure - 使用 Reader UMI : "Insufficient privileges to complete the operation" 获取 Azure 自动化下的 AzADUser

Azure CLI 和 KubeCTL 的 Java 方式

django - 将带有 SQL 数据库的 Django 应用程序部署到 Azure

c# - Azure 服务总线 - 留言

azure - ARM 模板部署 - 由于与并发请求错误冲突,请求失败

通过 ARM 模板部署时,Azure 函数暂存槽交换错误

用于连接到 Azure VM 上运行的 SQL 服务器的 Azure Runbook