Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.0.0 #47

Merged
merged 12 commits into from
Oct 8, 2024
89 changes: 89 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,95 @@
cookbook-rb-ips CHANGELOG
===============

## 1.0.0

- Miguel Negrón
- [2a1fa2d] Merge pull request #46 from redBorder/bugfix/18716_remove_sync_ip_from_hosts_file
- [176323b] Merge pull request #44 from redBorder/development
- [0b0e324] Merge pull request #42 from redBorder/development
- [215b2b1] Merge pull request #34 from redBorder/development
- [81600e3] Improvement/fix lint (#33)
- [a6be77f] Merge pull request #32 from redBorder/development
- Miguel Negron
- [e1b75f2] Pass lint
- [e3047de] Change the way to check if cloud
- [34179ba] Add comment to system health
- [6ff442c] Update update hosts
- [b4a2579] use role instead of reading yml file to know if proxy mode or manager mode
- [b4735d1] Bump version
- [1766bbe] Change configuration call for GeoIP
- nilsver
- [81a43e9] fix lint 2.0
- [6032735] fix lint
- [4ec2a52] fix duplication bug
- [3ee8cc4] fix lint
- [79f2a23] update hosts file
- [5e106a1] Release 0.6.0
- [488fa13] Merge pull request #39 from redBorder/feature/18019_add_chronyd_cookbook
- [6657481] update format
- [d4643f5] fix linter 1.1
- [40ee6c8] fix linter
- [786c54e] update hosts file
- Luis Blanco
- [a932601] update changelog migrate view raw
- [837ba65] Merge pull request #43 from redBorder/feature/#18237_Add_View_Raw_functionality_in_IPS
- [9630389] add clean operation in makefile
- [b0adaa8] Merge branch 'master' into feature/#18237_Add_View_Raw_functionality_in_IPS
- [68de4a6] update metadata
- [4e0ebd2] Merge pull request #38 from redBorder/feature/17731_ips_ssh_version
- [ac6f35a] Update system_health.rb
- [e73d75f] Revert "remove redBorder user because is legacy"
- [48fbb78] Revert "remove redBorder user because is legacy"
- [5c3739c] remove redBorder user because is legacy
- [a26f1c1] remove redBorder user because is legacy
- [e8b73c3] Merge remote-tracking branch 'origin/master' into feature/17731_ips_ssh_version
- [ec02f58] Merge pull request #37 from redBorder/development
- JPeraltaNic
- [196a877] Release 0.7.0
- [45fe633] Merge pull request #41 from redBorder/feature/18393_update_hosts_file
- [59adf2f] Merge branch 'master' into feature/18393_update_hosts_file
- [e03ca54] Merge branch 'master' into feature/#18237_Add_View_Raw_functionality_in_IPS
- jnavarrorb
- [df69047] MergeFromMaster. Fix user template
- [d834784] Merge branch 'master' into feature/#18237_Add_View_Raw_functionality_in_IPS
- [2289d8e] Change user to redborder for NG. Fix template folders
- [d9c6a39] Change user to redborder for NG. Fix template
- [5eff8fd] Change user to redborder for NG
- Miguel Álvarez
- [4344eeb] Merge pull request #40 from redBorder/development
- [28f7dcc] Update metadata.rb
- [4c6bd59] Update CHANGELOG.md
- [99100a4] Update configure.rb
- [8db18ec] Update default.rb
- [8bb737e] Update system_health.rb
- [76a3d79] Update metadata.rb
- [8c34884] Merge branch 'development' into feature/add_clamav
- Miguel Alvarez
- [d466315] Add chronyd
- [35d2ee2] fix lint issues
- [8ff38e9] Fix sys health
- [5672755] Fix lint
- [6d1f480] Fix motd when ssh version
- [3b39cfa] Only create ssh user if not cloud registration
- [fabdd03] Add rsa pub key
- [01a3935] Configure redBorder user
- [5832c9a] Fix services
- [38ca49a] Fix merge conflicts
- [b5c40f8] Add clamAV
- Juan Soto
- [3a862b1] Update CHANGELOG.md
- [faebefc] Update CHANGELOG.md
- [942281b] Merge pull request #36 from redBorder/feature/add_clamav
- [e7be16c] Merge pull request #35 from redBorder/feature/#17747_rb_exporter
- JuanSheba
- [f4f19ce] Release 0.4.0
- [deddb46] Release 0.4.0
- David Vanhoucke
- [2bdb85f] fix lint
- [0c5d6f6] add exporter service to ips
- vimesa
- [e8b26a4] Release 0.3.3

## 0.7.1

- Luis J Blanco Mier
Expand Down
71 changes: 42 additions & 29 deletions resources/libraries/update_hosts_file.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,69 @@
module RbIps
module Helpers
def update_hosts_file
managers = get_managers_all()
manager_ip = []
managers.each do |m|
manager_ip << m['ipaddress_sync']
def get_external_databag_services
Chef::DataBag.load('rBglobal').keys.grep(/^ipvirtual-external-/).map { |bag| bag.sub('ipvirtual-external-', '') }
end

def read_hosts_file
hosts_hash = Hash.new { |hash, key| hash[key] = [] }
File.readlines('/etc/hosts').each do |line|
next if line.strip.empty? || line.start_with?('#')
values = line.split(/\s+/)
ip = values.shift
services = values
hosts_hash[ip].concat(services).uniq!
end
hosts_hash
end

def update_hosts_file
manager_registration_ip = node['redborder']['manager_registration_ip'] if node['redborder'] && node['redborder']['manager_registration_ip']

return unless manager_registration_ip

# grouped_virtual_ips returns a hash where:
# - The keys are IP addresses from the data bags, or `nil` if an IP is missing.
# - The values are arrays of services associated with each IP address.
# - If an IP is missing from a data bag, the associated services are grouped under the sync_ip key.
running_services = node['redborder']['systemdservices'].values.flatten if node['redborder']['systemdservices']
databags = get_external_databag_services
hosts_hash = read_hosts_file

# Hash where services (from databag) are grouped by ip
grouped_virtual_ips = Hash.new { |hash, key| hash[key] = [] }
databags = Chef::DataBag.load('rBglobal').keys
databags.each do |bag|
next unless bag.start_with?('ipvirtual-external')
virtual_dg = data_bag_item('rBglobal', bag)
virtual_dg = data_bag_item('rBglobal', "ipvirtual-external-#{bag}")
ip = virtual_dg['ip']

if ip && !ip.empty?
grouped_virtual_ips[ip] << bag.gsub('ipvirtual-external-', '')
else
grouped_virtual_ips[manager_ip[0]] << bag.gsub('ipvirtual-external-', '')
grouped_virtual_ips[manager_registration_ip] << bag.gsub('ipvirtual-external-', '')
end
end

# Read hosts file and store in hash
hosts_hash = Hash.new { |hash, key| hash[key] = [] }
File.readlines('/etc/hosts').each do |line|
next if line.strip.empty? || line.start_with?('#')
values = line.split(/\s+/)
ip = values.shift
services = values
hosts_hash[ip].concat(services).uniq!
end
# Add running services to localhost
grouped_virtual_ips['127.0.0.1'] ||= []
running_services.each { |serv| grouped_virtual_ips['127.0.0.1'] << serv }

# Update hosts_hash based on grouped_virtual_ips
# Group services
grouped_virtual_ips.each do |new_ip, new_services|
new_services.each do |new_service|
# Avoids having duplicate services in the list
service_key = new_service.split('.').first

hosts_hash.each do |_ip, services|
services.delete_if { |service| service.split('.').first == service_key }
end

if new_ip
# Add running services to localhost
if new_ip == '127.0.0.1' && running_services.include?(new_service)
hosts_hash['127.0.0.1'] << "#{new_service}.service"
next
end

# If there is a virtual ip and ips is manager mode
if new_ip && !node['redborder']['cloud']
hosts_hash[new_ip] << "#{new_service}.service"
hosts_hash[new_ip] << "#{new_service}.#{node['redborder']['cdomain']}"
else
hosts_hash[manager_ip[0]] << "#{new_service}.service"
hosts_hash[manager_ip[0]] << "#{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
Expand All @@ -60,7 +74,6 @@ def update_hosts_file
format_entry = format('%-18s%s', ip, services.join(' '))
hosts_entries << format_entry unless services.empty?
end

hosts_entries
end
end
Expand Down
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
maintainer_email '[email protected]'
license 'AGPL-3.0'
description 'Installs/Configures redborder ips'
version '0.7.1'
version '1.0.0'

depends 'rb-common'
depends 'geoip'
Expand Down
4 changes: 4 additions & 0 deletions resources/recipes/system_health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
end

# Add manager node ip addr to /etc/hosts
# We need this for the kafka problem
# Is replaying with manager.domain and
# The ips need to be able to resolv this
# TODO: rework this part
ruby_block 'update_hosts_file_if_needed' do
block do
def managerToIp(str)
Expand Down
Loading