I have a situation where I am trying to manage some systems that have a single IP address but different ssh port numbers. For each of these systems I need to individually manage a logrotate.d configuration file, and a separate archive directory. Of course, this won''t work... file { "/data/syslog/${remote_host}/archive": ensure => directory; "/etc/logrotate.d/syslogng-host-${remote_host}": content => template("syslog-ng/etc/logrotate.d/server.erb"); } Puppet complains for the first entry that the file is not unique, since I am trying to call it multiple times with the same $remote_host. If the directory already exists, that''s great. How can I make puppet skip it in that case? The puppet docs at http://docs.reductivelabs.com/references/stable/function.html state that there is an "if defined" function, but I''ve never gotten this to work, and the documentation really isn''t very clear as to if functions are supposed to work inside a manifest. I tried this: file { if ! defined(File["/data/syslog/${remote_host}/archive"]) { "/data/syslog/${remote_host}/archive": ensure => directory; } } and this: if ! defined(File["/data/syslog/${remote_host}/archive"]) { file { "/data/syslog/${remote_host}/archive": ensure => directory; } } .... both of which resulted in errors. As I said, the documentation really isn''t clear if functions CAN be used inside a manifest. That has always confused me and I wish someone would clear up the docs. For the second entry, I can simply make it unique by suffixing the unique ssh port number. That''s not an option for the first file though. Doug -- 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.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> and this: > > if ! defined(File["/data/syslog/${remote_host}/archive"]) { > file { > "/data/syslog/${remote_host}/archive": > ensure => directory; > } > }this should work.> .... both of which resulted in errors. As I said, the documentation > really isn''t clear if functions CAN be used inside a manifest. That > has always confused me and I wish someone would clear up the docs.what kind of errors? which version of puppet are you using? In general I try to avoid defined, as in my opinion this is some kind of codesmell. But there are valid situations for that function. regarding to functions: they go into manifests. Where else do you imagine they could go? I mean if not in manifests you might assume that they could go somewhere else. And maybe you could raise a ticket about that point where documentation is not clear. Thanks. cheers pete -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkuieS0ACgkQbwltcAfKi3+OIQCfXkphSoK7oBvEz+MHHFMsPSOz gSgAoKyPBL/OUXMyROItfk0J00HaN6SM =OM+/ -----END PGP SIGNATURE----- -- 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.
On Thu, Mar 18, 2010 at 3:04 PM, Peter Meier <peter.meier@immerda.ch> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > >> and this: >> >> if ! defined(File["/data/syslog/${remote_host}/archive"]) { >> file { >> "/data/syslog/${remote_host}/archive": >> ensure => directory; >> } >> } > > this should work. > >> .... both of which resulted in errors. As I said, the documentation >> really isn''t clear if functions CAN be used inside a manifest. That >> has always confused me and I wish someone would clear up the docs. >Incidentally I''m working on doing a lot of work on docs.reductivelabs.com (adding new content, etc) at the moment. I could use *any* pointers on anything that''s not clear you can find -- on that /or/ the Wiki. I''m also interested in whether the docs covered things in Puppet in the way you thought you should learn them. -- 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.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Functions can absolutely be used inside of manifests. You may be running into an issue in that ''defined'' works based on the compile time order of your manifests. Example: class foo { ... } class bar { ... } # This does not work as expected if ! defined(Class["foo"]) { ... } include "foo" # This does include "foo" if ! defined(Class["foo"]) { ... } So, I''m guessing that whatever you''re trying to do is including that compile statement in an ordered include that you''ve already called. Does that make sense? Trevor On 03/18/2010 02:34 PM, Douglas Garstang wrote:> I have a situation where I am trying to manage some systems that have > a single IP address but different ssh port numbers. For each of these > systems I need to individually manage a logrotate.d configuration > file, and a separate archive directory. > > Of course, this won''t work... > > file { > "/data/syslog/${remote_host}/archive": > ensure => directory; > > "/etc/logrotate.d/syslogng-host-${remote_host}": > content => template("syslog-ng/etc/logrotate.d/server.erb"); > } > > Puppet complains for the first entry that the file is not unique, > since I am trying to call it multiple times with the same > $remote_host. If the directory already exists, that''s great. How can I > make puppet skip it in that case? The puppet docs at > http://docs.reductivelabs.com/references/stable/function.html state > that there is an "if defined" function, but I''ve never gotten this to > work, and the documentation really isn''t very clear as to if functions > are supposed to work inside a manifest. > > I tried this: > > file { > if ! defined(File["/data/syslog/${remote_host}/archive"]) { > "/data/syslog/${remote_host}/archive": > ensure => directory; > } > } > > and this: > > if ! defined(File["/data/syslog/${remote_host}/archive"]) { > file { > "/data/syslog/${remote_host}/archive": > ensure => directory; > } > } > > .... both of which resulted in errors. As I said, the documentation > really isn''t clear if functions CAN be used inside a manifest. That > has always confused me and I wish someone would clear up the docs. > > For the second entry, I can simply make it unique by suffixing the > unique ssh port number. That''s not an option for the first file > though. > > Doug >- -- Trevor Vaughan Vice President, Onyx Point, Inc. email: tvaughan@onyxpoint.com phone: 410-541-ONYX (6699) - -- This account not approved for unencrypted sensitive information -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkui3ZQACgkQyWMIJmxwHpRiWACePU0uYMeWCZifmbAD0RITHGiU jGQAoNZ77e+x7/zEbqAycwtYON3A6CcO =2O05 -----END PGP SIGNATURE----- -- 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.
On Thursday 18 Mar 2010 19:04:17 Peter Meier wrote:> > and this: > > > > if ! defined(File["/data/syslog/${remote_host}/archive"]) { > > file { > > "/data/syslog/${remote_host}/archive": > > ensure => directory; > > } > > } > > this should work. >Not in 0.24.x which IIRC is the one Douglas is using. Not 100% sure but this should: if defined(File[...]) != true { ... } or if not then: if defined(File[...]) { notice(''using already defined file'') } else { file { ... } } -- Michael Gliwinski Henderson Group Information Services 9-11 Hightown Avenue, Newtownabby, BT36 4RT Phone: 028 9034 3319 ********************************************************************************************** The information in this email is confidential and may be legally privileged. It is intended solely for the addressee and access to the email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed in the governing client engagement leter or contract. If you have received this email in error please notify support@henderson-group.com John Henderson (Holdings) Ltd Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT. Registered in Northern Ireland Registration Number NI010588 Vat No.: 814 6399 12 ********************************************************************************* -- 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.