【问题标题】:DSC Abort on ErrorDSC 出错时中止
【发布时间】:2016-05-02 22:34:24
【问题描述】:

如果发生错误,有没有办法让 DSC 中止其配置尝试,而不仅仅是继续配置中的下一个资源?

基本上,我想关闭“on error resume next”并做厨师所做的 - 中止错误运行。

【问题讨论】:

    标签: powershell dsc powershell-5.0


    【解决方案1】:

    如果您将 DependsOn 添加到您不想继续的任何资源,如果依赖链中的任何内容出现错误,它将中止。

    Using DependsOnthis 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 中提出问题

    特拉维斯

    【讨论】:

    • 我编辑了带有链接的帖子,以提交用户语音项目,以向我们的产品团队建议更好的行为,但目前,我相信这是最好的答案。
    • 好的,谢谢。那真不幸。 DSC 在概念上确实是一个好主意。不幸的是,它似乎很脆弱,让它工作是一件令人头疼的事情。目前使用 Chef 引擎似乎是一种更稳定的解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    相关资源
    最近更新 更多