Skip to content

Commit

Permalink
Realize exported Vrrp:Script resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jconroy77 committed Oct 8, 2016
1 parent 1758f64 commit 80730e1
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 90 deletions.
23 changes: 21 additions & 2 deletions manifests/vrrp/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@
# $vmac_xmit_base When using virtual MAC addresses transmit and receive
# VRRP messaged on the underlying interface whilst ARP
# will happen from the the VMAC interface.
#
# $collect_exported Boolean. Automatically collect exported
# @@keepalived::vrrp::script with a vrrp_instance equal
# to the name/title of this resource. This allows you to
# easily export a script resource on each node in the
# pool. Defaults to false, set to true to collect
# exported scripts.

define keepalived::vrrp::instance (
$interface,
Expand Down Expand Up @@ -174,7 +181,7 @@
$dont_track_primary = false,
$use_vmac = false,
$vmac_xmit_base = true,

$collect_exported = false,
) {
$_name = regsubst($name, '[:\/\n]', '')

Expand All @@ -185,10 +192,22 @@
fail('virtual_router_id must be an integer >= 1 and <= 255')
}

validate_bool($collect_exported)

concat::fragment { "keepalived.conf_vrrp_instance_${_name}":
target => "${::keepalived::config_dir}/keepalived.conf",
content => template('keepalived/vrrp_instance.erb'),
order => '100',
order => "100-${_name}-000",
}

concat::fragment { "keepalived.conf_vrrp_instance_${_name}-footer":
target => "${::keepalived::config_dir}/keepalived.conf",
content => template('keepalived/vrrp_instance-footer.erb'),
order => "100-${_name}-zzz",
}

if $collect_exported {
Keepalived::Vrrp::Script <<| vrrp_instance == $_name |>>
}
}

31 changes: 23 additions & 8 deletions manifests/vrrp/script.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@
# $timeout:: max time to wait for the vrrp script to return.
# Default: undef
#
# $vrrp_instance::
# The name of the vrrp_instance this script will be
# added to if collect_exported is enabled for it
# Default: undef

define keepalived::vrrp::script (
$interval = '2',
$script = undef,
$weight = undef,
$fall = undef,
$rise = undef,
$timeout = undef,
$no_weight = false,
$interval = '2',
$script = undef,
$weight = undef,
$fall = undef,
$rise = undef,
$timeout = undef,
$no_weight = false,
$vrrp_instance = undef,
) {
$_name = regsubst($name, '[:\/\n]', '')

Expand All @@ -50,7 +56,16 @@
concat::fragment { "keepalived.conf_vrrp_script_${_name}":
target => "${::keepalived::config_dir}/keepalived.conf",
content => template('keepalived/vrrp_script.erb'),
order => '002',
order => "002-${_name}",
}

if $vrrp_instance {
$_vrrp_instance = regsubst($vrrp_instance, '[:\/\n]', '')
concat::fragment { "keepalived.conf_vrrp_script_${_vrrp_instance}_${_name}":
target => "${::keepalived::config_dir}/keepalived.conf",
content => " ${_name}\n",
order => "100-${_vrrp_instance}-${_name}",
}
}
}

81 changes: 81 additions & 0 deletions templates/vrrp_instance-footer.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<%- if @track_script or @collect_exported -%>
}
<%- end -%>

<%- if @track_interface -%>
track_interface {
<%- Array(@track_interface).each do |interface| -%>
<%= interface %>
<%- end -%>
}
<%- end -%>

<%- if @virtual_ipaddress -%>
virtual_ipaddress {
<%- if @virtual_ipaddress.class == Hash -%>
<%- vips = [ @virtual_ipaddress ] -%>
<%- else -%>
<%- vips = @virtual_ipaddress -%>
<%- end -%>
<%- Array(vips).each do |ip| -%>
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%= ip['ip'] %> dev <%= device %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>
<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
}
<%- end -%>

