Puppet - 依赖项不起作用

Puppet - Dependencies are not working

我一直在开发一个小模块,它使用预制的 kibana puppet 模块(编辑:'lesaux/kibana4'),还包含一个简单的 exec,它为 kibana 安装 shield 插件。 (旁注:对于这个例子,我还从清单中包含的另一个模块安装 java8)

我的问题是 exec 在实际安装 kibana 之前保持 运行ning。我希望先安装 kibana,然后再安装 exec。所以我添加了一个 'require' 如下所示,还添加了一个链来确保 exec 发生在之后。

class test_kibana {

  class { '::kibana4':
     package_ensure             => '4.4.0-linux-x64',
     package_provider           => 'archive',
     config                     => {
       'server.host'            => 'localhost',
       'elasticsearch.url'      => 'http://localhost:9200',
       'elasticsearch.username' => 'testUserName',
       'elasticsearch.password' => 'testPassword',
       'shield.encryptionKey'   => 'testencryptionkey',
     }
  } ->

   exec { 'install kibana shield plugin':
     require                    => Class['::kibana4'],
     path                       => '/opt/kibana4/bin',
     command                    => 'kibana plugin --install kibana/shield/latest',
   }

}

require 和 chain 似乎不起作用。因此,当 exec 尝试 运行 时,它不知道命令的含义并失败,因为 kibana 尚不存在。

为什么 puppet 没有按照我要求的顺序安装这些?

这是我的输出:

==> nat: Notice: Scope(Archive::Download[kibana-4.4.0-linux-x64.tar.gz]): No checksum for this archive
==> nat: Notice: Compiled catalog for nat.test.com in environment production in 2.58 seconds
==> nat: Notice: /Stage[main]/Apt/File[preferences]/ensure: created
==> nat: Notice: /Stage[main]/test_java8/File[/tmp/java.preseed]/ensure: defined content as '{md5}fa13124e9e801dd42c91fa94ef7f1c1e'
==> nat: Notice: /Stage[main]/test_java8/File[/tmp/jce]/ensure: created
==> nat: Notice: /Stage[main]/test_java8/File[/tmp/jce/local_policy.jar]/ensure: defined content as '{md5}dabfcb23d7bf9bf5a201c3f6ea9bfb2c'
==> nat: Notice: /Stage[main]/test_java8/File[/tmp/jce/US_export_policy.jar]/ensure: defined content as '{md5}ef6e8eae7d1876d7f05d765d2c2e0529'
==> nat: Notice: /Stage[main]/Kibana4::User/Group[kibana4]/ensure: created
==> nat: Notice: /Stage[main]/Kibana4::User/User[kibana4]/ensure: created
==> nat: Error: Could not find command 'kibana'
==> nat: Error: /Stage[main]/Smart_monitoring_kibana/Exec[install kibana shield plugin]/returns: change from notrun to 0 failed: Could not find command 'kibana'
==> nat: Notice: /Stage[main]/Apt/Apt::Setting[conf-update-stamp]/File[/etc/apt/apt.conf.d/15update-stamp]/content: content changed '{md5}b9de0ac9e2c9854b1bb213e362dc4e41' to '{md5}0962d70c4ec78bbfa6f3544ae0c41974'
==> nat: Notice: /Stage[main]/test_java8/Apt::Ppa[ppa:webupd8team/java]/Exec[add-apt-repository-ppa:webupd8team/java]/returns: executed successfully
==> nat: Notice: /Stage[main]/Apt::Update/Exec[apt_update]: Triggered 'refresh' from 1 events
==> nat: Notice: /Stage[main]/test_java8/Exec[apt-update]/returns: executed successfully
==> nat: Notice: /Stage[main]/test_java8/Package[oracle-java8-installer]/ensure: created
==> nat: Notice: /Stage[main]/test_java8/File[/etc/profile.d/set_java_home.sh]/ensure: defined content as '{md5}717258a243a8addc2506097f12cd611f'
==> nat: Notice: /Stage[main]/test_java8/Exec[install-jce]/returns: executed successfully
==> nat: Notice: /Stage[main]/Kibana4::Install/Archive[kibana-4.4.0-linux-x64]/Archive::Download[kibana-4.4.0-linux-x64.tar.gz]/Exec[download archive kibana-4.4.0-linux-x64.tar.gz and check sum]/returns: executed successfully
==> nat: Notice: /Stage[main]/Kibana4::Install/Archive[kibana-4.4.0-linux-x64]/Archive::Extract[kibana-4.4.0-linux-x64]/Exec[kibana-4.4.0-linux-x64 unpack]/returns: executed successfully
==> nat: Notice: /Stage[main]/Kibana4::Install/Exec[chown_kibana_directory]: Triggered 'refresh' from 1 events
==> nat: Notice: /Stage[main]/Kibana4::Install/File[/opt/kibana4]/ensure: created
==> nat: Notice: /Stage[main]/Kibana4::Config/File[kibana-config-file]/content: content changed '{md5}dacdab7bddd2bcede2cc7cd8c6948307' to '{md5}7c24ae699bfbfbb5314ce01bdcdc3b6d'
==> nat: Notice: /Stage[main]/Kibana4::Config/File[kibana-config-file]/mode: mode changed '0644' to '0755'
==> nat: Notice: /Stage[main]/Kibana4::Config/File[/var/run/kibana.pid]/ensure: created
==> nat: Notice: /Stage[main]/Kibana4::Config/File[/var/log/kibana]/ensure: created
==> nat: Notice: /Stage[main]/Kibana4::Service/File[/etc/init.d/kibana4]/ensure: defined content as '{md5}0c5c726cdabb5355276abc6394a868a7'
==> nat: Notice: /Stage[main]/Kibana4::Service/File[/etc/default/kibana4]/ensure: defined content as '{md5}57b82a4af4f8872bfbc6488b0a85c652'
==> nat: Notice: /Stage[main]/Kibana4::Service/Service[kibana4]/ensure: ensure changed 'stopped' to 'running'
==> nat: Notice: Applied catalog in 644.11 seconds

编辑:我发现 lesaux/kibana 模块最近已更新,现在它允许您在安装过程中安装插件。 (因此我不再需要使用这个 exec 函数。问题已解决!)

您遇到了 containment 个问题。

类 充当它们直接声明的所有资源的容器。如果您声明与 class 的关系,则意味着与所有这些资源的关系相同。

类 不是资源,但是,classes 不会 自动充当它们声明的其他 classes 的容器.这有很好的理由,但它们在这里并不真正相关。对您来说,结果是您在 Exec 和 class 之间没有关系 kibana4::installkibana4::execkibana4::service。 Puppet 不受限于在这三个之后同步 Exec

您确实希望 class 包含它声明的部分或全部其他 class 是很常见的(但绝不是普遍的)。为此,有 contain 函数/语句(自 Puppet 3.4 起)。如果您添加

contain 'kibana4::install'
contain 'kibana4::exec'
contain 'kibana4::service'

在 class Kibana4 正文的 末尾 ,然后您将获得您正在寻找的包含语义。

如果您坚持使用早于 v3.4 的 Puppet(当前为 4.4;v3 树中的最新版本为 v3.8),那么还有其他方法可以确保适当的遏制,您可以在手册部分阅读相关内容我链接了。