diff --git a/libraries/manipulator.rb b/libraries/manipulator.rb index a51d9b1d..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 @@ -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. @@ -244,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