From 7201461f5f66f53ab9467c31c8eaa47cc41ef1d4 Mon Sep 17 00:00:00 2001 From: Doug Kerwin Date: Fri, 10 Feb 2017 11:32:35 -0500 Subject: [PATCH 1/2] added support for CRLF on windows to avoid max aliases per line issue --- libraries/manipulator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/manipulator.rb b/libraries/manipulator.rb index a51d9b1d..64d7e086 100644 --- a/libraries/manipulator.rb +++ b/libraries/manipulator.rb @@ -217,7 +217,14 @@ def new_content entries = hostsfile_header entries += unique_entries.map(&:to_line) entries << '' - entries.join("\n") + # windows has a limit of 9 host aliases per line, so without proper line + # endings, additional host entries wind up being ignored + case node['platform_family'] + when 'windows' + entries.join("\r\n") + else + entries.join("\n") + end end # The current sha of the system hostsfile. From 10f8b235dcf3ba40e199973774d9888891b4a9d1 Mon Sep 17 00:00:00 2001 From: Doug Kerwin Date: Fri, 10 Feb 2017 17:07:18 -0500 Subject: [PATCH 2/2] change to avoid flattening hosts/aliases onto one line for windows --- libraries/manipulator.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/manipulator.rb b/libraries/manipulator.rb index 64d7e086..aef9f41e 100644 --- a/libraries/manipulator.rb +++ b/libraries/manipulator.rb @@ -102,7 +102,7 @@ def update(options = {}) # # @param (see #add) def append(options = {}) - if entry = find_entry_by_ip_address(options[:ip_address]) + if entry = not(node['platform_family'] == 'windows') && find_entry_by_ip_address(options[:ip_address]) hosts = normalize(entry.hostname, entry.aliases, options[:hostname], options[:aliases]) entry.hostname = hosts.shift entry.aliases = hosts @@ -251,7 +251,8 @@ def normalize(*things) # @return [Array] # the sorted list of entires that are unique def unique_entries - entries = Hash[*@entries.map { |entry| [entry.ip_address, entry] }.flatten].values + is_windows = node['platform_family'] == 'windows' + entries = Hash[*@entries.map { |entry| [is_windows ? entry.hostname : entry.ip_address, entry] }.flatten].values entries.sort_by { |e| [-e.priority.to_i, e.hostname.to_s] } end