Adam Nielsen
2011-Jan-08 11:52 UTC
[Puppet Users] Is there a nice syntax for calling functions?
Hi all, I''m using the class below to set the timezone on a Debian system, however there are two things I''m unhappy with. 1) Why do I have to specify a trailing colon after the exec command and when calling timezone::set? If I leave it off I get the very helpful error "Syntax error at ''}''; expected ''}''" 2) Because of the exec command, /etc/timezone gets overwritten without a backup being made like with other functions. Is there a way to get the file included in the file bucket? I imagine I''d have to add an "onlyif" directive to make sure this only happened if the file contents changed. I''m using this function-call "design" in a few places so if it can be rewritten in a nicer way I''d like to know as I can then tidy up a few other classes too. This is all I have been able to decipher from the examples I''ve stumbled across. Many thanks, Adam. ------- class timezone { define set($ensure = present) { file { "/etc/localtime": ensure => symlink, target => "/usr/share/zoneinfo/$name", ; } exec { "/bin/echo ''${name}'' > /etc/timezone": } } } ------- include timezone timezone::set { "Australia/Brisbane": } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Patrick
2011-Jan-08 16:11 UTC
Re: [Puppet Users] Is there a nice syntax for calling functions?
On Jan 8, 2011, at 3:52 AM, Adam Nielsen wrote:> 2) Because of the exec command, /etc/timezone gets overwritten without a backup being made like with other functions. Is there a way to get the file included in the file bucket? I imagine I''d have to add an "onlyif" directive to make sure this only happened if the file contents changed.Nope. Puppet can''t infer what files it should backup for an exec. What you can do is add a layer of indirection if you need it. *) Create a temp folder that won''t be wiped on reboot. I use /usr/local/puppet_private for everything like this. *) Use your exec to create the file in there. ie at /usr/local/puppet_private/timezone *) Use file to copy from /usr/local/puppet_private/timezone to /etc/timezone so you get "file" to filebucket the old file. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2011-Jan-08 16:46 UTC
Re: [Puppet Users] Is there a nice syntax for calling functions?
On Sat, Jan 8, 2011 at 3:52 AM, Adam Nielsen <a.nielsen@shikadi.net> wrote:> Hi all, > > I''m using the class below to set the timezone on a Debian system, however > there are two things I''m unhappy with. > > 1) Why do I have to specify a trailing colon after the exec command and > when calling timezone::set? If I leave it off I get the very helpful error > "Syntax error at ''}''; expected ''}''" >It''s the minimum required syntax for declaring a resource. The : is required to seperate the resource title and the list of attributes: resource_type { title : attribute => value, (trailing comma optional for last attribute, can omit all default value) ; (trailing semicolon optional for single resource) } So removing optional parts: resource_type { title : }> 2) Because of the exec command, /etc/timezone gets overwritten without a > backup being made like with other functions. Is there a way to get the file > included in the file bucket? I imagine I''d have to add an "onlyif" > directive to make sure this only happened if the file contents changed. >You can use puppet filebucket command to backup the files before the exec, but in this case why not use the file resource? file { "/etc/timezone": content => $name, } I''m using this function-call "design" in a few places so if it can be> rewritten in a nicer way I''d like to know as I can then tidy up a few other > classes too. This is all I have been able to decipher from the examples > I''ve stumbled across. > > Many thanks, > Adam. > > ------- > > class timezone { > > define set($ensure = present) { > > file { > "/etc/localtime": > ensure => symlink, > target => "/usr/share/zoneinfo/$name", > ; > } > > exec { "/bin/echo ''${name}'' > /etc/timezone": } > > } > > } > > ------- > > include timezone > timezone::set { "Australia/Brisbane": } > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Adam Nielsen
2011-Jan-09 01:19 UTC
Re: [Puppet Users] Is there a nice syntax for calling functions?
> It''s the minimum required syntax for declaring a resource. The : is required > to seperate the resource title and the list of attributes:Thanks for the explanation. Shame the colon isn''t optional when there are no attributes ;-)> You can use puppet filebucket command to backup the files before the exec, but > in this case why not use the file resource? > > file { "/etc/timezone": > content => $name, > }Oh, I didn''t realise you could do that! That''s much better, thanks for the info. Thanks Patrick as well for the idea with writing to a temp folder and then copying it, that''s an interesting workaround. Cheers, Adam. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.