【问题标题】:Could not retrieve information from environment production source无法从环境生产源检索信息
【发布时间】:2026-01-13 23:45:01
【问题描述】:

我在我的一个流浪项目中使用 puppet 作为我的供应商。我正在尝试为自定义 bash_profile 添加一个模块。

puppet 的module_path 设置为:

 puppet.module_path = "puppet/modules"

我的 bash_profile 模块的类如下所示:

class bash_profile
{
    file
    {
        "/home/vagrant/bash_profile":
            ensure => present,
            source => "puppet:///modules/bash_profile/files/bash_profile"
    }
}

这是我的 puppet 结构的文件结构:

puppet
| manifests
| | phpbase.pp // my main manifest file that has includes for modules
| modules
| | bash_profile
| | | files
| | | | bash_profile // the actual bash_profile file I want to ensure is present on my VM
| | | manifests
| | | | init.pp // the init file included for the bash_profile class

当我为 vagrant 运行配置时,我收到错误

错误:/Stage[main]/Bash_profile/File[/home/vagrant/bash_profile]:无法评估:无法从环境生产源中检索信息 puppet:///modules/bash_profile/files/bash_profile在 /tmp/vagrant-puppet-1/modules-0/bash_profile/manifests/init.pp:8

我不确定为什么它无法检索信息。路径似乎是正确的。谁能看到我错过了什么?

【问题讨论】:

  • @timbooo,只是好奇,你为什么要编辑标题?我以这种方式为我的问题添加前缀,以便我以后更容易回顾它们。
  • 标题中不需要加标签,见this link。您也可以使用标签以与主题相关的方式处理您的问题。
  • 明白了,感谢您的链接和澄清。

标签: vagrant puppet provisioning vagrantfile


【解决方案1】:

是的,您不应该在 URL 中包含文字 files/。相反,它应该只是

puppet:///modules/bash_profile/bash_profile

【讨论】:

  • 我刚刚阅读了相同的文档并错过了同一点。四个小时试图弄清楚那个 URL!我也尝试使用文件 URI。我的同事说,在源属性中,您需要关闭“文件:”。不确定,但对他有用。
  • 天哪,这绝对违背了我对路径的期望。
【解决方案2】:

如果您的模块名称无效,您也可能会收到recurse => true 的此错误。例如,如果你有这个模块结构:

modules ├── my-example │   └── files │   └── example │   └── test.txt

还有这个资源:

file { "/tmp/example":
  ensure => directory,
  recurse => true,
  source => "puppet:///modules/my-example/example",
}

你会得到这个错误:

==> default: Info: Could not find filesystem info for file 'my-example/example' in environment production ==> default: Error: /Stage[main]/Main/Node[default]/File[/tmp/example]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///my-example/example

修复方法是重命名模块——例如,将其命名为 my_example 即可修复它。 rules for module names are documented 但很容易错过。

【讨论】:

    【解决方案3】:

    注意事项

    1. Puppet URI 格式puppet:///modules/name_of_module/filename
    2. 模块目录中的文件服务器目录

    video 是解决错误的分步指南

    【讨论】: