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

Added support for track_scripts to the template #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Install, enable and configure the keepalived VRRP and LVS management daemon.

The configuration file to be used can be specificed using either the `$content`
parameter (typically for templates), or the `$source` parameter. If neither is
specified, you will need to manage it rom elsewhere.
specified, you will need to manage it from elsewhere.

See the `templates/sysconfig.erb` file for the possible `$options` values. The
default is `-D` which enables both VRRP and LVS.
Expand Down Expand Up @@ -68,6 +68,53 @@ class { '::keepalived::vrrp':
},
}
```
The same but using track_script :
```puppet
case $::hostname {
'web1': { $vrrp_state = 'MASTER' $vrrp_priority = '50' }
default: { $vrrp_state = 'BACKUP' $vrrp_priority = '10' }
}
class { '::keepalived::vrrp':
global_defs => {
router_id => $::hostname,
debug_script => 'all',
},
instances => {
web => {
advert_int => '3',
authentication => {
auth_type => 'PASS',
auth_pass => 'abcd1234',
},
interface => 'eth1',
priority => $vrrp_priority,
state => $vrrp_state,
virtual_ipaddress => {
'10.0.0.13/24' => 'dev eth0 label eth0:13',
'10.0.1.13/24' => 'dev eth1 label eth1:13',
},
virtual_router_id => '13',
notify_master => "/path/to/script.sh",
track_script => {
haproxy_check => {
script => "/usr/libexec/haproxy_check.sh",
interval => 2,
weight => 2,
rise => 2,
fall => 2,
},
nginx_check => {
script => "/usr/libexec/nginx_check.sh",
interval => 3,
weight => 3,
rise => 3,
fall => 3,
},
},
},
},
}
```

Note that you may also set the `$global_defs_defaults` parameter, which will
be merged with the more specific `$global_defs`, which is especially useful
Expand Down
38 changes: 36 additions & 2 deletions templates/keepalived-vrrp.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,36 @@ global_defs {
<%- end -%>
}
<%- @instances.sort_by {|iname,idata| iname}.each do |iname,idata| -%>
<%- if idata['track_script'] -%>
<%- idata['track_script'].each do |key, value| %>
vrrp_script <%= File.basename(value['script'], '.sh') %> {
<%- if value['script'] -%>
script "<%= value['script'] %>"
<%- end -%>
<%- if value['interval'] -%>
interval <%= value['interval'] %>
<%- end -%>
<%- if value['weight'] -%>
weight <%= value['weight'] %>
<%- end -%>
<%- if value['timeout'] -%>
timeout <%= value['timeout'] %>
<%- end -%>
<%- if value['rise'] -%>
rise <%= value['rise'] %>
<%- end -%>
<%- if value['fall'] -%>
fall <%= value['fall'] %>
<%- end -%>
<%- if value['user'] -%>
user <%= value['user'] %>
<%- end -%>
}
<%- end -%>
<%- end -%>

vrrp_instance <%= iname %> {
<%- idata.sort_by {|key,value| key}.each do |key,value| -%>
<%- idata.select{|k,v| !['track_script'].include?(k)}.sort_by {|key,value| key}.each do |key,value| -%>
<%- if value.is_a?(Hash) -%>
<%= key %> {
<%- value.sort_by {|k,v| k}.each do |k,v| -%>
Expand All @@ -39,5 +66,12 @@ vrrp_instance <%= iname %> {
<%= key %> <%= value %>
<%- end -%>
<%- end -%>
<%- if idata['track_script'] -%>
<%- idata['track_script'].each do |key, value| %>
track_script {
<%= File.basename(value['script'], '.sh') %>
}
<%- end -%>
<%- end -%>
}
<% end -%>
<%- end -%>