From 5bbc8be2d552b1044bfa93b0c8c1ff3806193a12 Mon Sep 17 00:00:00 2001 From: Matthew Oliver Date: Wed, 5 Dec 2018 15:56:14 +1100 Subject: [PATCH] IPv6: dhcp/provisioner: make ipv6 aware If the admin network is IPv6 setup the ISC DHCPD server to configure and use the IPv6 daemon. For this use a seperate set of ipv6 files to list hosts and subnets as ipv6 hosts and subnets will fail if v4 dhcp tries to load them. Also make sure tftp is listening on both IPv4 and v6. --- chef/cookbooks/dhcp/attributes/default.rb | 14 ++++- chef/cookbooks/dhcp/providers/host.rb | 22 ++++--- chef/cookbooks/dhcp/providers/subnet.rb | 23 ++++--- chef/cookbooks/dhcp/recipes/default.rb | 50 +++++++++++---- chef/cookbooks/dhcp/resources/host.rb | 1 + .../dhcp/templates/default/dhcpd.conf.erb | 28 +++++++++ .../dhcp/templates/default/host.conf.erb | 5 ++ .../dhcp/templates/default/subnet6.conf.erb | 19 ++++++ .../default/suse-sysconfig-dhcpd.erb | 1 + chef/cookbooks/provisioner/recipes/base.rb | 7 ++- .../provisioner/recipes/dhcp_update.rb | 63 +++++++++++++++---- .../provisioner/recipes/setup_base_images.rb | 26 +++++--- .../provisioner/recipes/update_nodes.rb | 3 + .../default/crowbar_join.suse.sh.erb | 22 +++++-- .../provisioner/templates/default/tftp.erb | 2 +- .../templates/suse/crowbar_register.erb | 16 ++++- 16 files changed, 245 insertions(+), 57 deletions(-) create mode 100644 chef/cookbooks/dhcp/templates/default/subnet6.conf.erb diff --git a/chef/cookbooks/dhcp/attributes/default.rb b/chef/cookbooks/dhcp/attributes/default.rb index d2ce1c50df..b657f21933 100644 --- a/chef/cookbooks/dhcp/attributes/default.rb +++ b/chef/cookbooks/dhcp/attributes/default.rb @@ -1,6 +1,6 @@ default[:dhcp][:interfaces] = ["eth0"] -default[:dhcp][:options] = [ +default[:dhcp][:options][:v4] = [ "ddns-update-style none", "allow booting", "option option-128 code 128 = string", @@ -10,4 +10,16 @@ "option dhcp-client-debug code 226 = unsigned integer 16", "option dhcp-client-debug 0" ] +default[:dhcp][:options][:v6] = [ + "ddns-update-style none", + "allow booting", + "option option-128 code 128 = string", + "option option-129 code 129 = text", + "option dhcp-client-state code 225 = unsigned integer 16", + "option dhcp-client-state 0", + "option dhcp-client-debug code 226 = unsigned integer 16", + "option dhcp-client-debug 0", + "option dhcp6.bootfile-url code 59 = string", + "option dhcp6.client-arch-type code 61 = array of unsigned integer 16" +] diff --git a/chef/cookbooks/dhcp/providers/host.rb b/chef/cookbooks/dhcp/providers/host.rb index 6a590d6206..d2cd7ebd00 100644 --- a/chef/cookbooks/dhcp/providers/host.rb +++ b/chef/cookbooks/dhcp/providers/host.rb @@ -13,8 +13,11 @@ # limitations under the License. # +require "ipaddr" + action :add do Chef::Log.debug "Adding #{new_resource.name}.conf to /etc/dhcp3/hosts.d" + is_ipv6 = IPAddr.new(new_resource.ipaddress).ipv6? filename = "/etc/dhcp3/hosts.d/#{new_resource.name}.conf" template filename do cookbook "dhcp" @@ -24,7 +27,9 @@ hostname: new_resource.hostname, macaddress: new_resource.macaddress, ipaddress: new_resource.ipaddress, - options: new_resource.options + options: new_resource.options, + prefix: new_resource.prefix, + is_ipv6: is_ipv6 ) owner "root" group "root" @@ -33,9 +38,10 @@ notifies :restart, resources(service: "dhcp3-server"), :delayed end end + host_list_file = is_ipv6 ? "host6_list.conf" : "host_list.conf" utils_line "include \"#{filename}\";" do action :add - file "/etc/dhcp3/hosts.d/host_list.conf" + file "/etc/dhcp3/hosts.d/#{host_list_file}" if node[:provisioner][:enable_pxe] notifies :restart, resources(service: "dhcp3-server"), :delayed end @@ -54,11 +60,13 @@ end new_resource.updated_by_last_action(true) end - utils_line "include \"#{filename}\";" do - action :remove - file "/etc/dhcp3/hosts.d/host_list.conf" - if node[:provisioner][:enable_pxe] - notifies :restart, resources(service: "dhcp3-server"), :delayed + ["host_list.conf", "host6_list.conf"].each do |host_list| + utils_line "include \"#{filename}\";" do + action :remove + file "/etc/dhcp3/hosts.d/#{host_list}" + if node[:provisioner][:enable_pxe] + notifies :restart, resources(service: "dhcp3-server"), :delayed + end end end end diff --git a/chef/cookbooks/dhcp/providers/subnet.rb b/chef/cookbooks/dhcp/providers/subnet.rb index f98823f437..3ddde0b02a 100644 --- a/chef/cookbooks/dhcp/providers/subnet.rb +++ b/chef/cookbooks/dhcp/providers/subnet.rb @@ -13,11 +13,18 @@ # limitations under the License. # +require "ipaddr" + action :add do + ip_version = if IPAddr.new(new_resource.network["subnet"]).ipv6? + "6" + else + "" + end filename = "/etc/dhcp3/subnets.d/#{new_resource.subnet}.conf" template filename do cookbook "dhcp" - source "subnet.conf.erb" + source "subnet#{ip_version}.conf.erb" variables( network: new_resource.network, options: new_resource.options, @@ -33,7 +40,7 @@ end utils_line "include \"#{filename}\";" do action :add - file "/etc/dhcp3/subnets.d/subnet_list.conf" + file "/etc/dhcp3/subnets.d/subnet#{ip_version}_list.conf" if node[:provisioner][:enable_pxe] notifies :restart, resources(service: "dhcp3-server"), :delayed end @@ -52,11 +59,13 @@ end new_resource.updated_by_last_action(true) end - utils_line "include \"#{filename}\";" do - action :remove - file "/etc/dhcp3/subnets.d/subnet_list.conf" - if node[:provisioner][:enable_pxe] - notifies :restart, resources(service: "dhcp3-server"), :delayed + ["subnet_list.conf", "subnet6_list.conf"].each do |subnet_list| + utils_line "include \"#{filename}\";" do + action :remove + file "/etc/dhcp3/subnets.d/#{subnet_list}" + if node[:provisioner][:enable_pxe] + notifies :restart, resources(service: "dhcp3-server"), :delayed + end end end end diff --git a/chef/cookbooks/dhcp/recipes/default.rb b/chef/cookbooks/dhcp/recipes/default.rb index 616fa3f2e5..97f136ca3f 100644 --- a/chef/cookbooks/dhcp/recipes/default.rb +++ b/chef/cookbooks/dhcp/recipes/default.rb @@ -48,6 +48,21 @@ group "root" mode 0644 end +file "/etc/dhcp3/groups.d/group6_list.conf" do + owner "root" + group "root" + mode 0644 +end +file "/etc/dhcp3/subnets.d/subnet6_list.conf" do + owner "root" + group "root" + mode 0644 +end +file "/etc/dhcp3/hosts.d/host6_list.conf" do + owner "root" + group "root" + mode 0644 +end bash "build omapi key" do code <<-EOH @@ -63,18 +78,27 @@ intfs = [Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").interface] address = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address -d_opts = node[:dhcp][:options] +require "ipaddr" +admin_addr = IPAddr.new(address) + +if admin_addr.ipv4? + d_opts = node[:dhcp][:options][:v4] + dhcpd_conf = "dhcpd.conf" +else + d_opts = node[:dhcp][:options][:v6] + dhcpd_conf = "dhcpd6.conf" +end case node[:platform_family] when "debian" case node[:lsb][:codename] when "natty","oneiric","precise" - template "/etc/dhcp/dhcpd.conf" do + template "/etc/dhcp/#{dhcpd_conf}" do owner "root" group "root" mode 0644 source "dhcpd.conf.erb" - variables(options: d_opts) + variables(options: d_opts, is_ipv6: admin_addr.ipv6?) if node[:provisioner][:enable_pxe] notifies :restart, "service[dhcp3-server]" end @@ -90,12 +114,12 @@ end end else - template "/etc/dhcp3/dhcpd.conf" do + template "/etc/dhcp3/#{dhcpd_conf}" do owner "root" group "root" mode 0644 source "dhcpd.conf.erb" - variables(options: d_opts) + variables(options: d_opts, is_ipv6: admin_addr.ipv6?) if node[:provisioner][:enable_pxe] notifies :restart, "service[dhcp3-server]" end @@ -115,9 +139,9 @@ dhcp_config_file = case when node[:platform_version].to_f >= 6 - "/etc/dhcp/dhcpd.conf" + "/etc/dhcp/#{dhcpd_conf}" else - "/etc/dhcpd.conf" + "/etc/#{dhcpd_conf}" end template dhcp_config_file do @@ -125,7 +149,7 @@ group "root" mode 0644 source "dhcpd.conf.erb" - variables(options: d_opts) + variables(options: d_opts, is_ipv6: admin_addr.ipv6?) if node[:provisioner][:enable_pxe] notifies :restart, "service[dhcp3-server]" end @@ -143,12 +167,12 @@ end when "suse" - template "/etc/dhcpd.conf" do + template "/etc/#{dhcpd_conf}" do owner "root" group "root" mode 0644 source "dhcpd.conf.erb" - variables(options: d_opts) + variables(options: d_opts, is_ipv6: admin_addr.ipv6?) if node[:provisioner][:enable_pxe] notifies :restart, "service[dhcp3-server]" end @@ -168,7 +192,11 @@ service "dhcp3-server" do if %w(suse rhel).include?(node[:platform_family]) - service_name "dhcpd" + if admin_addr.ipv4? + service_name "dhcpd" + else + service_name "dhcpd6" + end elsif node[:platform] == "ubuntu" case node[:lsb][:codename] when "maverick" diff --git a/chef/cookbooks/dhcp/resources/host.rb b/chef/cookbooks/dhcp/resources/host.rb index 0ef4f62f49..5223cec4f4 100644 --- a/chef/cookbooks/dhcp/resources/host.rb +++ b/chef/cookbooks/dhcp/resources/host.rb @@ -19,6 +19,7 @@ attribute :hostname, kind_of: String attribute :macaddress, kind_of: String attribute :ipaddress, kind_of: String +attribute :prefix, kind_of: String attribute :group, kind_of: String attribute :options, kind_of: Array, default: [] diff --git a/chef/cookbooks/dhcp/templates/default/dhcpd.conf.erb b/chef/cookbooks/dhcp/templates/default/dhcpd.conf.erb index 3bb3deb9bf..97f3c3ebd3 100644 --- a/chef/cookbooks/dhcp/templates/default/dhcpd.conf.erb +++ b/chef/cookbooks/dhcp/templates/default/dhcpd.conf.erb @@ -21,6 +21,34 @@ log-facility local7; # Fix for https://bugzilla.opensuse.org/show_bug.cgi?id=961536 always-reply-rfc1048 true; +<% if @is_ipv6 -%> +# Other options we may want? +#option dhcp6.rfc4833-tz-posix-string code 41 = string; +#option dhcp6.rfc4833-tz-name code 42 = string; +# +# Use example: +# option dhcp6.rfc4833-tz-posix-string "EST5EDT4,M3.2.0/02:00,M11.1.0/02:00"; +# option dhcp6.rfc4833-tz-name "Europe/Zurich"; +# Use this to send dhcp log messages to a different log file (you also +# have to hack syslog.conf to complete the redirection). + +# Set preference to 255 (maximum) in order to avoid waiting for +# additional servers when there is only one +##option dhcp6.preference 255; + +# Server side command to enable rapid-commit (2 packet exchange) +##option dhcp6.rapid-commit; + +# The delay before information-request refresh +# (minimum is 10 minutes, maximum one day, default is to not refresh) +# (set to 6 hours) +#option dhcp6.info-refresh-time 21600; + +include "/etc/dhcp3/groups.d/group6_list.conf"; +include "/etc/dhcp3/subnets.d/subnet6_list.conf"; +include "/etc/dhcp3/hosts.d/host6_list.conf"; +<% else -%> include "/etc/dhcp3/groups.d/group_list.conf"; include "/etc/dhcp3/subnets.d/subnet_list.conf"; include "/etc/dhcp3/hosts.d/host_list.conf"; +<% end -%> diff --git a/chef/cookbooks/dhcp/templates/default/host.conf.erb b/chef/cookbooks/dhcp/templates/default/host.conf.erb index f2f6917860..0462693df7 100644 --- a/chef/cookbooks/dhcp/templates/default/host.conf.erb +++ b/chef/cookbooks/dhcp/templates/default/host.conf.erb @@ -2,7 +2,12 @@ host <%= @name %> { option host-name "<%= @hostname %>"; hardware ethernet <%= @macaddress %>; <% if @ipaddress -%> +<% if @is_ipv6 -%> + fixed-address6 <%= @ipaddress %>; + fixed-prefix6 <%= @prefix %>; +<% else -%> fixed-address <%= @ipaddress %>; +<% end -%> <% else -%> deny booting; <% end -%> diff --git a/chef/cookbooks/dhcp/templates/default/subnet6.conf.erb b/chef/cookbooks/dhcp/templates/default/subnet6.conf.erb new file mode 100644 index 0000000000..d8af240f5e --- /dev/null +++ b/chef/cookbooks/dhcp/templates/default/subnet6.conf.erb @@ -0,0 +1,19 @@ +# File managed by Crowbar +<% if node[:provisioner][:enable_pxe] -%> + +subnet6 <%= @network["subnet"] %>/<%= @network["netmask"]%> { + option subnet-mask <%= @network["netmask"] %>; +<% @options.each do |option| -%> + <%= option %>; +<% end -%> +<% @pools.each do |pool| -%> + pool6 { + range6 <%=@network["ranges"][pool]["start"]%> <%=@network["ranges"][pool]["end"]%>; + <% @pool_options[pool].each do |opt| -%> + <%=opt%><%=if opt[-1,1] != '}' then ';' else '' end%> + <% end if @pool_options[pool] -%> + } +<% end -%> +} + +<% end -%> diff --git a/chef/cookbooks/dhcp/templates/default/suse-sysconfig-dhcpd.erb b/chef/cookbooks/dhcp/templates/default/suse-sysconfig-dhcpd.erb index 34d3605af4..6d17f1d354 100644 --- a/chef/cookbooks/dhcp/templates/default/suse-sysconfig-dhcpd.erb +++ b/chef/cookbooks/dhcp/templates/default/suse-sysconfig-dhcpd.erb @@ -2,6 +2,7 @@ # Do not edit. <% unless @interfaces.empty? -%> DHCPD_INTERFACE="<%= @interfaces.collect! {|i| "#{i}" }.join(" ") %>" +DHCPD6_INTERFACE="<%= @interfaces.collect! {|i| "#{i}" }.join(" ") %>" <% end -%> DHCPD_IFUP_RESTART="" DHCPD_RUN_CHROOTED="no" diff --git a/chef/cookbooks/provisioner/recipes/base.rb b/chef/cookbooks/provisioner/recipes/base.rb index 19252b6ef6..6e251a091e 100644 --- a/chef/cookbooks/provisioner/recipes/base.rb +++ b/chef/cookbooks/provisioner/recipes/base.rb @@ -346,10 +346,15 @@ mode "0644" end +require "ipaddr" crowbar_node = node_search_with_cache("roles:crowbar").first address = crowbar_node["crowbar"]["network"]["admin"]["address"] protocol = crowbar_node["crowbar"]["apache"]["ssl"] ? "https" : "http" -server = "#{protocol}://#{address}" +server = if IPAddr.new(address).ipv6? + "#{protocol}://[#{address}]" +else + "#{protocol}://#{address}" +end password = crowbar_node["crowbar"]["users"]["crowbar"]["password"] verify_ssl = !crowbar_node["crowbar"]["apache"]["insecure"] diff --git a/chef/cookbooks/provisioner/recipes/dhcp_update.rb b/chef/cookbooks/provisioner/recipes/dhcp_update.rb index 3a6e01ca19..48ee9cb1c6 100644 --- a/chef/cookbooks/provisioner/recipes/dhcp_update.rb +++ b/chef/cookbooks/provisioner/recipes/dhcp_update.rb @@ -8,16 +8,17 @@ admin_net = Barclamp::Inventory.get_network_definition(node, "admin") lease_time = node[:provisioner][:dhcp]["lease-time"] +admin6_uri = "tftp://[#{admin_ip}]/discovery" -pool_opts = { - "dhcp" => ["allow unknown-clients", - "default-lease-time #{lease_time}", - "max-lease-time #{lease_time}", - 'if exists dhcp-parameter-request-list { +ipv4_dhcp_opts = [ + "allow unknown-clients", + "default-lease-time #{lease_time}", + "max-lease-time #{lease_time}", + 'if exists dhcp-parameter-request-list { # Always send the PXELINUX options (specified in hexadecimal) option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list,d0,d1,d2,d3); }', - 'if option arch = 00:06 { + 'if option arch = 00:06 { filename = "discovery/ia32/efi/bootia32.efi"; } else if option arch = 00:07 { filename = "discovery/x86_64/efi/default/boot/bootx64.efi"; @@ -31,18 +32,56 @@ } else { filename = "discovery/x86_64/bios/pxelinux.0"; }', - "next-server #{admin_ip}"], + "next-server #{admin_ip}" +] + +ipv6_dhcp_opts = [ + "allow unknown-clients", + "default-lease-time #{lease_time}", + "max-lease-time #{lease_time}", + 'if exists dhcp-parameter-request-list { + # Always send the PXELINUX options (specified in hexadecimal) + option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list,d0,d1,d2,d3); + }', + "if option dhcp6.client-arch-type = 00:06 { + option dhcp6.bootfile-url \"#{admin6_uri}/ia32/efi/bootia32.efi\"; + } else if option dhcp6.client-arch-type = 00:07 { + option dhcp6.bootfile-url \"/#{admin6_uri}x86_64/efi/default/boot/bootx64.efi\"; + } else if option dhcp6.client-arch-type = 00:09 { + option dhcp6.bootfile-url \"#{admin6_uri}/x86_64/efi/default/boot/bootx64.efi\"; + } else if option dhcp6.client-arch-type = 00:0b { + option dhcp6.bootfile-url \"#{admin6_uri}/aarch64/efi/default/boot/bootaa64.efi\"; + } else if option dhcp6.client-arch-type = 00:0e { + option dhcp6.bootfile-url \"#{admin6_uri}/discovery/ppc64le/bios/\"; + } else { + option dhcp6.bootfile-url \"#{admin6_uri}/x86_64/bios/pxelinux.0\"; + }" +] + +pool_opts = { "host" => ["deny unknown-clients"] } +require "ipaddr" +if IPAddr.new(admin_net["subnet"]).ipv6? + pool_opts["dhcp"] = ipv6_dhcp_opts + subnet_options = [ + "option domain-name \"#{domain_name}\"", + "option dhcp6.name-servers #{dns_servers.join(", ")}" + ] +else + pool_opts["dhcp"] = ipv4_dhcp_opts + subnet_options = [ + "server-identifier #{admin_ip}", + "option domain-name \"#{domain_name}\"", + "option domain-name-servers #{dns_servers.join(", ")}" + ] +end + dhcp_subnet admin_net["subnet"] do action :add network admin_net pools ["dhcp","host"] pool_options pool_opts - options [ - "server-identifier #{admin_ip}", - "option domain-name \"#{domain_name}\"", - "option domain-name-servers #{dns_servers.join(", ")}" - ] + options subnet_options end diff --git a/chef/cookbooks/provisioner/recipes/setup_base_images.rb b/chef/cookbooks/provisioner/recipes/setup_base_images.rb index 490b417067..e8b9a0d485 100644 --- a/chef/cookbooks/provisioner/recipes/setup_base_images.rb +++ b/chef/cookbooks/provisioner/recipes/setup_base_images.rb @@ -14,15 +14,18 @@ # limitations under the License # +require "ipaddr" + dirty = false # Set up the OS images as well # Common to all OSes admin_net = Barclamp::Inventory.get_network_by_type(node, "admin") -admin_ip = admin_net.address +admin_ip = IPAddr.new(admin_net.address) domain_name = node[:dns].nil? ? node[:domain] : (node[:dns][:domain] || node[:domain]) web_port = node[:provisioner][:web_port] -provisioner_web="http://#{admin_ip}:#{web_port}" +provisioner_web="http://#{admin_ip}:#{web_port}" if admin_ip.ipv4? +provisioner_web="http://[#{admin_ip}]:#{web_port}" if admin_ip.ipv6? append_line = node[:provisioner][:discovery][:append].dup # We'll modify it inline crowbar_node = node_search_with_cache("roles:crowbar").first @@ -157,7 +160,7 @@ source "grub.conf.erb" variables(append_line: "#{append_line} crowbar.state=discovery", install_name: "Crowbar Discovery Image", - admin_ip: admin_ip, + admin_ip: admin_ip.to_s, efi_suffix: arch == "x86_64", initrd: "discovery/#{arch}/initrd0.img", kernel: "discovery/#{arch}/vmlinuz0") @@ -182,7 +185,7 @@ mode 0o644 variables(docroot: tftproot, port: web_port, - admin_ip: admin_ip, + admin_ip: admin_ip.to_s, admin_subnet: admin_net.subnet, admin_netmask: admin_net.netmask, logfile: "/var/log/apache2/provisioner-access_log", @@ -298,12 +301,13 @@ notifies :reload, resources(service: "xinetd") end else + ip_addr = admin_ip.ipv6? ? "[#{admin_ip}]" : admin_ip.to_s template "/etc/systemd/system/tftp.service" do source "tftp.service.erb" owner "root" group "root" mode "0644" - variables(tftproot: tftproot, admin_ip: admin_ip) + variables(tftproot: tftproot, admin_ip: ip_addr) end service "tftp.service" do @@ -388,7 +392,7 @@ mode "0644" source "set_state.ps1.erb" variables(crowbar_key: crowbar_key, - admin_ip: admin_ip) + admin_ip: admin_ip.to_s) end # Also copy the required files to install chef-client and communicate with Crowbar @@ -507,11 +511,12 @@ owner "root" group "root" source "crowbar_join.suse.sh.erb" - variables(admin_ip: admin_ip, + variables(admin_ip: admin_ip.to_s, web_port: web_port, ntp_servers_ips: ntp_servers, platform: target_platform_distro, - target_platform_version: target_platform_version) + target_platform_version: target_platform_version, + is_ipv6: admin_ip.ipv6?) end repos = Provisioner::Repositories.get_repos(target_platform_distro, @@ -525,7 +530,7 @@ owner "root" group "root" source "crowbar_register.erb" - variables(admin_ip: admin_ip, + variables(admin_ip: admin_ip.to_s, admin_broadcast: admin_net.broadcast, crowbar_protocol: crowbar_protocol, crowbar_verify_ssl: crowbar_verify_ssl, @@ -538,7 +543,8 @@ repos: repos, packages: packages, platform: target_platform_distro, - target_platform_version: target_platform_version) + target_platform_version: target_platform_version, + is_ipv6: admin_ip.ipv6?) end missing_files = !File.exist?("#{os_dir}/install/boot/#{arch}/common") diff --git a/chef/cookbooks/provisioner/recipes/update_nodes.rb b/chef/cookbooks/provisioner/recipes/update_nodes.rb index ae40ff805b..2f07064770 100644 --- a/chef/cookbooks/provisioner/recipes/update_nodes.rb +++ b/chef/cookbooks/provisioner/recipes/update_nodes.rb @@ -149,6 +149,7 @@ def find_node_boot_mac_addresses(node, admin_data_net) admin_data_net = Chef::Recipe::Barclamp::Inventory.get_network_by_type(mnode, "admin") admin_mac_addresses = find_node_boot_mac_addresses(mnode, admin_data_net) admin_ip_address = admin_data_net.nil? ? mnode[:ipaddress] : admin_data_net.address + admin_prefix = admin_data_net.nil? ? "" : "#{admin_data_net.subnet}/#{admin_data_net.netmask}" #### # First deal with states that don't require PXE booting @@ -178,6 +179,7 @@ def find_node_boot_mac_addresses(node, admin_data_net) hostname mnode.name if admin_mac_addresses.include?(mac_list[i]) ipaddress admin_ip_address + prefix admin_prefix end macaddress mac_list[i] action :add @@ -244,6 +246,7 @@ def find_node_boot_mac_addresses(node, admin_data_net) }", "next-server #{admin_ip}" ] + prefix admin_prefix end action :add end diff --git a/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb index 1a232323a7..8303071437 100644 --- a/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb +++ b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb @@ -114,7 +114,11 @@ wait_for_hostname() { wait_for_admin_server() { # wait for admin server to become pingable tries_left=120 - while ! ping -q -c1 $IP > /dev/null; do + local ping="ping" + if (( $IPV6 > 0 )); then + ping="ping6" + fi + while ! $ping -q -c1 $IP > /dev/null; do tries_left=$(($tries_left-1)) if [ $tries_left -eq 0 ]; then return 1 @@ -163,9 +167,9 @@ do_setup() { # Make sure that the client knows how to talk to the server. local cfg=/etc/chef/client.rb if ! [ -f $cfg ] || \ - ! grep -q "^\s*chef_server_url\s*[\"\']http://$IP:4000[\"\']" $cfg; then + ! grep -q "^\s*chef_server_url\s*[\"\']http://$IP_WRAPPED:4000[\"\']" $cfg; then test -f $cfg && mv $cfg $cfg.bak - echo "chef_server_url \"http://$IP:4000\"" >$cfg + echo "chef_server_url \"http://$IP_WRAPPED:4000\"" >$cfg echo "zypper_check_gpg true" >> $cfg fi @@ -398,7 +402,17 @@ EXVAL=0 export HOME=/root IP="<%= @admin_ip %>" -HTTP_SERVER="<%= @admin_ip %>:<%= @web_port %>" +<% if @is_ipv6 -%> +IPV6=1 +<% else -%> +IPV6=0 +<% end -%> +if (( $IPV6 > 0 )); then + IP_WRAPPED="[$IP]" +else + IP_WRAPPED="$IP" +fi +HTTP_SERVER="$IP_WRAPPED:<%= @web_port %>" NTP_SERVERS="<%= @ntp_servers_ips.join(" ") %>" VALID_NTP_SERVERS="" diff --git a/chef/cookbooks/provisioner/templates/default/tftp.erb b/chef/cookbooks/provisioner/templates/default/tftp.erb index ba53690d62..97c72cf718 100644 --- a/chef/cookbooks/provisioner/templates/default/tftp.erb +++ b/chef/cookbooks/provisioner/templates/default/tftp.erb @@ -8,7 +8,7 @@ service tftp socket_type = dgram protocol = udp wait = yes - flags = IPv4 + flags = IPv6 IPv4 user = root server = /usr/sbin/in.tftpd server_args = -m /etc/tftpd.conf -s <%=@tftproot%> diff --git a/chef/cookbooks/provisioner/templates/suse/crowbar_register.erb b/chef/cookbooks/provisioner/templates/suse/crowbar_register.erb index b538e7f78d..8e525f1d73 100644 --- a/chef/cookbooks/provisioner/templates/suse/crowbar_register.erb +++ b/chef/cookbooks/provisioner/templates/suse/crowbar_register.erb @@ -122,7 +122,17 @@ add_user() { ADMIN_IP="<%= @admin_ip %>" ADMIN_BROADCAST="<%= @admin_broadcast %>" WEB_PORT="<%= @web_port %>" -HTTP_SERVER="http://${ADMIN_IP}:${WEB_PORT}" +<% if @is_ipv6 -%> +IPV6=1 +<% else -%> +IPV6=0 +<% end -%> +if (( $IPV6 > 0 )); then + ADMIN_IP_WRAPPED="[ADMIN_IP]" +else + ADMIN_IP_WRAPPED="ADMIN_IP" +fi +HTTP_SERVER="http://${ADMIN_IP_WRAPPED}:${WEB_PORT}" CROWBAR_OS="<%= @os %>" CROWBAR_ARCH="<%= @arch %>" CROWBAR_KEY="<%= @crowbar_key %>" @@ -381,7 +391,7 @@ TMP_ATTRIBUTES=$(mktemp --suffix .json) echo "{ \"target_platform\": \"$CROWBAR_OS\", \"crowbar_wall\": { \"registering\": true } }" > "$TMP_ATTRIBUTES" crowbarctl node transition $HOSTNAME "discovering" -chef-client -S http://$ADMIN_IP:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES" +chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES" crowbarctl node transition $HOSTNAME "discovered" # TODO need to find way of knowing that chef run is over on server side sleep 30 @@ -393,7 +403,7 @@ echo '{ "crowbar_wall": { "registering": true } }' > "$TMP_ATTRIBUTES" rm -f /etc/chef/client.pem crowbarctl node transition $HOSTNAME "hardware-installing" -chef-client -S http://$ADMIN_IP:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES" +chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES" crowbarctl node transition $HOSTNAME "hardware-installed" #TODO #wait_for_pxe_state ".*_install"