之前的Puppet通知要求不按预期工作

时间:2017-11-21 09:11:25

标签: puppet puppet-enterprise

我正在尝试在服务资源和两个exec资源之间创建关系。当服务发生变化时,服务应触发Exec ['before']并在服务被修改后启动Exec ['after']。

class foobar (
$debug = true
) {

    service { "sshd":
        ensure => 'stopped',
        notify => Exec['before']
    }

    exec { "before":
        command => "/bin/echo before",
        refreshonly => true,
    }

    exec { "after":
        refreshonly => true,
        command => "/bin/echo after",
    }

}

我已尝试过一切,但Exec ['before']在服务后不断被触发:

Notice: Compiled catalog for puppet.puppettest.local in environment production in 0.55 seconds
Notice: /Stage[main]/Foobar/Service[sshd]/ensure: ensure changed 'running' to 'stopped'
Notice: /Stage[main]/Foobar/Exec[before]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 0.04 seconds

如何确保Exec ['before']在服务之前运行,但前提是服务有变化而不是每次运行都有变化?

KR

1 个答案:

答案 0 :(得分:0)

您的元参数不正确。通过将ThingA设置为notify ThingB,您告诉Puppet ThingA必须在ThingB之前运行。 refresh_only => true之前的事情在其他事情之前执行会很棘手,因为他们需要先运行一些东西才能刷新它们。

如果您希望订单为Exec['before'] -> Service['sshd'] -> Exec['after'],则需要执行此类操作。

class foobar (
    $debug = true
) {

    service { "sshd":
        ensure  => 'stopped',
        notify  => Exec['after'],
        require => Exec['before'],
    }

    exec { "before":
        command => "/bin/echo before",
        onlyif  => "some command that helps determine if this should run",
    }

    exec { "after":
        command     => "/bin/echo after",
        refreshonly => true,
    }

}