Skip to content

Commit

Permalink
fix duplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsver committed Oct 7, 2024
1 parent 3ee8cc4 commit 4ec2a52
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resources/libraries/update_hosts_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ def update_hosts_file

# Add running services to localhost
grouped_virtual_ips['127.0.0.1'] ||= []
running_services.each { |serv| grouped_virtual_ips['127.0.0.1'] << "#{serv}.service" }
running_services.each { |serv| grouped_virtual_ips['127.0.0.1'] << serv }

# Group services
grouped_virtual_ips.each do |new_ip, new_services|
new_services.each do |new_service|
# Remove suffix and get services
# Avoids having duplicate services in the list
service_key = new_service.split('.').first
hosts_hash.each { |_ip, services| services.delete_if { |service| service.split('.').first == service_key } }
hosts_hash.each do |_ip, services|
services_before = services.dup
services.delete_if { |service| service.split('.').first == service_key }
end

# Add running services to localhost
if running_services.include?(new_service)
if new_ip == '127.0.0.1' && running_services.include?(new_service)
hosts_hash['127.0.0.1'] << "#{new_service}.service"
next
end
Expand All @@ -92,3 +95,8 @@ def update_hosts_file
end
end
end


# 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
# ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# 10.1.202.214 data.redborder.cluster rbips-18.node erchef.redborder.cluster rbookshelf.s3.redborder.cluster redborder.cluster s3.service erchef.service http2k.service rb-nils.node f2k.service f2k.redborder.cluster kafka.service kafka.redborder.cluster sfacctd.service sfacctd.redborder.cluster webui.service webui.redborder.cluster

0 comments on commit 4ec2a52

Please sign in to comment.