Skip to content

Commit

Permalink
merge vrrp_instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Klem committed Oct 19, 2014
2 parents a0a492a + ff4098c commit 7c13d38
Show file tree
Hide file tree
Showing 21 changed files with 557 additions and 127 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rvm:

matrix:
allow_failures:
- rvm: 1.8.7
- rvm: 2.0.0
env: PUPPET_VERSION="2.7"

Expand All @@ -25,6 +26,8 @@ env:
- PUPPET_VERSION="3.2"
- PUPPET_VERSION="3.3"
- PUPPET_VERSION="3.4"
- PUPPET_VERSION="3.5"
- PUPPET_VERSION="3.6"

branches:
only:
Expand Down
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ facterversion = ENV.key?('FACTER_VERSION') ? "~> #{ENV['FACTER_VERSION']}" : ['>
gem 'facter', facterversion

gem 'rake'
gem 'rspec'
gem 'rspec', '< 3.0.0'
gem 'puppet-lint', '>=0.3.2'
gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
gem 'puppetlabs_spec_helper', '>=0.4.1'
gem 'puppetlabs_spec_helper', '>=0.8.0'
gem 'puppet-syntax'

group :development do
gem 'guard'
gem 'guard-rake'
end
7 changes: 7 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
guard 'rake', :task => 'lint' do
watch(/(.*).pp$/)
end

guard 'rake', :task => 'syntax' do
watch(/(.*).pp$/)
end
11 changes: 0 additions & 11 deletions Modulefile

This file was deleted.

41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

## Tested on...

* Debian 7 (Wheezy)
* Debian 6 (Squeeze)
* RHEL 6

Expand All @@ -32,7 +33,7 @@ node /node01/ {
priority => '101',
auth_type => 'PASS',
auth_pass => 'secret',
virtual_ipaddress => '10.0.0.1/29',
virtual_ipaddress => [ '10.0.0.1/29' ],
track_interface => ['eth1','tun0'], # optional, monitor these interfaces.
}
}
Expand All @@ -47,12 +48,32 @@ node /node02/ {
priority => '100',
auth_type => 'PASS',
auth_pass => 'secret',
virtual_ipaddress => '10.0.0.1/29',
virtual_ipaddress => [ '10.0.0.1/29' ],
track_interface => ['eth1','tun0'], # optional, monitor these interfaces.
}
}
```

### Add floating routes

```puppet
node /node01/ {
include keepalived
keepalived::vrrp::instance { 'VI_50':
interface => 'eth1',
state => 'MASTER',
virtual_router_id => '50',
priority => '101',
auth_type => 'PASS',
auth_pass => 'secret',
virtual_ipaddress => [ '10.0.0.1/29' ],
virtual_routes => [ { to => '168.168.2.0/24', via => '10.0.0.2' },
{ to => '168.168.3.0/24', via => '10.0.0.3' } ]
}
}
```

### Detect application level failure

This configuration will fail-over when:
Expand Down Expand Up @@ -100,15 +121,27 @@ node /node02/ {
}
```

###I'd like to opt out of having the service controlled; we use another tool for that.
### Global definitions

```puppet
class { 'keepalived::global_defs':
ensure => present,
notification_email => '[email protected]',
notification_email_from => '[email protected]',
smtp_server => 'localhost',
smtp_connect_timeout => '60',
router_id => 'your_router_instance_id',
}
```

### Opt out of having the service managed by the module

```puppet
class { '::keepalived':
service_manage => false,
}
```


## Unit testing

