Skip to content

Commit

Permalink
fixing condition and virtual_ip_present
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezborder committed Oct 9, 2024
1 parent 22c7e7b commit caa8dfa
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,14 @@

# Check if the virtual IP field exists in the data bag
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
virtual_ip_present = (data_bag_response.include?('ip:')) ? true : false

# 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
# If all conditions are met /etc/hosts will be removed
if postgresql_registered && !virtual_ip_present && postgresql_nodes['members'].size == 1
execute 'Removing postgresql service from /etc/hosts' do
command "sed -i 's/.*postgresql.*//g' /etc/hosts"
end
Expand Down

0 comments on commit caa8dfa

Please sign in to comment.