Ah...nevermind, figured this out!

Sorting (well, reverse sorting so lo0 gets put first):
<% @interfaces.split(',').sort!{|x, y| y <=> x}.each do |int| if 
has_variable?("ipaddress_#{int}") -%>

Splitting:
<% fqdn =  Resolv.getname(scope["ipaddress_#{int}"]) -%>
<% name = (fqdn.split('.')) -%>
<%= scope["ipaddress_#{int}"] -%> <%= fqdn -%> <%= name.first %>


On Monday, November 30, 2015 at 8:52:00 AM UTC-6, Dayton Jones wrote:
>
> Ok... I switched tactics somewhat and have more or less what I wanted:
>
> === start ERB file ===
> <% @interfaces.split(',').each do |int| if 
> has_variable?("ipaddress_#{int}") -%>
> <%= scope["ipaddress_#{int}"] -%> <%= 
> Resolv.getname(scope["ipaddress_#{int}"]) -%>
> <% end -%>
> <% end -%>
> === end ERB file ===
>
> this will give the the IP and associated FQDN of all the interfaces but I 
> was wondering if the community could give me a little more help..
>
> 1) Once I have all the interfaces/names, how can I split the FQDN and get 
> the short name (myhost vs myhost.domain.com)
> 2) Is there a way to order the output (put 127.0.0.1 at the top, etc)?
>
>
> On Wednesday, November 25, 2015 at 2:25:22 PM UTC-6, Dayton Jones 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/8a361168-e034-475d-ac9b-898abcd04a10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to