Ruby-on-rails 如何从模块中获取木偶清单中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7216375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:52:04  来源:igfitidea点击:

How to source a file in puppet manifest from module

ruby-on-railsmanifestpuppetvagrant

提问by Viktor Trón

I am trying to source files from local modules in a puppet manifest (using puppet in standalone mode):

我正在尝试从木偶清单中的本地模块中获取文件(在独立模式下使用木偶):

file {
  '/home/repowt/.crontab':
    ensure => present,
    source => 'puppet:///modules/site/crontab';
}

but I get:

但我得到:

Could not evaluate: Could not retrieve information from source(s) ...

The file is in:

该文件位于:

config/puppet/modules/site/files/crontab

(puppet is called via vagrant provisionand the Vagrantfile specifies module_path='config/puppet/modules' and is clearly ok since puppet does load modules with import from there.)

(puppet 是通过调用的vagrant provision,Vagrantfile 指定 module_path='config/puppet/modules' 并且显然没问题,因为 puppet 确实从那里加载了模块。)

I also tried:

我也试过:

source => 'puppet:///site/crontab'
source => 'site/crontab'
source => 'config/puppet/modules/site/files/crontab'
source => '/modules/site/crontab'

of no avail. I found nothing illuminating on the web, seems like something very simple. your help is appreciated.

无济于事。我在网上没有发现任何有启发性的东西,看起来很简单。感谢您的帮助。

回答by akumria

There are a couple of things going on here.

这里有几件事情正在发生。

First, as pwan notes, the fileserver.confneeds to be setup correctly.

首先,正如 pwan 所指出的,fileserver.conf需要正确设置。

Keeping in mind that /vagrantcontains the directory where Vagrantfileis (and therefore all of it content), that meant for me doing:

请记住,/vagrant包含目录 where Vagrantfile(以及所有内容),这对我来说意味着:

vm_config.vm.provision :puppet, :module_path => "modules", :options => ["--fileserverconfig=/vagrant/fileserver.conf", ]

My fileserver.confspecifies that /etc/puppet/filesis to be used.

fileserver.conf指定/etc/puppet/files要使用的。

Whilst I could have specified a different fileserver.conf, just for Vagrant, I wanted pretty much everything to be the same as normal.

虽然我可以fileserver.conf为 Vagrant指定一个不同的,但我希望几乎所有内容都与正常情况相同。

So, I also mounted /etc/puppet/filestoo, with

所以,我也安装/etc/puppet/files

vm_config.vm.share_folder "files", "/etc/puppet/files", "files"

Which got things working for me.

这让事情对我有用。

回答by knoopx

puppet:///modules/my_module/fileshould match %vagrant_root%/modules/my_module/files/file

puppet:///modules/my_module/file应该匹配 %vagrant_root%/modules/my_module/files/file

回答by Shentonfreude

I noticed that Vagrant mounted a copy of its dir on the target VM (I'm using base http://dl.dropbox.com/u/15307300/vagrant-0.7-centos-64-base.box); do a "mount" and see if you have this too.

我注意到 Vagrant 在目标 VM 上安装了其目录的副本(我正在使用 base http://dl.dropbox.com/u/15307300/vagrant-0.7-centos-64-base.box);做一个“装载”,看看你是否也有这个。

This allows me to create a directory within my Vagrant, parallel to manifests/ that I call "files/". I then put my config source file under there, e.g., .../myvagrantproject/files/slapd.conf. This appears on the VM as /vagrant/files/slapd.conf

这允许我在我的 Vagrant 中创建一个目录,与 manifests/ 平行,我称之为“files/”。然后我将我的配置源文件放在那里,例如,.../myvagrantproject/files/slapd.conf。这在 VM 上显示为 /vagrant/files/slapd.conf

Then in the puppet manifest for the file source I list the source as an absolute file path, not a puppet server path, like:

然后在文件源的 puppet 清单中,我将源列为绝对文件路径,而不是 puppet 服务器路径,例如:

file { 'slapd.conf':
  name          => '/etc/openldap/slapd.conf',
  ensure        => present,
  source        => '/vagrant/files/slapd.conf',
  owner         => root,
  group         => ldap,
  mode          => 0640,
  require       => Package["ldapservers"],
}

It found it no problemmo from it's own vbox-mounted remote filesystem.

它从它自己的 vbox 安装的远程文件系统中发现它没有问题。

回答by pwan

Your original puppet://modules/site/crontab should work.

您原来的 puppet://modules/site/crontab 应该可以工作。

I suspect the fileserver.conf on your puppetmaster may not have a modules section. Try adding something like below if it's not already present.

我怀疑您的 puppetmaster 上的 fileserver.conf 可能没有模块部分。如果尚不存在,请尝试添加如下内容。

[modules]
    allow *

Check out the 'Module Lookup' section at http://docs.puppetlabs.com/guides/modules.html

http://docs.puppetlabs.com/guides/modules.html查看“模块查找”部分

回答by zekus

It is not clear from your description if you are using the puppet in standalone mode or in client-server mode. Assuming that you are using the standalone mode, double check in your /tmp folder in your vm to see if the module folder is actually there and vagrant has mounted it. The fact that you can load the manifest, doesn't mean that the modules are there as well.

从您的描述中不清楚您是在独立模式下还是在客户端-服务器模式下使用人偶。假设您使用的是独立模式,请仔细检查 vm 中的 /tmp 文件夹,以查看模块文件夹是否确实存在并且 vagrant 已安装它。您可以加载清单的事实并不意味着模块也在那里。

Your original configuration, looks correct.

您的原始配置看起来正确。