James Sapam
James Sapam

Reputation: 16930

How to fix 'Could not parse for environment production' error?

Here is my little puppet snippet: when i execute this snippet i got the following error:

err: Could not parse for environment production: Could not match   at /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,
    }
}

Could some one please help in pointing out?

Upvotes: 7

Views: 35434

Answers (4)

Karan
Karan

Reputation: 13

This Error also appears when the host has a duplicate entry in nodes.pp file. In case there are multiple host in the file, please make sure there is single entry for a host.

Upvotes: 1

kenorb
kenorb

Reputation: 166319

The error:

Error: Could not parse for environment production

is always followed by another error, for example:

  • Syntax error at 'x': expected 'x' at manifest.pp:123

    Which could indicate a missing comma.

  • Could not match at manifest.pp:123

    which could indicate a missing bracket.

So you should check the file at the specific line where the error is reported to see if the previous line has missing any commas or brackets (which is the most common mistake for that kind of error).

Upvotes: 2

Christian Long
Christian Long

Reputation: 11514

Also check for missing quotation marks immediately before the point at which Puppet reports the error.

Upvotes: 0

BMW
BMW

Reputation: 45223

Regarding error Could not parse for environment production, you can check url https://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.)

For troubleshooting and validate manifest (*.pp) file, you can run :

puppet parser validate test.pp

or you can install puppet-lint (http://puppet-lint.com/) for help as well.

Third, find out if there are any hidden characters to make the trouble.

Upvotes: 9

Related Questions