Using foreman to provision a vm with static ip

5,582

I got it working now by changing this line in the default kickstart template from:

network --bootproto <%= @static ? "static --ip=#{@host.ip} --netmask=#{@host.subnet.mask} --gateway=#{@host.subnet.gateway} --nameserver=#{[@host.subnet.dns_primary,@host.subnet.dns_secondary].reject{|n| n.blank?}.join(',')}" : 'dhcp' %> --hostname <%= @host %>

to:

network --bootproto <%= "static --ip=#{@host.ip} --netmask=#{@host.subnet.mask} --gateway=#{@host.subnet.gateway} --nameserver=#{[@host.subnet.dns_primary,@host.subnet.dns_secondary].reject{|n| n.blank?}.join(',')}" %> --hostname <%= @host %>

This way i force using a static ip.

However, i still wonder how to pass that variable to kickstart correctly.

Share:
5,582

Related videos on Youtube

rinini
Author by

rinini

Updated on September 18, 2022

Comments

  • rinini
    rinini almost 2 years

    I am trying to provision a vm with Centos6.5 on vmware with a static ip address using Foreman 1.5.1. However, the vm's keeps getting provisioned with a dhcp address. Im doing a network based install. I created a subnet with all the information about the network (subnet range, gateway, dns server, etc). In foreman i enabled the dhcp smart proxy for that subnet (disabling it will still give the same result, as long as the dhcp server is running)

    Here the relevant lines from the provisioning templates:

    Kickstart pxe:

    <% if @host.operatingsystem.name == 'Fedora' and @host.operatingsystem.major.to_i > 16 -%>`
    append initrd=<%= @initrd %> ks=<%= foreman_url('provision')%>?static=yes ks.device=bootif network ks.sendmac ip=<%= @host.ip %> netmask=<%= @host.subnet.mask %> gateway=<%= @host.subnet.gateway %> dns=<%= @host.subnet.dns_primary %>
    <% elsif @host.operatingsystem.name != 'Fedora' and @host.operatingsystem.major.to_i >= 7 -%>
    `append initrd=<%= @initrd %> ks=<%= foreman_url('provision')%>?static=yes network ks.sendmac ip=        <%= @host.ip %> netmask=<%= @host.subnet.mask %> gateway=<%= @host.subnet.gateway %> dns=<%= @host.subnet.dns_primary %>
    <% else -%>
    append initrd=<%= @initrd %> ks=<%= foreman_url('provision')%>?static=yes ksdevice=bootif  network kssendmac ip=<%= @host.ip %> netmask=<%= @host.subnet.mask %> gateway=<%= @host.subnet.gateway %> dns=<%= @host.subnet.dns_primary %> 
    <% end -%>
    

    kickstart default:

    network --bootproto <%= @static ? "static --ip=#{@host.ip} --netmask=#{@host.subnet.mask} --gateway=#{@host.subnet.gateway} --nameserver=#{[@host.subnet.dns_primary,@host.subnet.dns_secondary].reject{|n| n.blank?}.join(',')}" : 'dhcp' %> --hostname <%= @host %>
    

    Everything works, the server is created in vmware, it is installed using pxe, registered in foreman, etc. Except the ip address is not static.

    What am i doing wrong here?

    The actual ks file after the installation contains the following line:

    network --onboot yes --device eth0 --mtu=1500 --bootproto dhcp --hostname test3.example.net 
    

    which is weird because i add ?static=yes to the ks url. (i think thats the way to do it?)

    • devicenull
      devicenull almost 10 years
      What does the actual kickstart look like after the VM installs? This is saved in /root/ on the newly installed machine. Does it contain the proper network line?
    • rinini
      rinini almost 10 years
      It contains the following line: network --onboot yes --device eth0 --mtu=1500 --bootproto dhcp --hostname test3.example.net which is weird because i add ?static=yes to the ks url. (i think thats the way to do it?)