【发布时间】:2016-05-02 22:34:24
【问题描述】:
如果发生错误,有没有办法让 DSC 中止其配置尝试,而不仅仅是继续配置中的下一个资源?
基本上,我想关闭“on error resume next”并做厨师所做的 - 中止错误运行。
【问题讨论】:
标签: powershell dsc powershell-5.0
如果发生错误,有没有办法让 DSC 中止其配置尝试,而不仅仅是继续配置中的下一个资源?
基本上,我想关闭“on error resume next”并做厨师所做的 - 中止错误运行。
【问题讨论】:
标签: powershell dsc powershell-5.0
如果您将 DependsOn 添加到您不想继续的任何资源,如果依赖链中的任何内容出现错误,它将中止。
见Using DependsOn和this StackOverflow answer describing dependencies
例如,在下面的配置中,如果组失败,则不会创建其他资源,因为 UserExample 依赖于 GroupExample,而 UserExample2 依赖于 UserExample。
Configuration DependsOnExample {
Node Test-PC1 {
Group GroupExample {
Ensure = "Present"
GroupName = "TestGroup"
}
User UserExample {
Ensure = "Present"
UserName = "TestUser"
FullName = "TestUser"
DependsOn = "[Group]GroupExample"
}
User UserExample2 {
Ensure = "Present"
UserName = "TestUser2"
FullName = "TestUser2"
DependsOn = "[User]UserExample"
}
}
}
目前没有一种方法可以在没有显式依赖的情况下获得相同的行为。
如果您想向产品团队请求该功能,我建议您在PowerShell User Voice 中提出问题
特拉维斯
【讨论】: