custom define type for array with 'case' argument pass to it

171 views
Skip to first unread message

iamauser

unread,
Dec 4, 2012, 3:48:47 PM12/4/12
to puppet...@googlegroups.com
I am trying to write a define type which will use an array but in the meantime have an argument pass to it that sets a case. See for example :

define link_files ($linkcase) {

   case $linkcase { 
       "var" : {
           file { "${name}_exelink" :
                  path => "/var/log/puppet/${name}_log",
                  ensure => link,
                  target => "/var/log/puppet/${name}_lastlog",
           }
       }
     
      "data" : {
           file { "${name}_exelink" :
                  path => "/var/log/puppet/${name}_log",
                  ensure => link,
                  target => "/var/data/log/puppet/${name}_lastlog",
           }                
       }
    }
}

I would like to use array of names inside manifests.

I tried to call it like this :

$mynamevar = range("node01", "node05")

link_files { '$mynamevar' :
   $linkcase => "var",
}

but it doesn't like it and complains this :
Error 400 on SERVER: Syntax error at 'linkcase'; expected '}'

What should be the correct syntax for this ?

In principle, without the case $linkcase argument one could run the define type for an array by using just like,
link_files {$mynamevar :}

Thanks for any suggestion.



                

Jakov Sosic

unread,
Dec 5, 2012, 6:21:46 PM12/5/12
to puppet...@googlegroups.com
On 12/04/2012 09:48 PM, iamauser wrote:

> link_files { '$mynamevar' :

When you pass the argument within the single quotes, variables are not
parsed AFAIK. Maybe that's your issue. Remove the quotes?

iamauser

unread,
Dec 5, 2012, 6:24:19 PM12/5/12
to puppet...@googlegroups.com
Thanks, but I have tried that already, it doesn't help.

-Tapas

Jakov Sosic

unread,
Dec 5, 2012, 6:50:30 PM12/5/12
to puppet...@googlegroups.com
On 12/06/2012 12:24 AM, iamauser wrote:
> Thanks, but I have tried that already, it doesn't help.
>

You have another syntax problem that escaped me first time I reviewed
your code...

This is the problem:

link_files { '$mynamevar' :
$linkcase => "var",
}

You should remove quotes around array, dollar sign in front of linkcase,
and replace doublequotes around simple string with singleqoutes:

link_files { $mynamevar :
linkcase => 'var',
}



Really, your code is a mess... You have doublequote where singlequotes
would be enough, singleqoutes where they should not be at all, dollar
sign in front of param in resource, you don't use two-space as
identation, you don't have default: {} in your case conditional, you
have blanks after the end of line, etc, etc...

I urge you to use 'puppet parser validate' and 'puppet-lint' to review
your code. It would be even better if you would use it in your
pre-commit hooks, so that you cannot commit code that is written bellow
certain standards.

iamauser

unread,
Dec 5, 2012, 6:58:56 PM12/5/12
to puppet...@googlegroups.com


On Wednesday, December 5, 2012 5:50:30 PM UTC-6, Jakov Sosic wrote:
On 12/06/2012 12:24 AM, iamauser wrote:
> Thanks, but I have tried that already, it doesn't help.
>

You have another syntax problem that escaped me first time I reviewed
your code...

This is the problem:

link_files { '$mynamevar' :
   $linkcase => "var",
}

You should remove quotes around array, dollar sign in front of linkcase,
and replace doublequotes around simple string with singleqoutes:

link_files { $mynamevar :
  linkcase => 'var',
}


First of all, I didn't copy paste my code, rather typed it here, so indentation should be ignored. 
You are right, dollar sign shouldn't be there, and I think it was a typo on my part that I failed to notice. I disagree with your comment about singlequote or doublequote for "var". That shouldn't be an issue here as it will consider this as string of characters.
 

Really, your code is a mess... You have doublequote where singlequotes
would be enough, singleqoutes where they should not be at all, dollar
sign in front of param in resource, you don't use two-space as
identation, you don't have default: {} in your case conditional, you
have blanks after the end of line, etc, etc...

I urge you to use 'puppet parser validate' and 'puppet-lint' to review
your code. It would be even better if you would use it in your
pre-commit hooks, so that you cannot commit code that is written bellow
certain standards.

Thanks and I am aware of all these in practice.


 

Jakov Sosic

unread,
Dec 5, 2012, 7:16:55 PM12/5/12
to puppet...@googlegroups.com
On 12/06/2012 12:58 AM, iamauser wrote:
> First of all, I didn't copy paste my code, rather typed it here, so
> indentation should be ignored.
> You are right, dollar sign shouldn't be there, and I think it was a typo
> on my part that I failed to notice. I disagree with your comment about
> singlequote or doublequote for "var". That shouldn't be an issue here as
> it will consider this as string of characters.

Sorry if my comments sounded harsh, I didn't mean to offend you. Just
urge you to incorporate those tools into your daily practice, which
would save you a lot of time and nerves ;)

