azure - 使用具有 Azure DSC 扩展的自定义复合资源

标签 azure deployment azure-powershell dsc

我有一个部署 DSC 扩展的 VM 模板。它运行良好,但我的配置正在增长,因此我将其重构为使用复合资源,并将其重新发布到 blob 存储 Publish-AzureRmVMDscConfiguration .

我验证了 Blob 存储中的 .ps1.zip 文件包含我的自定义模块,并且该模块列在 dscmetadata.json 下。但是,当我部署时,DSC 扩展失败。 C:\WindowsAzure\Logs\Plugins\Microsoft.Powershell.DSC\2.17.0.0下的日志揭示原因:

C:\Packages\Plugins\Microsoft.Powershell.DSC\2.17.0.0\bin..\DSCWork\AppServerDev.ps1.0\AppserverDev.ps1

PSDesiredStateConfiguration\node : The module 'xCustomResource' could not be loaded. For more information, run 'Import-Module xCustomResource'.

At C:\Packages\Plugins\Microsoft.Powershell.DSC\2.17.0.0\DSCWork\AppServerDev.ps1.0\AppserverDev.ps1:9 char:3

  • node "localhost"
  • ~~~~
    • CategoryInfo : ObjectNotFound: (xCustomResource\xCustomResource:String) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
    • FullyQualifiedErrorId : CouldNotAutoLoadModule,PSDesiredStateConfiguration\node

以下是我的配置文件的相关部分:

configuration AppServerDev
{
    param($environment)
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'SaaSModule'

    node "localhost"
    {
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
            ConfigurationMode = "ApplyAndAutoCorrect"
            ConfigurationModeFrequencyMins = 1440
        }
        xDCTPlatformVM VM {
            OctopusParametersFile = $environment
            ChocolateyPackages = @(
                'googlechrome',
                'notepadplusplus',
                '7zip',
                'microsoftwse',
                'octopusdeploy.tentacle',
                'sqlserver-cmdlineutils'
                )
        }
    }
}

正在运行Get-Module -ListAvailable揭示DankModule找到了,我可以从 powershell 运行 Import-Module DankModule它按预期工作。我认为困惑来自于它试图导入 xCustomResource而不是DankModule但我的 .ps1 文件位于 C:\Packages\Plugins\Microsoft.Powershell.DSC\2.17.0.0\DSCWork 下说

Import-Module "DankModule"

而不是

Import-Module "xCustomType"

为什么要尝试导入 xCustomType而不是DankModule ?我怎样才能找到DankModule可用并包含 xCustomType

更新:Get-Module -ListAvailable显示DankModule已安装但 Get-DSCResource -Module DankModule不返回任何内容。

最佳答案

我不确定,但我认为这是我的菜鸟错误,因为我没有构建 powershell 模块的经验。我正在使用 this page以及this one为了构建我的模块,我通过使用 New-ModuleManifest 获得了一个有效的模块文件,我在它们中都提到了正确的文件结构,例如

C:\Program Files\WindowsPowerShell\Modules\

DankModule
    DankModule.psd1
    DankModule.psm1
    DSCResources
        xCustomResource
            xCustomResource.psd1
                RootModule = ‘xCustomResource.schema.psm1'
            xCustomResource.schema.psm1
                Configuration, no Node block

但我没有意识到我还需要进行一些调整。我需要将 DankModule.psd1 中的 RootModule 属性更正为如下所示:

RootModule = 'C:\Program Files\WindowsPowerShell\Modules\DankModule\DankModule.psm1'

还需要在我的空白 DankModule.psm1 中添加一行引用我的 xCustomResource.schema.psm1 等效项:

. .\DSCResources\xCustomResource\xCustomResource.schema.psm1

这是我的模块级 .psm1 文件中的唯一一行,现在一切正常。我还一度从两个 .psd1 文件中删除了所有 \0,但现在我不确定这是否绝对必要。

关于azure - 使用具有 Azure DSC 扩展的自定义复合资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42306630/

相关文章:

azure - 有没有办法使用 bacpac 或类似工具以编程方式备份​​和恢复 Azure 数据库?

azure - 创建表期间写入 UserMetadata 字段

spring - 如何将 Spring Boot 应用程序部署到 Tomcat 6 Servlet 2.5

deployment - 如何使 S3 Cloudfront 上部署的 Gatsby 网站上的服务 worker 缓存失效?

python - 如何构建和部署 Python Web 应用程序

azure - APIM 背后的消费计划 Azure Function

django - python 社交身份验证更改引荐来源地址

azure - Connect-AzureAD -确认抛出 AADSTS900144 : The request body must contain the following parameter: 'code' . 错误

azure - PowerShell::Microsoft.Azure.Commands.Sql.Database.Model.AzureSqlDatabaseModel.DatabaseName

powershell - 无法安装最新的 Azure PowerShell