Re: [Puppet Users] String substituion in puppet template
Okay, I got it now. <% if @ip_xforward != '' %> <% if ip_xforward.is_a? Array -%> <% ip_xforward.map do |value| -%> <%= "\t\tSetEnvIf X-Forwarded-For ^(" + value.gsub('.', '\.') + ".*) AllowIP\n" -%> <% end -%> <% else %> <%= " SetEnvIF X-Forwarded-For ^(#{ip_xforward}) AllowIP" -%> <% end -%> <% end -%> So a array of ip address in the manifests results in SetEnvIf X-Forwarded-For ^(13\.74\.8\.23.*) AllowIP SetEnvIf X-Forwarded-For ^(5\.63\.23\.53.*) AllowIP Thanks! Regards, Björn Am Freitag, 22. Mai 2015 14:21:26 UTC+2 schrieb Henrik Lindberg: > > On 2015-22-05 11:08, Gabriel Filion wrote: > > On 20/05/15 09:04 AM, Björn wrote: > >> I tried it with regsubst, but without success: > >> | > >> <%ip_xforward.each do|name|-%><%="\t\tSetEnvIF X-Forwarded-For > >> ^(regsubst(#{name}, '\.','\\.')) AllowIP\n"%><%end-%> > >> | > > > > maybe you need to call the function outside of the string. e.g.: > > > > <%= "\t\tSetEnvIf X-Forwarded-For ^(" + regsubst(name, '\.','\\.') + ") > > AllowIP\n"%> > > > > Note that the each method returns the original LHS not the string. Also, > the substitution inside the string is not code that gets evaluation, you > need to interpolate it using #{} around the expression, or do a concat. > > If you want to transform each, you should use the map function instead > of each - then the result is an array of each value returned from the > block. > > Regards > - henrik > > -- > > Visit my Blog "Puppet on the Edge" > http://puppet-on-the-edge.blogspot.se/ > > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b32aa9ae-79a6-4480-9033-2ddcb981df63%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] String substituion in puppet template
On 2015-22-05 11:08, Gabriel Filion wrote: On 20/05/15 09:04 AM, Björn wrote: I tried it with regsubst, but without success: | <%ip_xforward.each do|name|-%><%="\t\tSetEnvIF X-Forwarded-For ^(regsubst(#{name}, '\.','\\.')) AllowIP\n"%><%end-%> | maybe you need to call the function outside of the string. e.g.: <%= "\t\tSetEnvIf X-Forwarded-For ^(" + regsubst(name, '\.','\\.') + ") AllowIP\n"%> Note that the each method returns the original LHS not the string. Also, the substitution inside the string is not code that gets evaluation, you need to interpolate it using #{} around the expression, or do a concat. If you want to transform each, you should use the map function instead of each - then the result is an array of each value returned from the block. Regards - henrik -- Visit my Blog "Puppet on the Edge" http://puppet-on-the-edge.blogspot.se/ -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/mjn6v5%24gen%241%40ger.gmane.org. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] String substituion in puppet template
Am Freitag, 22. Mai 2015 11:09:15 UTC+2 schrieb Gabriel Filion: > > On 20/05/15 09:04 AM, Björn wrote: > > I tried it with regsubst, but without success: > > | > > <%ip_xforward.each do|name|-%><%="\t\tSetEnvIF X-Forwarded-For > > ^(regsubst(#{name}, '\.','\\.')) AllowIP\n"%><%end-%> > > | > > maybe you need to call the function outside of the string. e.g.: > > <%= "\t\tSetEnvIf X-Forwarded-For ^(" + regsubst(name, '\.','\\.') + ") > AllowIP\n"%> > > -- > Gabriel Filion > > Probably. But somehow the puppet agent can't find the value for regsubst <% ip_xforward.each do |name| -%> <%= "\t\tSetEnvIf X-Forwarded-For ^(" + regsubst("#{name}", 'foo','bar') + ") AllowIP\n" %> <% end -%> Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template apache/vhost-default.conf.erb: Filepath: /usr/lib/ruby/site_ruby/1.8/puppet/parser/templatewrapper.rb Line: 81 Detail: Could not find value for 'regsubst' at /etc/puppet/modules/apache/ templates/vhost-default.conf.erb:68 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/55b63a29-3e24-410a-9646-760e016e1007%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] String substituion in puppet template
On 20/05/15 09:04 AM, Björn wrote: > I tried it with regsubst, but without success: > | > <%ip_xforward.each do|name|-%><%="\t\tSetEnvIF X-Forwarded-For > ^(regsubst(#{name}, '\.','\\.')) AllowIP\n"%><%end-%> > | maybe you need to call the function outside of the string. e.g.: <%= "\t\tSetEnvIf X-Forwarded-For ^(" + regsubst(name, '\.','\\.') + ") AllowIP\n"%> -- Gabriel Filion -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/555EF225.6020401%40lelutin.ca. For more options, visit https://groups.google.com/d/optout. signature.asc Description: OpenPGP digital signature
[Puppet Users] String substituion in puppet template
Hello, I try to customize my http vhost template and defined and array of ip addresses in the manifests: class apache::webservice( $htdocs = $apache::param::htdocs, $apacheuser = $apache::param::apacheuser, $apachegroup = $apache::param::apachegroup, $logdir = $apache::param::logdir, ) inherits apache::param{ $sitename = "service.de" file{"$logdir/$sitename": ensure => directory, } apache::vhost {"app $name": template=> 'apache/vhost-proxypass.conf.erb', port=> 80, servername => "$sitename", modsec => "", pptarget=> "10.18.10.10", ppproto => "http", ppport => "8080", ppoptions => "", ppexception => "", logformat => "combined_forwarded", rewrite => "webservice", ip => ["10.18.10."], ip_xforward => ["75.2.91.24", "94.5.52.252", ], } } In my template I try to use the array ip_xforward to put those ip adresses in a variable and allow them: <% if @rewrite != '' && @ip != '' || @ip_xforward != '' %> > <% if @ip_xforward != '' %> <% if ip.is_a? Array -%> <% ip_xforward.each do |name| -%><%= "\t\tSetEnvIF X-Forwarded-For ^(#{name}) AllowIP\n" %><% end -%> <% elsif @ip_xforward != '' -%> <%= " SetEnvIF X-Forwarded-For ^(#{ip_xforward}) AllowIP" -%> <% end -%> <% end -%> Order deny,allow Deny from all Allow from env=AllowIP <% if @ip != '' %> <% if ip.is_a? Array -%> <% ip.each do |name| -%><%= "Allow from #{name}\n" %><% end -%> <% elsif @ip != '' -%> <%= " Allow from #{ip}" -%> <% end -%> <% end -%> <% end %> My problem is that I have to escape the dot's in the ip address because it's a regex. It should look like SetEnvIF X-Forwarded-For ^(94\.20\.18\.9) AllowIP But actually it look like this: SetEnvIF X-Forwarded-For ^(94.20.18.9) AllowIP I tried it with regsubst, but without success: <% ip_xforward.each do |name| -%><%= "\t\tSetEnvIF X-Forwarded-For ^(regsubst(#{name}, '\.','\\.')) AllowIP\n" %><% end -%> -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ba298552-d752-4db5-930a-7aa2515ffc39%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.