Ask Your Question
0

puppet parser validate * shows error at a resource with mutiple bodies [closed]

asked 2017-10-17 04:30:22 -0600

mknl gravatar image

It feels like tidyis not working 100% reliable (at least my experience - one example: https://ask.puppet.com/question/32226...) in puppet version 3.8.6 (this is the version which comes with RHEL satellite and unfortunatelly we cannot update it)

So I decided to keep it very simple and use file ensure absent to delete some files and it will be notified by an exec.

Therefor I created the following little block:

 file {
                default:
                        ensure => absent,
                        require => Exec['<my_exec>'],
                        refreshonly => true,
                ;
                ['<full_path_to_file_1>', '<full_path_to_file_2>', '<full_path_to_file_3>', '...']:
                # use all defaults above
                ;
        }

when I parse my class files with puppet parser validate * I got the following message:

Error: Could not parse for environment <my_env>: Syntax error at ':'; expected '}' at <path_to_myclass_file><line_number_of_default:>

I wanted to go for a resource with multiple bodies, but I don't see any mistake. I followed this doc: https://puppet.com/docs/puppet/5.1/langresourcesadvanced.html#multiple-resource-bodies Not sure if this is not fully supported under 3.8 but I did not found the lang reference for this specific version. The oldest is 4.6.

Thanks for any tip in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mknl
close date 2017-10-18 07:47:54.285815

Comments

1

PP 3.8, eh? Do you have the future parser enabled? https://docs.puppet.com/puppet/3.8/configuration.html#parser BTW, the documentation is still available at https://docs.puppet.com/puppet/3.8/ Also, the file resource does not know a `refreshonly` attribute. That's supposed to go with the definition of Exec[my_exec].

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-17 04:50:28 -0600 )edit

Thanks for your comment and the link to the 3.8 doc. I don't see "Resources (advanced)" section in there. So multiple bodies are not allowed? Ah, ok thanks as well for the hint regarding refreshonly. So it is only valid for resource type exec. I think require should be enough anyhow.

mknl gravatar imagemknl ( 2017-10-17 05:02:51 -0600 )edit

Future parser: https://docs.puppet.com/puppet/3.8/experiments_future.html To use it manually: puppet parser --parser future validate *

mknl gravatar imagemknl ( 2017-10-17 05:06:19 -0600 )edit

I thought multiple bodies was something that you've been able to do since the early days, and some people do it because it makes their code 'more compact', but it is something that generally makes your code harder to read, and puppet lint will heavily complain about it

DarylW gravatar imageDarylW ( 2017-10-17 08:13:34 -0600 )edit

"and some people do it because it makes their code 'more compact'" --> this was my intention and as explained I just used this way as tidy did work as expected as well. Annoying that we are somehow trapped to 3.8.

mknl gravatar imagemknl ( 2017-10-17 08:18:18 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-10-17 11:32:19 -0600

Henrik Lindberg gravatar image

In 3.8 you must use the --parser=future to be able to have a default body in a resource expression. This was added in PUP-2898 which was released in future parser in Puppet 3.7.

Multiple bodies are supported with the old parser as well, but not using the default keyword.

edit flag offensive delete link more

Comments

Thanks for the explanation, but in the meanwhile I transformed it to multiple file resources which all have the same attributes. Unfortunately this is not a very compact code, from my perspective. Anyway as I wasted so many time on it, I will leave it as it is for now.

mknl gravatar imagemknl ( 2017-10-18 02:58:17 -0600 )edit

Thanks for these details. In the meanwhile I transformed my class which looked pretty clean and compact into a very stretched one with several single 'file'-resources. Even I was able to parse with future parser the class still threw the error when running on target hosts (with a default body in it)

mknl gravatar imagemknl ( 2017-10-18 07:47:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-17 04:30:22 -0600

Seen: 21 times

Last updated: Oct 17