Plain RSpec:
Expand Down
12 changes: 2 additions & 10 deletions manifests/global_defs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@
$smtp_connect_timeout = undef,
$router_id = undef,
$ensure = present,
){
if $notification_email {
if is_array($notification_email) {
$notification_email_array = $notification_email
}
else {
$notification_email_array = [$notification_email]
}
}
) inherits keepalived::params {
concat::fragment { 'keepalived.conf_globaldefs':
ensure => $ensure,
target => "${keepalived::config_dir}/keepalived.conf",
target => "${::keepalived::params::config_dir}/keepalived.conf",
content => template('keepalived/globaldefs.erb'),
order => 010,
}
Expand Down
7 changes: 3 additions & 4 deletions manifests/lvs/real_server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#
# === Parameters
#
# Refer to keepalived's documentation to understand the behaviour of these parameters
# Refer to keepalived's documentation to understand the behaviour
# of these parameters
#
# [*virtual_server*]
# The name of the virtual server this real server will be added to
Expand Down Expand Up @@ -35,17 +36,15 @@
$port,
$options = {},
) {

if ( ! is_ip_address($ip_address) ) {
fail('Invalid IP address')
}

validate_re($port, '^[0-9]{1,5}$', "Invalid port: ${port}")

concat::fragment { "keepalived.conf_lvs_real_server_${name}":
target => "${keepalived::config_dir}/keepalived.conf",
target => "${::keepalived::config_dir}/keepalived.conf",
content => template('keepalived/lvs_real_server.erb'),
order => "250-${virtual_server}-${name}",
}

}
72 changes: 51 additions & 21 deletions manifests/lvs/virtual_server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#
# === Parameters
#
# Refer to keepalived's documentation to understand the behaviour of these parameters
# Refer to keepalived's documentation to understand the behaviour
# of these parameters
#
# [*ip_address*]
# Virtual server IP address.
Expand All @@ -23,6 +24,9 @@
# [*delay_loop*]
# Default: not set.
#
# [*protocol*]
# Default: TCP
#
# [*lb_kind*]
# Must be one of NAT, TUN, DR.
# Default: NAT
Expand Down Expand Up @@ -76,55 +80,81 @@
$ip_address,
$port,
$lb_algo,
$delay_loop=undef,
$lb_kind='NAT',
$ha_suspend=false,
$persistence_timeout=undef,
$virtualhost=undef,
$alpha=false,
$omega=false,
$quorum=undef,
$hysteresis=undef,
$tcp_check=undef,
$sorry_server=undef,
$real_servers=undef,
$collect_exported=true,
$alpha = false,
$collect_exported = true,
$delay_loop = undef,
$ha_suspend = false,
$hysteresis = undef,
$lb_kind = 'NAT',
$omega = false,
$persistence_timeout = undef,
$protocol = 'TCP',
$quorum = undef,
$real_servers = undef,
$sorry_server = undef,
$tcp_check = undef,
$virtualhost = undef,
) {

if ( ! is_ip_address($ip_address) ) {
fail('Invalid IP address')
}

validate_re($port, '^[0-9]{1,5}$', "Invalid port: ${port}")
validate_re($lb_algo, '^(rr|wrr|lc|wlc|lblc|sh|dh)$', "Invalid lb_algo: ${lb_algo}")
if $delay_loop { validate_re($delay_loop, '^[0-9]+$', "Invalid delay_loop: ${delay_loop}") }
validate_re(
$lb_algo, '^(rr|wrr|lc|wlc|lblc|sh|dh)$',
"Invalid lb_algo: ${lb_algo}"
)

if $delay_loop {
validate_re(
$delay_loop,
'^[0-9]+$',
"Invalid delay_loop: ${delay_loop}"
)
}

validate_re($lb_kind, '^(NAT|DR|TUN)$', "Invalid lb_kind: ${lb_kind}")
validate_re($protocol, '^(TCP|UDP)$', "Invalid protocol: ${protocol}")
validate_bool($ha_suspend)
validate_bool($alpha)
validate_bool($omega)

if $quorum { validate_re($quorum, '^[0-9]+$', "Invalid quorum: ${quorum}") }
if $hysteresis { validate_re($hysteresis, '^[0-9]+$', "Invalid hysteresis ${hysteresis}") }

if $hysteresis {
validate_re(
$hysteresis,
'^[0-9]+$',
"Invalid hysteresis ${hysteresis}"
)
}

if $sorry_server {
if ( ! is_ip_address($sorry_server['ip_address']) ) {
fail("Invalid sorry server IP address: ${sorry_server['ip_address']}")
}
validate_re($sorry_server['port'], '^[0-9]{1,5}$', "Invalid sorry serverport: ${sorry_server['port']}")

validate_re(
$sorry_server['port'],
'^[0-9]{1,5}$',
"Invalid sorry serverport: ${sorry_server['port']}"
)
}

concat::fragment { "keepalived.conf_lvs_virtual_server_${name}":
target => "${keepalived::config_dir}/keepalived.conf",
target => "${::keepalived::config_dir}/keepalived.conf",
content => template('keepalived/lvs_virtual_server.erb'),
order => "250-${name}-000",
}

concat::fragment { "keepalived.conf_lvs_virtual_server_${name}-footer":
target => "${keepalived::config_dir}/keepalived.conf",
target => "${::keepalived::config_dir}/keepalived.conf",
content => "}\n",
order => "250-${name}",
}

if $collect_exported {
Keepalived::Lvs::Virtual_server <<| virtual_server == $name |>>
Keepalived::Lvs::Real_server <<| virtual_server == $name |>>
}
}
14 changes: 14 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
$service_name = 'keepalived'
}

'gentoo': {
$config_dir = '/etc/keepalived'
$config_dir_mode = '0755'
$config_file_mode = '0644'
$config_group = 'root'
$config_owner = 'root'
$daemon_group = 'root'
$daemon_user = 'root'
$pkg_list = [ 'keepalived' ]
$service_hasrestart = false
$service_hasstatus = false
$service_name = 'keepalived'
}

default: {
fail "Operating system ${::operatingsystem} is not supported."
}
Expand Down
Loading

0 comments on commit 7c13d38

Please sign in to comment.