如何修复“无法解析生产环境”的错误?

7
这是我的小木偶片段:当我执行这个片段时,我得到了以下错误:
err: 无法解析生产环境:在/home/test.pp的第8行无法匹配
$vendor = generate("/usr/bin/lsscsi")

if defined($vendor) {
    if $vendor =~ /LSI/{
        $d_multipath = [{
            vendor => 'LSI',
            product => 'INF-01-00',
            path_checker => 'rdac',
            path_selector => 'round-robin 0',
       }]
    }
}
else {
    notify {'faield-lsscsi':
        message  => "ERROR: failed to execute lsscsi to get the scsi vendor type",
        loglevel => critical,
    }
}

有人可以帮忙指出吗?

错误与您复制粘贴的代码无关,您可以尝试运行 puppet apply --environment=production - BMW
2
https://docs.puppetlabs.com/learning/manifests.html#syntax-hints - BMW
1
我使用 puppet parser validate test.pp 命令检查代码,未报告任何错误。你要在这里粘贴所有的代码吗? - BMW
我在运行验证时遇到了那个错误,而且我无法安装puppet-lint。 - James Sapam
1
我将代码复制/粘贴到我的环境中,并使用验证运行,没有收到任何错误。在pp文件中是否有任何隐藏字符? - BMW
1
你能否在第5行和第10行删除[],然后再试一次? - BMW
4个回答

9

关于错误Could not parse for environment production,你可以查看urlhttps://docs.puppetlabs.com/learning/manifests.html#syntax-hints获取语法提示。

Syntax Hints

Watch out for these common errors:

Don’t forget commas and colons! Forgetting them causes errors like Could not parse for environment production: Syntax error at 'mode'; expected '}' at /root/manifests/1.file.pp:6 on node learn.localdomain.

Capitalization matters! The resource type and the attribute names should always be lowercase.
The values used for titles and attribute values will usually be strings, which you should usually quote. Read more about Puppet’s data types here.

There are two kinds of quotes in Puppet: single (') and double ("). The main difference is that double quotes let you interpolate $variables, which we cover in another lesson.

Attribute names (like path, ensure, etc.) are special keywords, not strings. They shouldn’t be quoted.

Also, note that Puppet lets you use whatever whitespace makes your manifests more readable. We suggest visually lining up the => arrows, because it makes it easier to understand a manifest at a glance. (The Vim plugins on the Learning Puppet VM will do this automatically as you type.)

如果需要排除故障并验证manifest(*.pp)文件,您可以运行以下命令:

puppet parser validate test.pp

或者你可以安装 puppet-lint (http://puppet-lint.com/) 来获得帮助。

第三步,找出是否有任何隐藏字符造成了问题。


2

错误信息:

错误:无法解析生产环境

通常会跟随另一个错误,例如:

  • 语法错误在manifest.pp的123行处的'x':预期为'x'

    这可能表示缺少逗号。

  • 无法匹配manifest.pp:123

    这可能表示缺少括号。

因此,您应该检查报告错误的特定行处的文件,看看前一行是否缺少任何逗号或括号(这是这种类型错误最常见的错误)。


1
当主机在nodes.pp文件中有重复条目时,也会出现此错误。 如果文件中有多个主机,请确保每个主机只有一个条目。

0

同时,还要立即检查Puppet报告错误之前是否缺少引号。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接