Drop <% @host.interfaces.each do |i| %> key is <%= i.ip %> <% end %> into the top line of the "Kickstart default" template. I was expecting
this to print 'key is 192.168.x.y key is 192.168.n.m' into the provisioning
template, but instead it prints nothing.
Try <%= @host.interfaces.each do |i| %> key is <%= i.ip %> <% end %> into the top of the template. This results in a syntax error:
There was an error rendering the Kickstart default: (erb):1: syntax error, unexpected ')'
… @host.interfaces.each do |i| ).to_s); _erbout.concat " key …
… ^
(erb):116: syntax error, unexpected $end, expecting ')'
_erbout.force_encoding(ENCODING)
Clearly I'm missing something about arrays within ERB. Any ideas?
My goal is for the Kickstart template to dynamically provision the IP address, Netmask, Gateway and Hostname based on the information for this second interface; and assign that to eth0. Here is some pseudo-code:
Well, I figured this out. Sort of. #2 failed because it starts with a <%=, which is the wrong syntax. The correct syntax is <%, with no =.
Option #1 now works. I'm not really sure why it was failing yesterday and
it works today, but I must have twiddled another switch somehow.
-= Stefan
···
On Thursday, December 5, 2013 5:58:39 PM UTC-8, Stefan Lasiewski wrote:
>
>
> 1. Drop `<% @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
> %>` into the top line of the
> 2. Try `<%= @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
> %>` into the top of the template.
>
>
>
> I am using the "Kickstart default" provisioning template.
>
> My goal is for the Kickstart template to dynamically provision the IP address, Netmask, Gateway and Hostname based on the information for this second interface; and assign that to eth0. Here is some pseudo-code:
>
>
> network --bootproto static --hostname <%= @host %> --device eth0 --onboot yes --ip <%= the_public_ip %> --netmask <%= the_public_netmask %> --gateway <%= the_public_gateway %> --noipv6 --hostname <%= the_public_hostname %>
>
>
And at long last I figure this out.
My Kickstart provisioning ERB template is now able to utilize the IP
address, Netmask, Gateway and Hostname which was assigned in the Foreman
interface.
Use the IP, Netmask & gateway for the first managed (e.g. Non -MC)
I learned that the Primary interface is not actually contained within the @host.interfaces array. That array only contains the BMC and secondary
interfaces.
Also, since the array contains secondary and BMC interfaces, it's important
to look for managed interfaces using @host.interfaces.managed, as
opposed to @host.interfaces.bmc interfaces.
Kudos to RobertBirnie in #theforeman for helping me out here.
-= Stefan
···
On Thursday, December 5, 2013 5:58:39 PM UTC-8, Stefan Lasiewski wrote:
>
>
>
···
On Thursday, December 5, 2013 at 7:58:39 PM UTC-6, Stefan Lasiewski wrote:
>
> I am using the "Kickstart default" provisioning template.
>
> My systems have two network interfaces.
>
> If I add a second interface using
> https://foreman.example.org/hosts/node2.example.org/edit , can I use the
> IP address, netmask, etc. in a variable in the provisioning template? I
> read http://projects.theforeman.org/projects/foreman/wiki/TemplateWriting
> and I see that `@host.interfaces` is available as an array. I have disabled
> 'Safe mode' under "*More > Settings"*
>
> I've tried the following without success. For each of these experiments, I
> test my changes using
> https://foreman.example.org/unattended/provision?spoof=192.168.x.y
>
>
> 1. Drop `<% @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
> %>` into the top line of the "Kickstart default" template. I was expecting
> this to print 'key is 192.168.x.y key is 192.168.n.m' into the provisioning
> template, but instead it prints nothing.
> 2. Try `<%= @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
> %>` into the top of the template. This results in a syntax error:
>
> There was an error rendering the Kickstart default: (erb):1: syntax error, unexpected ')'
> ... @host.interfaces.each do |i| ).to_s); _erbout.concat " key ...
> ... ^
> (erb):116: syntax error, unexpected $end, expecting ')'
> _erbout.force_encoding(__ENCODING__)
>
> Clearly I'm missing something about arrays within ERB. Any ideas?
>
> My goal is for the Kickstart template to dynamically provision the IP address, Netmask, Gateway and Hostname based on the information for this second interface; and assign that to eth0. Here is some pseudo-code:
>
>
> network --bootproto static --hostname <%= @host %> --device eth0 --onboot yes --ip <%= the_public_ip %> --netmask <%= the_public_netmask %> --gateway <%= the_public_gateway %> --noipv6 --hostname <%= the_public_hostname %>
>
>
>
> -= Stefan
>
>
>
I don't totally remember if this solves my problem, but once I figured out
how to access the array, I simply assign a variable and use that. This
looks simple, but it was pretty hard to figure out.
Use the IP, Netmask & gateway for the first managed (e.g. Non -MC)
interface.
NOTE: SERVER MUST HAVE ADDITIONAL NICS (Not just the primary NIC) FOR
···
On Thursday, January 22, 2015 at 2:10:34 PM UTC-8, Randy Black wrote:
>
> Mind sharing your snippet that made that work?
>
> On Thursday, December 5, 2013 at 7:58:39 PM UTC-6, Stefan Lasiewski wrote:
>>
>> I am using the "Kickstart default" provisioning template.
>>
>> My systems have two network interfaces.
>>
>> If I add a second interface using
>> https://foreman.example.org/hosts/node2.example.org/edit , can I use the
>> IP address, netmask, etc. in a variable in the provisioning template? I
>> read http://projects.theforeman.org/projects/foreman/wiki/TemplateWriting
>> and I see that `@host.interfaces` is available as an array. I have disabled
>> 'Safe mode' under "*More > Settings"*
>>
>> I've tried the following without success. For each of these experiments,
>> I test my changes using
>> https://foreman.example.org/unattended/provision?spoof=192.168.x.y
>>
>>
>> 1. Drop `<% @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
>> %>` into the top line of the "Kickstart default" template. I was expecting
>> this to print 'key is 192.168.x.y key is 192.168.n.m' into the provisioning
>> template, but instead it prints nothing.
>> 2. Try `<%= @host.interfaces.each do |i| %> key is <%= i.ip %> <% end
>> %>` into the top of the template. This results in a syntax error:
>>
>> There was an error rendering the Kickstart default: (erb):1: syntax error, unexpected ')'
>> ... @host.interfaces.each do |i| ).to_s); _erbout.concat " key ...
>> ... ^
>> (erb):116: syntax error, unexpected $end, expecting ')'
>> _erbout.force_encoding(__ENCODING__)
>>
>> Clearly I'm missing something about arrays within ERB. Any ideas?
>>
>> My goal is for the Kickstart template to dynamically provision the IP address, Netmask, Gateway and Hostname based on the information for this second interface; and assign that to eth0. Here is some pseudo-code:
>>
>>
>> network --bootproto static --hostname <%= @host %> --device eth0 --onboot yes --ip <%= the_public_ip %> --netmask <%= the_public_netmask %> --gateway <%= the_public_gateway %> --noipv6 --hostname <%= the_public_hostname %>
>>
>>
>>
>> -= Stefan
>>
>>
>>
undefined method `gateway' for nil:NilClass
>
>
To me that says the interface doesn't have a subnet set upon it - you're
getting 'nil' back for int.subnet, and then trying to call gateway on nil.
I've tested this locally, and so long as my extra interface has a subnet
set, it works fine:
irb(main):010:0> @host.interfaces.size
=> 1 # Note that the interfaces array doesn't include the primary
interface, so this host has 2 interfaces
Indeed, I accidentally left those fields blank. And I sort of assumed that
if I assigned an IP address, the netmask and gateway would be implicit.
Now I'm using the following test code, and it is closer to what I want:
Start loop:
<% @host.interfaces.each do |int| %>
Test: key is <%= int.ip %>, int is <%= int %>
Test: Gateway: <%= int.subnet.gateway %>
Test: Netmask: <%= int.subnet.mask %>
network --bootproto static --hostname <%= @host %> --device eth0 --onboot
yes --ip <%= int.ip %> --netmask <%= int.subnet.mask %> --gateway <%=
int.subnet.gateway %> --noipv6
<% end %>
End loop
Result
Start loop:
Test: key is 192.168.250.250, int is stefantest-bmc
Test: Gateway: 192.168.250.1
Test: Netmask: 255.255.255.0
network --bootproto static --hostname stefantest.example.org --device
eth0 --onboot yes --ip 192.168.250.250 --netmask 255.255.255.0
–gateway 192.168.250.1 --noipv6
Test: key is 172.16.100.117, int is second-interface
Test: Gateway: 172.16.1.1
Test: Netmask: 255.255.0.0
network --bootproto static --hostname stefantest.example.org --device
eth0 --onboot yes --ip 172.16.100.117 --netmask 255.255.0.0 --gateway
172.16.1.1 --noipv6
End loop
Now I just need to figure out how to select the right interface via an
index and I'll be good to go. I only want to print information for the
second interface and assign that to eth0.
Thanks!
-= Stefan
···
On Sat, Dec 7, 2013 at 5:38 AM, Greg Sutcliffe wrote:
Hey,
undefined method `gateway’ for nil:NilClass
To me that says the interface doesn’t have a subnet set upon it - you’re
getting ‘nil’ back for int.subnet, and then trying to call gateway on nil.
I’ve tested this locally, and so long as my extra interface has a subnet
set, it works fine:
irb(main):010:0> @host.interfaces.size
=> 1 # Note that the interfaces array doesn’t include the primary
interface, so this host has 2 interfaces
Rails to the rescue - try @host.interfaces.find_by_name('second-interface')
Greg
···
On 7 December 2013 16:17, Stefan Lasiewski wrote:
Now I just need to figure out how to select the right interface via an
index and I’ll be good to go. I only want to print information for the
second interface and assign that to eth0.
Where I hope this still works, is it possible to exclude eth0 for an
example ?
···
Op zaterdag 7 december 2013 17:17:02 UTC+1 schreef Stefan Lasiewski:
>
> Thanks again Greg! This works for me now.
>
> Indeed, I accidentally left those fields blank. And I sort of assumed that
> if I assigned an IP address, the netmask and gateway would be implicit.
>
> Now I'm using the following test code, and it is closer to what I want:
>
> ### Start loop:
> <% @host.interfaces.each do |int| %>
> Test: key is <%= int.ip %>, int is <%= int %>
> Test: Gateway: <%= int.subnet.gateway %>
> Test: Netmask: <%= int.subnet.mask %>
> network --bootproto static --hostname <%= @host %> --device eth0 --onboot
> yes --ip <%= int.ip %> --netmask <%= int.subnet.mask %> --gateway <%=
> int.subnet.gateway %> --noipv6
>
> <% end %>
> ### End loop
>
> Result
>
> ### Start loop:
>
> Test: key is 192.168.250.250, int is stefantest-bmc
> Test: Gateway: 192.168.250.1
> Test: Netmask: 255.255.255.0
> network --bootproto static --hostname stefantest.example.org --device eth0 --onboot yes --ip 192.168.250.250 --netmask 255.255.255.0 --gateway 192.168.250.1 --noipv6
>
>
> Test: key is 172.16.100.117, int is second-interface
> Test: Gateway: 172.16.1.1
> Test: Netmask: 255.255.0.0
> network --bootproto static --hostname stefantest.example.org --device eth0 --onboot yes --ip 172.16.100.117 --netmask 255.255.0.0 --gateway 172.16.1.1 --noipv6
>
>
> ### End loop
>
>
> Now I just need to figure out how to select the right interface via an
> index and I'll be good to go. I only want to print information for the
> second interface and assign that to eth0.
>
> Thanks!
>
> -= Stefan
>
>
> On Sat, Dec 7, 2013 at 5:38 AM, Greg Sutcliffe > wrote:
>
>> Hey,
>>
>> undefined method `gateway' for nil:NilClass
>>>
>>>
>> To me that says the interface doesn't have a subnet set upon it - you're
>> getting 'nil' back for int.subnet, and then trying to call gateway on nil.
>>
>> I've tested this locally, and so long as my extra interface has a subnet
>> set, it works fine:
>>
>> irb(main):010:0> @host.interfaces.size
>> => 1 # Note that the interfaces array doesn't include the primary
>> interface, so this host has 2 interfaces
>>
>> irb(main):011:0> @host.interfaces.first.subnet.gateway
>> => "192.168.122.1"
>> irb(main):012:0> @host.interfaces.first.subnet.mask
>> => "255.255.255.0"
>>
>> HTH,
>> Greg
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Foreman users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/foreman-users/vE1P49gFtQk/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> foreman-user...@googlegroups.com .
>> To post to this group, send email to forema...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/foreman-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
I see, and then to print all interfaces I can use the .all method in the
template. For example, this will print all information about all interfaces
in the @host array:
Find all: <%= @host.interfaces.all -%>
This will print the name of the first, second and third arrays:
Find first: <%= @host.interfaces.first %>
Find second (blank?): <%= @host.interfaces.second %>
Find third (blank?): <%= @host.interfaces.third %>
-= Stefan
···
On Saturday, December 7, 2013 9:30:31 AM UTC-8, Greg Sutcliffe wrote:
>
> On 7 December 2013 16:17, Stefan Lasiewski <ste...@stefanco.com > > wrote:
>
>> Now I just need to figure out how to select the right interface via an
>> index and I'll be good to go. I only want to print information for the
>> second interface and assign that to eth0.
>>
>
> Rails to the rescue - try @host.interfaces.find_by_name('second-interface')
>
I'm pretty sure I recently saw a ticket which will change how the @host.interfaces will work. @host.interfaces should include all
interfaces on a system so that it is easier to select which interface will
be used for pxebooting.
Many of us want to pxeboot from the secondary interface, because the
primary interface is already reserved for whatever service my node will end
up providing, and I don't want to switch cables every time I provision a
system.
-= Stefan
···
On Wed, Aug 20, 2014 at 10:55 AM, wrote:
Where I hope this still works, is it possible to exclude eth0 for an
example ?
Op zaterdag 7 december 2013 17:17:02 UTC+1 schreef Stefan Lasiewski:
Thanks again Greg! This works for me now.
Indeed, I accidentally left those fields blank. And I sort of assumed
that if I assigned an IP address, the netmask and gateway would be implicit.
Now I’m using the following test code, and it is closer to what I want:
Start loop:
<% @host.interfaces.each do |int| %>
Test: key is <%= int.ip %>, int is <%= int %>
Test: Gateway: <%= int.subnet.gateway %>
Test: Netmask: <%= int.subnet.mask %>
network --bootproto static --hostname <%= @host %> --device eth0 --onboot
yes --ip <%= int.ip %> --netmask <%= int.subnet.mask %> --gateway <%=
int.subnet.gateway %> --noipv6
<% end %>
End loop
Result
Start loop:
Test: key is 192.168.250.250, int is stefantest-bmc
Test: Gateway: 192.168.250.1
Test: Netmask: 255.255.255.0
network --bootproto static --hostname stefantest.example.org --device eth0 --onboot yes --ip 192.168.250.250 --netmask 255.255.255.0 --gateway 192.168.250.1 --noipv6
Test: key is 172.16.100.117, int is second-interface
Test: Gateway: 172.16.1.1
Test: Netmask: 255.255.0.0
network --bootproto static --hostname stefantest.example.org --device eth0 --onboot yes --ip 172.16.100.117 --netmask 255.255.0.0 --gateway 172.16.1.1 --noipv6
End loop
Now I just need to figure out how to select the right interface via an
index and I’ll be good to go. I only want to print information for the
second interface and assign that to eth0.
–
You received this message because you are subscribed to a topic in the
Google Groups “Foreman users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/foreman-users/vE1P49gFtQk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to foreman-user...@googlegroups.com.
To post to this group, send email to forema...@googlegroups.com.
Where I hope this still works, is it possible to exclude eth0 for an
example ?
Op zaterdag 7 december 2013 17:17:02 UTC+1 schreef Stefan Lasiewski:
Thanks again Greg! This works for me now.
Indeed, I accidentally left those fields blank. And I sort of assumed that
if I assigned an IP address, the netmask and gateway would be implicit.
Now I’m using the following test code, and it is closer to what I want:
Start loop:
<% @host.interfaces.each do |int| %>
Test: key is <%= int.ip %>, int is <%= int %>
Test: Gateway: <%= int.subnet.gateway %>
Test: Netmask: <%= int.subnet.mask %>
network --bootproto static --hostname <%= @host %> --device eth0 --onboot
yes --ip <%= int.ip %> --netmask <%= int.subnet.mask %> --gateway <%=
int.subnet.gateway %> --noipv6
<% end %>
End loop
Result
Start loop:
Test: key is 192.168.250.250, int is stefantest-bmc
Test: Gateway: 192.168.250.1
Test: Netmask: 255.255.255.0
network --bootproto static --hostname stefantest.example.org --device eth0
–onboot yes --ip 192.168.250.250 --netmask 255.255.255.0 --gateway
192.168.250.1 --noipv6
Test: key is 172.16.100.117, int is second-interface
Test: Gateway: 172.16.1.1
Test: Netmask: 255.255.0.0
network --bootproto static --hostname stefantest.example.org --device eth0
–onboot yes --ip 172.16.100.117 --netmask 255.255.0.0 --gateway
172.16.1.1 --noipv6
End loop
Now I just need to figure out how to select the right interface via an
index and I’ll be good to go. I only want to print information for the
second interface and assign that to eth0.
Thanks!
-= Stefan
On Sat, Dec 7, 2013 at 5:38 AM, Greg Sutcliffe <greg.su...@gmail.com > > > > <javascript:>> wrote:
Hey,
undefined method `gateway’ for nil:NilClass
To me that says the interface doesn’t have a subnet set upon it - you’re
getting ‘nil’ back for int.subnet, and then trying to call gateway on
nil.
I’ve tested this locally, and so long as my extra interface has a subnet
set, it works fine:
irb(main):010:0> @host.interfaces.size
=> 1 # Note that the interfaces array doesn’t include the primary
interface, so this host has 2 interfaces
> I'm pretty sure I recently saw a ticket which will change how the
> @host.interfaces will work. @host.interfaces should include all interfaces
> on a system so that it is easier to select which interface will be used for
> pxebooting.
Eventually yes. Work is in progress, but it may be a while in arriving
in a stable release.
> Many of us want to pxeboot from the secondary interface, because the primary
> interface is already reserved for whatever service my node will end up
> providing, and I don't want to switch cables every time I provision a
> system.
As a workaround, consider that what Foreman regards as the "primary"
interface does not have to be what you regard as the primary. Simply
assign the provisioning network device as the primary, and the other
one as a secondary, and it should work fine.
Greg
···
On 21 August 2014 17:02, Stefan Lasiewski wrote: