okay, this works.

test.pp
class a {

  $inline = inline_template(
'<% scope.lookupvar("interfaces").split(",").each do |interface| %>
 <% @int_ip = scope.lookupvar("ipaddress_" + interface) %>
 <% @int_name = Resolv.new.getname @int_ip %>
 <%= "#{@int_ip} :::::::: #{@int_name}" %>
 <% end %>')

notify { $inline: }

}

include a


$ puppet apply test.pp

Notice: /Stage[main]/A/Notify[
 10.0.2.15 :::::::: fake.name.net
 172.28.128.5 :::::::: another.faker.net
 127.0.0.1 :::::::: localhost
 ]/

Sorry to mess you around before. Maybe it was your mixing of "'" and """?



On Thu, Nov 26, 2015 at 8:21 AM, Dayton Jones <jones.day...@gmail.com>
wrote:

> Right, that works -- but I want to get the IP by using the scope.lookup
> var and not hardcode an IP in the template.  I know both the
> "scope.lookupvar('ipaddress_'+interface)" and "@int_name =
> Resolv.new.getname <ip>" works, but I'm struggling on how to send the IP
> gained from the lookupvar to the Resolv.new.getname function inside the
> template.. It should just be a syntax issue, but I'm new to ruby/erb  so
> I'm not sure the correct way to pass a generated string to a function
> within the same structure...
>
> On Wednesday, November 25, 2015 at 3:10:55 PM UTC-6, denmat wrote:
>>
>> Sorry, rushing around on trains. Try this:
>>
>> irb(main):002:0> require 'resolv'
>> => true
>> irb(main):003:0> Resolv.new.getname('127.0.0.1')
>> => "localhost"
>>
>> On Thu, Nov 26, 2015 at 7:54 AM, Denmat <tu2b...@gmail.com> wrote:
>>
>>> Sorry, ignore my suggestion. That won't work.
>>>
>>> On 26 Nov 2015, at 06:57, Dayton Jones <jones....@gmail.com> wrote:
>>>
>>> I'm writing a template to populate a file - easy enough...
>>>
>>> What I want is to to grab the list of interfaces, get the ip assigned to
>>> that interface and then do a lookup of the ip to get the dns name.
>>>
>>> I'm able to get the interfaces/ips just fine, but can't figure out how
>>> to then pass the IP to the function to do the lookup.  Any help is greatly
>>> appreciated...
>>>
>>> =======================
>>> start ERB
>>>
>>> <% scope.lookupvar('interfaces').split(",").each do |interface| %>
>>> <% @int_ip = scope.lookupvar('ipaddress_'+interface) %>
>>> <% @int_name = Resolv.new.getname @int_ip %>
>>> ...
>>> <% end %>
>>>
>>> end ERB
>>> ========================
>>>
>>> @int_ip gets popluated and I can manipulate it as needed, but how do I
>>> properly pass it to 'Resolv.new.getname' to set the int_name string?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/puppet-users/6bf51a8e-eb7f-4bcd-ac77-2451bcbec5ce%40googlegroups.com
>>> <https://groups.google.com/d/msgid/puppet-users/6bf51a8e-eb7f-4bcd-ac77-2451bcbec5ce%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>> --
> 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/14fe0e25-b0b6-4118-8212-87734e580029%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/14fe0e25-b0b6-4118-8212-87734e580029%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAJsPER0kBDxCpkdZqWoav_EJqmDeCtLFPU4Z6wh1uU_WL%2BTVXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to