I'm new to ruby and I'm writing a puppet module to be accessed via Foreman.
I writing it to be used by Foreman's Smart Class Parameter so it can be configured from the Foreman web console.
I was trying to see how I could create a parameter for 48 possible ports a device might have. Instead of manually entering the ports I was wondering if it is possible to do this dynamically.
For example instead of this:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface'
) {
interface {
'FastEthernet 0/1':
description => $interface_description_lan
}
interface {
'FastEthernet 0/2':
description => $interface_description_lan
}
}
I want to do this:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface',
) {
interface {
(0..48).each do |i|
"FastEthernet 0/#{i}":
description => $interface_description_lan
end
}
}
Following a commenter's suggestion I tried this, but it doesn't not work:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface',
) {
arrInterfaces = Array(1..48)
arrInterfaces.each{
interface {
|intNum| puts "FastEthernet 0/#{intNum}":
description => $interface_description_lan
}
}
}