1

我们使用 Boxen/Puppet 来自动构建我们的 Mac 开发笔记本电脑,第一步是安装 rabbitmq,声明 vhosts 并添加用户。

但是rabbitmq需要更多的时间来准备vhosts声明和添加新用户,所以我们总是需要运行两次boxen。

这是我的逻辑

通过运行以下命令检查rabbitmq是否准备好 rabbitmqadmin list vhost 但是我们需要安装并运行rabbitmq所以我添加了 require => Service['dev.rabbitmq'] 如果上述命令有效,那么我们知道rabbit正在接受连接。

在这里,让我们把所有东西放在一起。

  exec { "Wait for rabbitmq":
    command => "rabbitmqadmin list vhosts",
    tries   => 2,
    try_sleep => 30,
    require   => Service['dev.rabbitmq']
  }
  dev::rabbitmq::vhost { '/clearvh':
    require => Exec['Wait for rabbitmq']
  }
  dev::rabbitmq::user { 'clear': password => 'password' }
  dev::rabbitmq::permission { [ 'guest', 'clear' ]: vhost => '/clearvh' }
}

这很好用,但Exec {"Wait for rabbit"}每次都会被调用,即使dev::rabbit::vhost不是。如果它只被dev::rabbitmq::vhost.

那可能吗 ?

谢谢

4

1 回答 1

0

Your going about the exec the wrong way. You need to have a condition to stop the exec from running.

exec { "Wait for rabbitmq":
  command => "rabbitmqadmin list vhosts",
  tries   => 2,
  try_sleep => 30,
  unless    => 'some command which returns "0" that tells you rabbitmq is already ready for vhosts',
  require   => Service['dev.rabbitmq']

}

Unless you tell your exec not to run for some reason or another, it will always run.

See the Puppet Type Reference for the exec resource and look for unless and onlyif.

And as for the title of this question which I originally overlooked. require means that the the resource passed to require must be applied before the calling resource. So in this case

Service['dev.rabbitmq']

will be applied before

Exec['Wait for rabbitmq'].

require does not ensure that an exec resource will not be run.

于 2014-08-29T04:37:01.017 回答