Skip to content

Commit

Permalink
Add support for vrrp_track_process (#45)
Browse files Browse the repository at this point in the history
* Add support for vrrp_track_process

* Add documentation

* Fix full_command

* Make v2.2.2 the default version
  • Loading branch information
tersmitten committed May 10, 2021
1 parent e4f42f1 commit 3bc10c2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Set up the latest or a specific version of [Keepalived](http://www.keepalived.or
#### Variables

* `keepalived_git_repo`: [default: `https://github.com/acassen/keepalived.git`]: Keepalived git repo
* `keepalived_version`: [default: `v2.1.5`]: Keepalived version to install
* `keepalived_version`: [default: `v2.2.2`]: Keepalived version to install

* `keepalived_install`: [default: `[]`]: Additional packages to install (e.g. `['libnl-3-dev', 'libnl-genl-3-dev', 'libnl-route-3-dev', 'libnfnetlink-dev']`)
* `keepalived_configure_options`: [default: `[]`]: Options to pass to `./configure`
Expand Down Expand Up @@ -55,6 +55,18 @@ Set up the latest or a specific version of [Keepalived](http://www.keepalived.or
* `keepalived_vrrp_scripts.key.rise`: [optional]: Required number of successes for OK transition
* `keepalived_vrrp_scripts.key.fall`: [optional]: Required number of successes for KO transition

* `keepalived_vrrp_track_processes`: [default: `{}`]: VRRP process declarations
* `keepalived_vrrp_track_processes.key`: The name of the VRRP script
* `keepalived_vrrp_track_processes.key.process`: The process to monitor (with optional parameters)
* `keepalived_vrrp_track_processes.key.param_match`: [optional]: If matching parameters, this specifies a `partial` match (i.e. the first n parameters match exactly), or an `initial` match, i.e. the last parameter may be longer that the parameter configured
* `keepalived_vrrp_track_processes.key.weight`: [optional]: The check weight to adjust the priority
* `keepalived_vrrp_track_processes.key.quorum`: [optional]: Minimum number of processes for success
* `keepalived_vrrp_track_processes.key.quorum_max`: [optional]: Maximum number of processes for success
* `keepalived_vrrp_track_processes.key.fork_delay`: [optional]: Time to delay after process quorum gained after fork before consider process up
* `keepalived_vrrp_track_processes.key.terminate_delay`: [optional]: Time to delay after process quorum lost before consider process down
* `keepalived_vrrp_track_processes.key.delay`: [optional]: This sets `fork_delay` and `terminate_delay`
* `keepalived_vrrp_track_processes.key.full_command`: [optional]: Normally process string is matched against the process name, as shown on the `Name`: line in `/proc/PID/status`, unless parameters are specified

* `keepalived_vrrp_instances`: [default: `{}`]: VRRP instance declarations
* `keepalived_vrrp_instances.key`: The name of the VRRP instance
* `keepalived_vrrp_instances.key.interface`: Interface bound by VRRP
Expand All @@ -72,6 +84,7 @@ Set up the latest or a specific version of [Keepalived](http://www.keepalived.or
* `keepalived_vrrp_instances.key.preempt_delay`: [optional]: Seconds after startup until preemption (if not disabled by `nopreempt`). Range: 0 (default) to 1000 **NOTE:** For this to work, the initial state of this entry must be BACKUP
* `keepalived_vrrp_instances.key.track_interfaces`: [optional]: Interface states we monitor
* `keepalived_vrrp_instances.key.track_scripts`: [optional]: Scripts state we monitor
* `keepalived_vrrp_instances.key.track_processes`: [optional]: Processes state we monitor

* `keepalived_vrrp_instances.key.notify`: [optional]: Scripts that is invoked when a server changes state
* `keepalived_vrrp_instances.key.notify_user`: [optional]: Specify the user / group to run this script under (since `1.3.0`, e.g. `'nobody nogroup'`)
Expand Down Expand Up @@ -100,7 +113,7 @@ None
- name: log-detail
keepalived_vrrp_scripts:
chk_haproxy:
script: '/bin/pidof haproxy'
script: '/usr/bin/pgrep haproxy'
weight: 2
interval: 1

Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# defaults file
---
keepalived_git_repo: https://github.com/acassen/keepalived.git
keepalived_version: v2.1.5
keepalived_version: v2.2.2
keepalived_install: []
keepalived_configure_options: []
keepalived_options: []
Expand All @@ -19,5 +19,6 @@ keepalived_global_defs_smtp_connect_timeout: 30
keepalived_vrrp_script_map: {}

keepalived_vrrp_scripts: {}
keepalived_vrrp_track_processes: {}

keepalived_vrrp_instances: {}
40 changes: 39 additions & 1 deletion templates/etc/keepalived/keepalived.conf.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# {{ ansible_managed }}
{{ ansible_managed | comment }}

global_defs {
notification_email {
Expand Down Expand Up @@ -45,6 +45,36 @@ vrrp_script {{ key }} {
}
{% endfor %}

{% for key, value in keepalived_vrrp_track_processes.items() | sort %}
vrrp_track_process {{ key }} {
process {{ value.process }}
{% if value.param_match is defined %}
param_match {{ value.param_match }}
{% endif %}
{% if value.weight is defined %}
weight {{ value.weight }}
{% endif %}
{% if value.quorum is defined %}
quorum {{ value.quorum }}
{% endif %}
{% if value.quorum_max is defined %}
quorum_max {{ value.quorum_max }}
{% endif %}
{% if value.fork_delay is defined %}
fork_delay {{ value.fork_delay }}
{% endif %}
{% if value.terminate_delay is defined %}
terminate_delay {{ value.terminate_delay }}
{% endif %}
{% if value.delay is defined %}
delay {{ value.delay }}
{% endif %}
{% if value.full_command is defined and value.full_command | bool %}
full_command
{% endif %}
}
{% endfor %}

{% for key, value in keepalived_vrrp_instances.items() | sort %}
vrrp_instance {{ key }} {
interface {{ value.interface }}
Expand Down Expand Up @@ -103,6 +133,14 @@ vrrp_instance {{ key }} {
}
{% endif %}

{% if value.track_processes is defined %}
track_process {
{% for track_process in value.track_processes %}
{{ track_process }}
{% endfor %}
}
{% endif %}

{% if value.unicast_peer is defined %}
unicast_peer {
{{ value.unicast_peer }}
Expand Down
2 changes: 1 addition & 1 deletion tests/vars/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ keepalived_options:

keepalived_vrrp_scripts:
chk_sshd:
script: '/bin/pidof sshd'
script: '/usr/bin/pgrep haproxy'
weight: 2
interval: 1
timeout: 2
Expand Down

0 comments on commit 3bc10c2

Please sign in to comment.