diff --git a/resources/libraries/update_hosts_file.rb b/resources/libraries/update_hosts_file.rb index 315b857..44c37cb 100644 --- a/resources/libraries/update_hosts_file.rb +++ b/resources/libraries/update_hosts_file.rb @@ -1,18 +1,5 @@ module RbIps module Helpers - def load_rb_init_conf - @rb_init_conf ||= YAML.load_file('/etc/redborder/rb_init_conf.yml') - end - - def get_setup_ip - conf = load_rb_init_conf - if node['roles'].include?('ipscp-sensor') - conf['cloud_address'] - else - conf['webui_host'] - end - end - def get_external_databag_services Chef::DataBag.load('rBglobal').keys.grep(/^ipvirtual-external-/).map { |bag| bag.sub('ipvirtual-external-', '') } end @@ -30,7 +17,10 @@ def read_hosts_file end def update_hosts_file - setup_ip = get_setup_ip + manager_registration_ip = node['redborder']['manager_registration_ip'] if node['redborder'] && node['redborder']['manager_registration_ip'] + + return unless manager_registration_ip + running_services = node['redborder']['systemdservices'].values.flatten if node['redborder']['systemdservices'] databags = get_external_databag_services hosts_hash = read_hosts_file @@ -44,7 +34,7 @@ def update_hosts_file if ip && !ip.empty? grouped_virtual_ips[ip] << bag.gsub('ipvirtual-external-', '') else - grouped_virtual_ips[setup_ip] << bag.gsub('ipvirtual-external-', '') + grouped_virtual_ips[manager_registration_ip] << bag.gsub('ipvirtual-external-', '') end end @@ -68,12 +58,12 @@ def update_hosts_file end # If there is a virtual ip and ips is manager mode - if new_ip && !node['roles'].include?('ipscp-sensor') + if new_ip && !node['roles'].include?('ipscp-sensor') hosts_hash[new_ip] << "#{new_service}.service" hosts_hash[new_ip] << "#{new_service}.#{node['redborder']['cdomain']}" - else # Add services with setup_ip - hosts_hash[setup_ip] << "#{new_service}.service" - hosts_hash[setup_ip] << "#{new_service}.#{node['redborder']['cdomain']}" + else # Add services with manager_registration_ip + hosts_hash[manager_registration_ip] << "#{new_service}.service" + hosts_hash[manager_registration_ip] << "#{new_service}.#{node['redborder']['cdomain']}" end end end diff --git a/resources/recipes/system_health.rb b/resources/recipes/system_health.rb index beae4e3..f63f0fb 100644 --- a/resources/recipes/system_health.rb +++ b/resources/recipes/system_health.rb @@ -11,42 +11,42 @@ end # Add manager node ip addr to /etc/hosts -ruby_block 'update_hosts_file_if_needed' do - block do - def managerToIp(str) - ipv4_regex = /\A(\d{1,3}\.){3}\d{1,3}\z/ - ipv6_regex = /\A(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\z/ - dns_regex = /\A[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+\z/ - - return str if str =~ ipv4_regex || str =~ ipv6_regex - - if str =~ dns_regex - ip = `dig +short #{str}`.strip - return ip unless ip.empty? - end - end - - unless node['redborder']['cloud'] - # Read webui_host from the rb_init_conf.yml file - webui_host_command = "grep '^webui_host:' /etc/redborder/rb_init_conf.yml | awk '{print $2}'" - webui_host = managerToIp `#{webui_host_command}`.strip - - # Search for a node matching the webui_host IP address - matching_node_name = search(:node, "ipaddress:#{webui_host}").first&.name - - # Update /etc/hosts if a matching node is found - if matching_node_name - node_name_with_suffix = "#{matching_node_name}.node" - hosts_file = '/etc/hosts' - - unless ::File.readlines(hosts_file).grep(/#{Regexp.escape(node_name_with_suffix)}/).any? - ::File.open(hosts_file, 'a') { |file| file.puts "#{webui_host} #{node_name_with_suffix}" } - end - end - end - end - action :run -end +# ruby_block 'update_hosts_file_if_needed' do +# block do +# def managerToIp(str) +# ipv4_regex = /\A(\d{1,3}\.){3}\d{1,3}\z/ +# ipv6_regex = /\A(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\z/ +# dns_regex = /\A[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+\z/ +# +# return str if str =~ ipv4_regex || str =~ ipv6_regex +# +# if str =~ dns_regex +# ip = `dig +short #{str}`.strip +# return ip unless ip.empty? +# end +# end +# +# unless node['redborder']['cloud'] +# # Read webui_host from the rb_init_conf.yml file +# webui_host_command = "grep '^webui_host:' /etc/redborder/rb_init_conf.yml | awk '{print $2}'" +# webui_host = managerToIp `#{webui_host_command}`.strip +# +# # Search for a node matching the webui_host IP address +# matching_node_name = search(:node, "ipaddress:#{webui_host}").first&.name +# +# # Update /etc/hosts if a matching node is found +# if matching_node_name +# node_name_with_suffix = "#{matching_node_name}.node" +# hosts_file = '/etc/hosts' +# +# unless ::File.readlines(hosts_file).grep(/#{Regexp.escape(node_name_with_suffix)}/).any? +# ::File.open(hosts_file, 'a') { |file| file.puts "#{webui_host} #{node_name_with_suffix}" } +# end +# end +# end +# end +# action :run +# end # Check barnyard2 health ruby_block 'check_barnyard2_health' do