Matthias Saou
2011-Jun-12 14:20 UTC
[Puppet Users] Global scope variables and erb templates in puppet 2.7
Hi, I''m starting to play with the latest puppet 2.7.0rc4, one of my goals being to try and update all of my puppet related files to be compatible with it, with no warnings at all. I''ve read in detail this page : http://docs.puppetlabs.com/guides/scope_and_puppet.html There is no mention of anything special to do for global scope variables inside templates, such as : file { ''/tmp/test'': content => inline_template (''<%= fqdn %>'') } Yet when using <%= ::fqdn %> I get the following : (err): compile error (erb):1: syntax error, unexpected tIDENTIFIER, expecting tCONSTANT _erbout = ''''; _erbout.concat(( ::fqdn ).to_s); _erbout How should these global scope variables (facts in this case) be used inside erb templates? Maybe there''s some obvious ruby syntax I''m missing? Matthias -- 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.
Ken Barber
2011-Jun-12 16:08 UTC
Re: [Puppet Users] Global scope variables and erb templates in puppet 2.7
Try: inline_template(''<%= scope.lookupvar("::fqdn") %>'') ken. On Sun, Jun 12, 2011 at 3:20 PM, Matthias Saou <thias@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net> wrote:> Hi, > > I''m starting to play with the latest puppet 2.7.0rc4, one of my goals > being to try and update all of my puppet related files to be compatible > with it, with no warnings at all. > > I''ve read in detail this page : > http://docs.puppetlabs.com/guides/scope_and_puppet.html > > There is no mention of anything special to do for global scope > variables inside templates, such as : > > file { ''/tmp/test'': content => inline_template (''<%= fqdn %>'') } > > Yet when using <%= ::fqdn %> I get the following : > > (err): compile error > (erb):1: syntax error, unexpected tIDENTIFIER, expecting tCONSTANT > _erbout = ''''; _erbout.concat(( ::fqdn ).to_s); _erbout > > How should these global scope variables (facts in this case) be used > inside erb templates? Maybe there''s some obvious ruby syntax I''m > missing? > > Matthias > > -- > 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. > >-- 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.
Matthias Saou
2011-Jun-12 19:01 UTC
Re: [Puppet Users] Global scope variables and erb templates in puppet 2.7
Hi, Thanks, using scope.lookupvar() in the templates does work. But will this be the proper way to echo facts in puppet 2.7 and 2.8? Because it does seem like quite an extra burden, and if it''s not really decided yet, I prefer sticking with the warnings for now ;-) Matthias Ken Barber <ken@puppetlabs.com> wrote:> Try: > > inline_template(''<%= scope.lookupvar("::fqdn") %>'') > > ken. > > On Sun, Jun 12, 2011 at 3:20 PM, Matthias Saou > <thias@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net> > wrote: > > Hi, > > > > I''m starting to play with the latest puppet 2.7.0rc4, one of my > > goals being to try and update all of my puppet related files to be > > compatible with it, with no warnings at all. > > > > I''ve read in detail this page : > > http://docs.puppetlabs.com/guides/scope_and_puppet.html > > > > There is no mention of anything special to do for global scope > > variables inside templates, such as : > > > > file { ''/tmp/test'': content => inline_template (''<%= fqdn %>'') } > > > > Yet when using <%= ::fqdn %> I get the following : > > > > (err): compile error > > (erb):1: syntax error, unexpected tIDENTIFIER, expecting tCONSTANT > > _erbout = ''''; _erbout.concat(( ::fqdn ).to_s); _erbout > > > > How should these global scope variables (facts in this case) be used > > inside erb templates? Maybe there''s some obvious ruby syntax I''m > > missing? > > > > Matthias > > > > -- > > 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. > > > > >-- 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.
Alessandro Franceschi
2011-Jun-13 09:26 UTC
Re: [Puppet Users] Global scope variables and erb templates in puppet 2.7
scope.lookupvar() works also on Puppet 2.6 and 0.25 and maybe earlier versions, and AFAIK will keep on working in future versions. Incidentally it has the benefit of not throwing an exception when the referred variables is not set (it just returns an empty field) I find it useful to refer to fully qualified variables (ie apache::params::port) that are not usable in the traitional form (<%= apache::params::port %> Al -- 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/-/3kSOk6-o2sYJ. 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.
Matthias Saou
2011-Jun-13 13:19 UTC
Re: [Puppet Users] Global scope variables and erb templates in puppet 2.7
Hi, Then I''m guessing the only other solution, which also works with 0.25 and any higher version would be : $local_scope_fqdn = $::fqdn Then : <%= local_scope_fqdn %> In order to use a local scope variable from within templates. It''s really too bad to not be able to use scoped variables from erb templates directly, as it won''t ever be as convenient as before for facts and global scope variables. Matthias Alessandro Franceschi <al@lab42.it> wrote:> scope.lookupvar() works also on Puppet 2.6 and 0.25 and maybe earlier > versions, and AFAIK will keep on working in future versions. > Incidentally it has the benefit of not throwing an exception when the > referred variables is not set (it just returns an empty field) > I find it useful to refer to fully qualified variables (ie > apache::params::port) that are not usable in the traitional form (<%= > apache::params::port %> > > Al >-- 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.