<%- if @virtual_ipaddress_excluded -%>
virtual_ipaddress_excluded {
<%- if @virtual_ipaddress_excluded.class == Hash -%>
<%- vips = [ @virtual_ipaddress_excluded ] -%>
<%- else -%>
<%- vips = @virtual_ipaddress_excluded -%>
<%- end -%>
<%- vips.each do |ip| -%>
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%= ip['ip'] %> dev <%= device %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>

<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
}
<%- end -%>

<%- if @virtual_routes -%>
virtual_routes {
<%- if @virtual_routes.class == Hash -%>
<%- vroutes = [ @virtual_routes ] -%>
<%- else -%>
<%- vroutes = @virtual_routes -%>
<%- end -%>
<%- vroutes.each do |route| -%>
<%- attrs = Hash[ route.select { |k,v| ['src', 'to', 'via', 'dev', 'scope'].include? k } ] -%>
<%= route['route'] %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>
<%- end -%>
}
<%- end -%>

<%- if @multicast_source_ip -%>
mcast_src_ip <%= @multicast_source_ip %>
<%- end -%>
<%- if @unicast_source_ip -%>
unicast_src_ip <%= @unicast_source_ip %>
<%- end -%>

<%- if @unicast_peers -%>
unicast_peer {
<%- @unicast_peers.each do |peer| -%>
<%= peer %>
<%- end -%>
}
<%- end -%>

}
81 changes: 1 addition & 80 deletions templates/vrrp_instance.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,89 +77,10 @@ vrrp_instance <%= @_name %> {
auth_pass <%= @auth_pass %>
}
<%- end -%>
<%- if @track_script -%>
<%- if @track_script or @collect_exported -%>

track_script {
<%- Array(@track_script).each do |track| -%>
<%= track %>
<%- end -%>
}
<%- end -%>

<%- if @track_interface -%>
track_interface {
<%- Array(@track_interface).each do |interface| -%>
<%= interface %>
<%- end -%>
}
<%- end -%>

<%- if @virtual_ipaddress -%>
virtual_ipaddress {
<%- if @virtual_ipaddress.class == Hash -%>
<%- vips = [ @virtual_ipaddress ] -%>
<%- else -%>
<%- vips = @virtual_ipaddress -%>
<%- end -%>
<%- Array(vips).each do |ip| -%>
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%= ip['ip'] %> dev <%= device %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>
<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
}
<%- end -%>

<%- if @virtual_ipaddress_excluded -%>
virtual_ipaddress_excluded {
<%- if @virtual_ipaddress_excluded.class == Hash -%>
<%- vips = [ @virtual_ipaddress_excluded ] -%>
<%- else -%>
<%- vips = @virtual_ipaddress_excluded -%>
<%- end -%>
<%- vips.each do |ip| -%>
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%= ip['ip'] %> dev <%= device %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>

<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
}
<%- end -%>

<%- if @virtual_routes -%>
virtual_routes {
<%- if @virtual_routes.class == Hash -%>
<%- vroutes = [ @virtual_routes ] -%>
<%- else -%>
<%- vroutes = @virtual_routes -%>
<%- end -%>
<%- vroutes.each do |route| -%>
<%- attrs = Hash[ route.select { |k,v| ['src', 'to', 'via', 'dev', 'scope'].include? k } ] -%>
<%= route['route'] %> <%= attrs.sort_by{ |k,v| k }.entries.join ' ' %>
<%- end -%>
}
<%- end -%>

<%- if @multicast_source_ip -%>
mcast_src_ip <%= @multicast_source_ip %>
<%- end -%>
<%- if @unicast_source_ip -%>
unicast_src_ip <%= @unicast_source_ip %>
<%- end -%>

<%- if @unicast_peers -%>
unicast_peer {
<%- @unicast_peers.each do |peer| -%>
<%= peer %>
<%- end -%>
}
<%- end -%>

}

0 comments on commit 80730e1

Please sign in to comment.