|
<%#
|
|
kind: snippet
|
|
name: kickstart_networking_setup
|
|
description: this will configure your host networking, it configures your primary interface as well
|
|
as other configures NICs. It supports physical, VLAN and Alias interfaces. It's intended to be
|
|
called from %post in your kickstart template. Note that this snippet can be used with Foreman 1.7
|
|
and later
|
|
%>
|
|
<% subnet = @host.subnet -%>
|
|
<% subnet6 = @host.subnet6 -%>
|
|
<% dhcp = subnet.dhcp_boot_mode? -%>
|
|
|
|
<% if @host.respond_to?(:has_primary_interface?) %>
|
|
<%# Foreman 1.7 - primary interface contained in @host %>
|
|
# primary interface
|
|
real=`ip -o link | grep <%= @host.mac -%> | awk '{print $2;}' | sed s/://`
|
|
<% if @host.has_primary_interface? %>
|
|
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$real
|
|
BOOTPROTO="<%= dhcp ? 'dhcp' : 'none' -%>"
|
|
<% unless dhcp -%>
|
|
IPADDR="<%= @host.ip -%>"
|
|
NETMASK="<%= subnet.mask -%>"
|
|
<% if subnet.gateway.present? -%>
|
|
GATEWAY="<%= subnet.gateway %>"
|
|
<% end -%>
|
|
<% if @host.ip6.present? -%>
|
|
IPV6INIT=yes
|
|
IPV6_AUTOCONF=no
|
|
IPV6ADDR=<%= @host.ip6 %>
|
|
<% if subnet6.gateway.present? -%>
|
|
IPV6_DEFAULTGW=<%= subnet6.gateway %>
|
|
<% end -%>
|
|
IPV6_PEERDNS=no
|
|
<% end -%>
|
|
<% end -%>
|
|
DEVICE=$real
|
|
HWADDR="<%= @host.mac -%>"
|
|
ONBOOT=yes
|
|
EOF
|
|
<% end -%>
|
|
<% end -%>
|
|
|
|
<% bonded_interfaces = [] %>
|
|
<% bonds = @host.bond_interfaces %>
|
|
<% bonds.each do |bond| %>
|
|
<% subnet = bond.subnet -%>
|
|
<% subnet6 = bond.subnet6 -%>
|
|
<% dhcp = subnet.nil? ? false : subnet.dhcp_boot_mode? -%>
|
|
# <%= bond.identifier %> interface
|
|
real="<%= bond.identifier -%>"
|
|
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$real
|
|
BOOTPROTO="<%= dhcp ? 'dhcp' : 'none' -%>"
|
|
<% unless dhcp || subnet.nil? -%>
|
|
IPADDR="<%= bond.ip -%>"
|
|
NETMASK="<%= subnet.mask -%>"
|
|
<% if subnet.gateway.present? -%>
|
|
GATEWAY="<%= subnet.gateway %>"
|
|
<% end -%>
|
|
<% if bond.ip6.present? -%>
|
|
IPV6INIT=yes
|
|
IPV6_AUTOCONF=no
|
|
IPV6ADDR=<%= bond.ip6 %>
|
|
<% if subnet6.gateway.present? -%>
|
|
IPV6_DEFAULTGW=<%= subnet6.gateway %>
|
|
<% end -%>
|
|
IPV6_PEERDNS=no
|
|
<% end -%>
|
|
<% end -%>
|
|
DEVICE=$real
|
|
ONBOOT=yes
|
|
PEERDNS=no
|
|
PEERROUTES=no
|
|
DEFROUTE="<%= bond.primary ? 'yes' : 'no' -%>"
|
|
TYPE=Bond
|
|
BONDING_OPTS="<%= bond.bond_options -%> mode=<%= bond.mode -%>"
|
|
BONDING_MASTER=yes
|
|
NM_CONTROLLED=no
|
|
EOF
|
|
|
|
<% @host.interfaces_with_identifier(bond.attached_devices_identifiers).each do |interface| -%>
|
|
<% next if !interface.managed? -%>
|
|
|
|
<% subnet = interface.subnet -%>
|
|
<% virtual = interface.virtual? -%>
|
|
<% vlan = virtual && (subnet.has_vlanid? || interface.vlanid.present?) -%>
|
|
<% alias_type = virtual && !subnet.nil? && !subnet.has_vlanid? && interface.identifier.include?(':') -%>
|
|
<% dhcp = !subnet.nil? && subnet.dhcp_boot_mode? -%>
|
|
|
|
# <%= interface.identifier %> interface
|
|
real=`ip -o link | grep <%= interface.inheriting_mac -%> | awk '{print $2;}' | sed s/:$//`
|
|
<% if virtual -%>
|
|
real=`echo <%= interface.identifier -%> | sed s/<%= interface.attached_to -%>/$real/`
|
|
<% end -%>
|
|
|
|
# ifcfg files are ignored by NM if their name contains colons so we convert colons to underscore
|
|
<% if alias_type -%>
|
|
sanitized_real=`echo $real | sed s/:/_/`
|
|
<% else -%>
|
|
sanitized_real=$real
|
|
<% end -%>
|
|
|
|
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$sanitized_real
|
|
BOOTPROTO="none"
|
|
DEVICE=$real
|
|
<% unless virtual -%>
|
|
HWADDR="<%= interface.mac -%>"
|
|
<% end -%>
|
|
ONBOOT=yes
|
|
PEERDNS=no
|
|
PEERROUTES=no
|
|
DEFROUTE=no
|
|
<% if vlan -%>
|
|
VLAN=yes
|
|
<% elsif alias_type -%>
|
|
TYPE=Alias
|
|
<% end -%>
|
|
NM_CONTROLLED=no
|
|
MASTER=<%= bond.identifier %>
|
|
SLAVE=yes
|
|
EOF
|
|
|
|
<% bonded_interfaces.push(interface.identifier) -%>
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<% @host.managed_interfaces.each do |interface| %>
|
|
<% next if !interface.managed? || interface.subnet.nil? -%>
|
|
<% next if bonded_interfaces.include?(interface.identifier) -%>
|
|
|
|
<% subnet = interface.subnet -%>
|
|
<% subnet6 = interface.subnet6 -%>
|
|
<% virtual = interface.virtual? -%>
|
|
<% vlan = virtual && (subnet.has_vlanid? || interface.vlanid.present?) -%>
|
|
<% alias_type = virtual && !subnet.has_vlanid? && interface.identifier.include?(':') -%>
|
|
<% dhcp = subnet.dhcp_boot_mode? -%>
|
|
|
|
# <%= interface.identifier %> interface
|
|
real=`ip -o link | grep <%= interface.inheriting_mac -%> | awk '{print $2;}' | sed s/:$//`
|
|
<% if virtual -%>
|
|
real=`echo <%= interface.identifier -%> | sed s/<%= interface.attached_to -%>/$real/`
|
|
<% end -%>
|
|
|
|
# ifcfg files are ignored by NM if their name contains colons so we convert colons to underscore
|
|
<% if alias_type -%>
|
|
sanitized_real=`echo $real | sed s/:/_/`
|
|
<% else -%>
|
|
sanitized_real=$real
|
|
<% end -%>
|
|
|
|
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$sanitized_real
|
|
BOOTPROTO="<%= dhcp ? 'dhcp' : 'none' -%>"
|
|
<% unless dhcp -%>
|
|
IPADDR="<%= interface.ip -%>"
|
|
NETMASK="<%= subnet.mask -%>"
|
|
<% if subnet.gateway.present? -%>
|
|
GATEWAY="<%= subnet.gateway %>"
|
|
<% end -%>
|
|
<% end -%>
|
|
DEVICE=$real
|
|
<% unless virtual -%>
|
|
HWADDR="<%= interface.mac -%>"
|
|
<% end -%>
|
|
ONBOOT=yes
|
|
<% if interface.respond_to?(:primary) && interface.primary -%>
|
|
PEERDNS=yes
|
|
PEERROUTES=yes
|
|
DEFROUTE=yes
|
|
<% if !dhcp && subnet.dns_primary.present? -%>
|
|
DNS1=<%= subnet.dns_primary %>
|
|
<% if subnet.dns_secondary.present? -%>
|
|
DNS2=<%= subnet.dns_secondary %>
|
|
<% end -%>
|
|
<% end -%>
|
|
<% else -%>
|
|
PEERDNS=no
|
|
PEERROUTES=no
|
|
DEFROUTE=no
|
|
<% end -%>
|
|
<% if @host.ip6.present? -%>
|
|
IPV6INIT=yes
|
|
IPV6_AUTOCONF=no
|
|
IPV6ADDR=<%= @host.ip6 %>
|
|
<% if subnet6.gateway.present? -%>
|
|
IPV6_DEFAULTGW=<%= subnet6.gateway %>
|
|
<% end -%>
|
|
IPV6_PEERDNS=no
|
|
<% end -%>
|
|
<% if vlan -%>
|
|
VLAN=yes
|
|
<% elsif alias_type -%>
|
|
TYPE=Alias
|
|
<% end -%>
|
|
EOF
|
|
|
|
<% end %>
|