Migrating to future parser (on 3.8) in preparation for upgrade to 4.0

64 views
Skip to first unread message

Matthew Ceroni

unread,
Nov 24, 2015, 3:03:04 PM11/24/15
to puppet...@googlegroups.com
Working on migrating my manifests to work with Puppet 4.0. Currently on 3.8 and have started to experiment with the future parser (probably not so much future anymore).

I am stuck on an error that is being reported.

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, ensure parameter must be specified at /etc/puppet/environments/sandbox/modules/sudo/manifests/init.pp:51:2 on node op1227

The code is a simple check and fail if not met

    if ! ($ensure in [ 'present', 'absent' ]) {
        fail("sudo 'ensure' parameter must be set to either 'absent' or 'present'")
    }

It isn't liking something about the function call fail. 

Any help would be appreciated.

Thanks

Peter Huene

unread,
Nov 24, 2015, 7:45:10 PM11/24/15
to puppet...@googlegroups.com
Hi Matthew:

On Tue, Nov 24, 2015 at 12:02 PM, Matthew Ceroni <matthe...@gmail.com> wrote:
Working on migrating my manifests to work with Puppet 4.0. Currently on 3.8 and have started to experiment with the future parser (probably not so much future anymore).

I am stuck on an error that is being reported.

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, ensure parameter must be specified at /etc/puppet/environments/sandbox/modules/sudo/manifests/init.pp:51:2 on node op1227

The code is a simple check and fail if not met

    if ! ($ensure in [ 'present', 'absent' ]) {
        fail("sudo 'ensure' parameter must be set to either 'absent' or 'present'")
    }


Fail is expected to fail the parse, but I'd expect the given error message to match up with what was returned by the server.

What's the value of $ensure at evaluation time?  Perhaps changing the error message to something like "'$ensure' is not a valid value for parameter \$ensure: expected either 'absent' or 'present'" so it's easily displayed in the error might help debug this.
 
It isn't liking something about the function call fail. 

Any help would be appreciated.

Thanks

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CA%2BNsY5iN4%3DjYvXnppOdnw_KLNZZtunauoF8kodryXLwYcohEhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Nov 25, 2015, 9:29:25 AM11/25/15
to Puppet Users
In a sense, the whole point of fail() is for Puppet to not like it: its purpose is to abort catalog building.  I think you are mistaken, however; the error message text is not consistent with the manifest code you presented, so I don't think that specific code is directly related to your problem.  You may be looking at the wrong line or at the wrong file (maybe the wrong version of the file).  Perhaps you are looking at a manifest for the wrong environment.

The result you described would be the natural effect of the fail() function if the message reported in the log matched the function argument.  The message that is emitted is similar enough to the argument in the code you presented, and the condition under which the function is called is enough reminiscent of it, that I'm leaning toward the theory that you're looking at the wrong version of the manifest, with the root problem being that an unsupported (or no) value has been given for $ensure.


John

Corey Osman

unread,
Nov 26, 2015, 2:46:27 PM11/26/15
to Puppet Users
It looks like your doing parameter validation the old fashioned way.  So there is no reason to have complicated validation code when it can be done easier using parameter data types and runtime validation.  The easiest way is to validate $ensure is to use data types like Enum.  Check out the data type feature in the future parser which would negate the need to use the conditional logic in your original example.  Another way without using the future parser would be to use stdlib validate_XX functions.


Example class
class foo(Enum['present', 'absent'] $ensure = 'present'){
   file{'/tmp/foo.txt':
     ensure => $ensure,
     content => 'bar'
   }
}


Corey
Reply all
Reply to author
Forward
0 new messages