Skip to content

Commit

Permalink
If there is more than two nodes /etc/hosts remains condition added
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezborder committed Oct 9, 2024
1 parent af1d75c commit 22c7e7b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@
data_bag_response = `knife data bag show rBglobal ipvirtual-internal-postgresql 2>/dev/null`
virtual_ip_present = (data_bag_response.include?('id') && !data_bag_response.include?('id: null')) ? true : false

# If PostgreSQL is registered in Consul and no virtual IP is set, remove postgresql from /etc/hosts
if postgresql_registered && !virtual_ip_present
# Get the list of alive server members from Serf
alive_server_members = `serf members -format=json -status=alive`
postgresql_nodes = JSON.parse(alive_server_members) unless alive_server_members.strip.empty?

# If all conditions are met /etc/hosts remains
if postgresql_registered && virtual_ip_present && postgresql_nodes && postgresql_nodes['members'].size > 1
Chef::Log.info('Conditions met, keeping master.postgresql.service in /etc/hosts')
else
execute 'Removing postgresql service from /etc/hosts' do
command "sed -i 's/.*postgresql.*//g' /etc/hosts"
end
Expand Down

0 comments on commit 22c7e7b

Please sign in to comment.