iamauser

unread,
Dec 5, 2012, 7:19:35 PM12/5/12
to puppet...@googlegroups.com
No worries. Your comment helped me to notice the dollar sign in front of the linkcase. That actually solved the issue. Now it works and yes, I have added a default case as well :)

Thanks

Nikola Petrov

unread,
Dec 6, 2012, 10:11:17 AM12/6/12
to puppet...@googlegroups.com
You should consider using a good editor which will show those error for
you. You can incorporate puppet-lint for example and it will spot most
of the problems and warn you about the double quotes for performance and
clarity reasons.

Hope that helps :-)

Best, Nikola
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/I07DoBUDI_gJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>

iamauser

unread,
Dec 6, 2012, 11:51:38 AM12/6/12
to puppet...@googlegroups.com
Hi,

I had tried installing puppet-lint sometime ago, and tried this again as you wrote, but I get a bunch of buffer overflow (see below). I have reported an issue with rodjek's github and let's see if I get an answer. Any suggestion from this forum will certainly help.

]# gem install puppet-lint
*** buffer overflow detected ***: /usr/bin/ruby terminated
======= Backtrace: =========
/lib64/libc.so.6(__chk_fail+0x2f)[0x2af4423bffaf]
/usr/lib64/ruby/1.8/x86_64-linux/syck.so(rb_syck_mktime+0x48e)[0x2af44284149e]
/usr/lib64/ruby/1.8/x86_64-linux/syck.so(yaml_org_handler+0x860)[0x2af442841db0]
/usr/lib64/ruby/1.8/x86_64-linux/syck.so(syck_defaultresolver_node_import+0x39)[0x2af442841fb9]
/usr/lib64/libruby.so.1.8[0x2af441737a9e]
/usr/lib64/libruby.so.1.8[0x2af441737fb8]
/usr/lib64/libruby.so.1.8[0x2af441738562]
.....
.....
and goes on...

am I missing something trivial in here ?

]# gem --version
1.3.1
]# ruby --version
ruby 1.8.5 (2006-08-25) [x86_64-linux]


#####

Jakov Sosic

unread,
Dec 6, 2012, 12:20:08 PM12/6/12
to puppet...@googlegroups.com
On 12/06/2012 05:51 PM, iamauser wrote:
> Hi,
>
> I had tried installing puppet-lint sometime ago, and tried this again as
> you wrote, but I get a bunch of buffer overflow (see below). I have
> reported an issue with rodjek's github and let's see if I get an answer.
> Any suggestion from this forum will certainly help.

Are you using RHEL od RHEL derivative? If yes, I can provide you RPM.

iamauser

unread,
Dec 6, 2012, 2:00:11 PM12/6/12
to puppet...@googlegroups.com
Yes, I am. That will be a lot helpful. Thanks a lot.


 

Jakov Sosic

unread,
Dec 6, 2012, 6:12:33 PM12/6/12
to puppet...@googlegroups.com
On 12/06/2012 08:00 PM, iamauser wrote:

>> Are you using RHEL od RHEL derivative? If yes, I can provide you RPM.
>
> Yes, I am. That will be a lot helpful. Thanks a lot.

http://ftp.srce.hr/srce-redhat/base/el6/x86_64/rubygem-puppet-lint-0.1.13-1.el6.srce.noarch.rpm



--
Jakov Sosic
www.srce.unizg.hr

iamauser

unread,
Dec 6, 2012, 6:20:35 PM12/6/12
to puppet...@googlegroups.com
Thanks, but we are still running EL5. Do you have rpm available for this ?

Jakov Sosic

unread,
Dec 6, 2012, 6:23:16 PM12/6/12
to puppet...@googlegroups.com
On 12/07/2012 12:20 AM, iamauser wrote:
> Thanks, but we are still running EL5. Do you have rpm available for this ?

Yeah it's easy just replace el6 with el5 ;)

http://ftp.srce.hr/srce-redhat/base/el5/x86_64/rubygem-puppet-lint-0.1.13-1.el5.srce.noarch.rpm


Although I don't have all packages build for both versions (el5 & el6)
and all architectures (x86_64 & i386), I sure try my best. When I get
Koji up and working it should be easier to provide all the packages...

Jakov Sosic

unread,
Dec 10, 2012, 5:20:55 PM12/10/12
to puppet...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages