Skip to content

Commit

Permalink
Merge branch 'master' into feature/#18850_add_internal_virtual_ips
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezborder committed Nov 29, 2024
2 parents 647375b + da255a6 commit 34b80d0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
cookbook-keepalived CHANGELOG
===============

## 0.2.1

- nilsver
- [f0f1604] track sync interface fix

## 0.2.0

- Miguel Negron
Expand Down
10 changes: 10 additions & 0 deletions resources/libraries/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module Keepalived
module Helper
require 'socket'

def interface_for_ip(ip_address)
return if ip_address.nil? || ip_address.empty?
interfaces = Socket.getifaddrs
interface = interfaces.find do |ifaddr|
ifaddr.addr.ipv4? && ifaddr.addr.ip_address == ip_address
end
interface.name
end
end
end
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
maintainer_email 'dvanhoucke@redborder.com'
license 'All rights reserved'
description 'Installs/Configures cookbook-keepalived'
version '0.2.0'
version '0.2.1'
18 changes: 17 additions & 1 deletion resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Provider:: config
#

include Keepalived::Helper

action :add do
begin
user = new_resource.user
Expand Down Expand Up @@ -101,7 +103,21 @@
mode '0644'
retries 2
notifies :reload, 'service[keepalived]'
variables(vrrp_password: vrrp_secrets['pass'], managers: managers, start_id: vrrp_secrets['start_id'], balanced_services: balanced_services, virtual_ips: virtual_ips, virtual_ips_per_ip: virtual_ips_per_ip, has_any_virtual_ip: has_any_virtual_ip, manager_services: manager_services, ipmgt: ipmgt, iface: iface, ipsync: ipaddress_sync, managers_per_service: managers_per_service)
variables(
vrrp_password: vrrp_secrets['pass'],
managers: managers,
start_id: vrrp_secrets['start_id'],
balanced_services: balanced_services,
virtual_ips: virtual_ips,
virtual_ips_per_ip: virtual_ips_per_ip,
has_any_virtual_ip: has_any_virtual_ip,
manager_services: manager_services,
ipmgt: ipmgt,
iface: iface,
ipsync: ipaddress_sync,
managers_per_service: managers_per_service,
sync_iface_name: interface_for_ip(ipaddress_sync)
)
end

ips_added = {}
Expand Down
4 changes: 4 additions & 0 deletions resources/templates/default/keepalived.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ vrrp_instance vi_<%= ip %> {
virtual_ipaddress {
<%= ip %>/32
}
track_interface {
<%= @sync_iface_name %>
}

<% webui_services = services.select{ |x| x['service']=='webui' } %>
<% if webui_services.count > 0 && webui_services.first['ip'] == ip %>
notify_master "/usr/lib/redborder/bin/rb_keepalived_master_notify_webui.sh"
Expand Down

0 comments on commit 34b80d0

Please sign in to comment.