如果我将 DSC 配置嵌套在这样的单个文件中,它可以正常工作:
Configuration Secondary {
Param ($SomeParameter)
Environment Test {
Name = $SomeParameter
Value = "12345"
}
}
Configuration MyConfiguration {
Node localhost {
Secondary TheSecondary {
SomeParameter = "TestEnvVar"
}
}
}
MyConfiguration
Start-DscConfiguration .\MyConfiguration -Wait -Verbose
Run Code Online (Sandbox Code Playgroud)
我想将我的配置分成两个单独的文件。一个将点源另一个以包含配置。
次要.ps1:
Configuration Secondary {
Param ($SomeParameter)
Environment Test {
Name = $SomeParameter
Value = "12345"
}
}
Run Code Online (Sandbox Code Playgroud)
主要.ps1:
. .\Secondary.ps1
Configuration MyConfiguration {
Node localhost {
Secondary TheSecondary {
SomeParameter = "TestEnvVar"
}
}
}
MyConfiguration
Start-DscConfiguration .\MyConfiguration -Wait -Verbose
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这不会获取传递给辅助配置的参数,因此会导致错误:
Could not find mandatory property Name. Add this property and try again.
+ CategoryInfo : ObjectNotFound: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 6
+ PSComputerName : localhost
Run Code Online (Sandbox Code Playgroud)
它在同一个文件中工作但在点源时不起作用,这似乎很奇怪。我认为 dot-sourcing 与在同一个文件中包含代码基本相同。我在这里缺少什么?
如果要从未在同一文件中定义的另一个配置中引用配置,则需要使用复合资源模式。
在一个模块中,您将创建一个 DscResources 文件夹。在该文件夹中,您将创建一个模块来保存您的复合配置。复合配置将在扩展名为 .schema.psm1 的文件中定义。该文件将需要一个指向 schema.psm1 文件作为根模块的模块清单。
有关更多详细信息和示例,请查看 PowerShell 团队博客 - http://blogs.msdn.com/b/powershell/archive/2014/02/25/reusing-existing-configuration-scripts-in-powershell-desired-状态配置.aspx
归档时间: |
|
查看次数: |
5987 次 |
最近记录: |