Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
65abc6ca2c | |||
9624b3d53e | |||
24a8f7b230 | |||
17e493406c | |||
459b362b7a | |||
c3c1765b11 | |||
81dc07a29c | |||
e2bee4e950 | |||
8768d2fe2f | |||
5c9ee49c89 | |||
f0d84e9aa1 |
13 changed files with 135 additions and 49 deletions
18
.forgejo/workflows/molecule.yml
Normal file
18
.forgejo/workflows/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
on: [push]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.waks.be/nishiki/molecule:docker
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: ansible-lint .
|
||||
- run: yamllint .
|
||||
molecule:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.waks.be/nishiki/molecule:docker
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: molecule test
|
10
.gitlab-ci.yml
Normal file
10
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
image: nishiki/molecule:docker
|
||||
|
||||
before_script:
|
||||
- molecule --version
|
||||
|
||||
molecule:
|
||||
stage: test
|
||||
script:
|
||||
- molecule test
|
|
@ -2,11 +2,11 @@
|
|||
extends: default
|
||||
|
||||
ignore: |
|
||||
.kitchen/*
|
||||
.kitchen*
|
||||
vendor/
|
||||
.forgejo/
|
||||
|
||||
rules:
|
||||
line-length:
|
||||
max: 120
|
||||
level: warning
|
||||
truthy: false
|
||||
|
|
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -5,6 +5,20 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- add track files
|
||||
|
||||
### Changed
|
||||
|
||||
- keepalived_vrrp_scripts variable is now a hash
|
||||
- keepalived_vrrp_instances variable is now a hash
|
||||
- test: test: use personal docker registry
|
||||
|
||||
### Fixed
|
||||
|
||||
- missing bracket for vrrp_sript in template
|
||||
|
||||
## v1.1.0 - 2021-08-18
|
||||
|
||||
### Added
|
||||
|
|
60
README.md
60
README.md
|
@ -1,32 +1,34 @@
|
|||
# Ansible role: Keepalived
|
||||
|
||||
[![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-keepalived/releases)
|
||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-keepalived/src/branch/master/LICENSE)
|
||||
[![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://code.waks.be/nishiki/ansible-role-keepalived/releases)
|
||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://code.waks.be/nishiki/ansible-role-keepalived/src/branch/main/LICENSE)
|
||||
[![Build](https://code.waks.be/nishiki/ansible-role-keepalived/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-keepalived/actions?workflow=molecule.yml)
|
||||
|
||||
Install and configure Keepalived
|
||||
|
||||
## Requirements
|
||||
|
||||
* Ansible >= 2.9
|
||||
* Debian
|
||||
* Buster
|
||||
* Bullseye
|
||||
- Ansible >= 2.9
|
||||
- Debian
|
||||
- Bullseye
|
||||
- Bookworm
|
||||
|
||||
## Role variables
|
||||
|
||||
| Name | Type | Required |Default | Comment |
|
||||
|-------------------------------|-------|----------|-----------------------|-----------------------------------|
|
||||
| Name | Type | Required | Default | Comment |
|
||||
| ----------------------------- | ----- | -------- | --------------------- | --------------------------------- |
|
||||
| keepalived_mail_from | str | no | keepalived@test.local | from header for notification mail |
|
||||
| keepalived_smtp_server | str | no | localhost | the smtp server |
|
||||
| keepalived_notification_mails | array | no | | the mail addresses to notify |
|
||||
| keepalived_vrrp_instances | array | no | | the vrrp instances |
|
||||
| keepalived_vrrp_scripts | array | no | | the vrrp check scripts |
|
||||
| keepalived_vrrp_instances | hash | no | | the vrrp instances |
|
||||
| keepalived_vrrp_scripts | hash | no | | the vrrp check scripts |
|
||||
| keepalived_track_files | hash | no | | the track files |
|
||||
|
||||
### keepalived_vrrp_instances
|
||||
|
||||
| Name | Type | Required | Default | Comment |
|
||||
|---------------------|-------|----------|---------|----------------------------------------------|
|
||||
| name | str | yes | | the instance name |
|
||||
| ------------------- | ----- | -------- | ------- | -------------------------------------------- |
|
||||
| key | str | yes | | the instance name |
|
||||
| state | str | yes | | Initial state, MASTER or BACKUP |
|
||||
| interface | str | yes | | interface for inside_network, bound by vrrp |
|
||||
| virtual_router_id | int | yes | | arbitrary unique number from 1 to 255 |
|
||||
|
@ -35,12 +37,13 @@ Install and configure Keepalived
|
|||
| authentication | hash | no | | use an authentication `deprecated` |
|
||||
| virtual_ipaddresses | array | yes | | addresses add on change to MASTER, to BACKUP |
|
||||
| track_scripts | array | no | | add a tracking script to the interface |
|
||||
| track_files | array | no | | add a tracking file to the interface |
|
||||
| notify | hash | no | | notify scripts, alert as above |
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
- name: vip_ngninx
|
||||
vip_ngninx:
|
||||
state: master
|
||||
interface: eth0
|
||||
virtual_router_id: 5
|
||||
|
@ -61,23 +64,40 @@ Example:
|
|||
### keepalived_vrrp_scripts
|
||||
|
||||
| Name | Type | Required | Default | Comment |
|
||||
|----------|-------|----------|---------|---------------------------------------|
|
||||
| name | str | yes | | the script name |
|
||||
| -------- | ---- | -------- | ------- | ------------------------------------- |
|
||||
| key | str | yes | | the script name |
|
||||
| script | str | yes | | path of the script to execute |
|
||||
| interval | int | no | 2 | seconds between script invocations |
|
||||
| fall | int | no | 2 | number of successes for KO transition |
|
||||
| rise | int | no | 2 | number of successes for OK transition |
|
||||
| weight | int | no | 1 | weigth of script |
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
- name: check_nginx
|
||||
check_nginx:
|
||||
script: /usr/local/bin/check_nginx
|
||||
fall: 3
|
||||
rise: 5
|
||||
interval: 10
|
||||
```
|
||||
|
||||
### keepalived_track_file
|
||||
|
||||
| Name | Type | Required | Default | Comment |
|
||||
| ------ | ---- | -------- | ------- | ------------------------- |
|
||||
| key | str | yes | | the track file name |
|
||||
| file | str | yes | | path of the file to track |
|
||||
| weight | int | no | 1 | weigth of file |
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
master_file:
|
||||
file: /tmp/master
|
||||
weight: 3
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
```
|
||||
|
@ -107,10 +127,10 @@ Example:
|
|||
|
||||
### Test with molecule and docker
|
||||
|
||||
* install [docker](https://docs.docker.com/engine/installation/)
|
||||
* install `python3` and `python3-pip`
|
||||
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||
* run `molecule test`
|
||||
- install [docker](https://docs.docker.com/engine/installation/)
|
||||
- install `python3` and `python3-pip`
|
||||
- install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||
- run `molecule test`
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
keepalived_mail_from: keepalived@test.local
|
||||
keepalived_smtp_server: localhost
|
||||
keepalived_notification_mails: []
|
||||
keepalived_vrrp_instances: []
|
||||
keepalived_vrrp_scripts: []
|
||||
keepalived_vrrp_instances: {}
|
||||
keepalived_vrrp_scripts: {}
|
||||
keepalived_track_files: {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
- name: restart keepalived
|
||||
- name: Restart keepalived
|
||||
ansible.builtin.service:
|
||||
name: keepalived
|
||||
state: restarted
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
---
|
||||
galaxy_info:
|
||||
role_name: keepalived
|
||||
namespace: nishiki
|
||||
author: Adrien Waksberg
|
||||
company: Adrien Waksberg
|
||||
description: Install and configure keepalived
|
||||
license: Apache2
|
||||
min_ansible_version: 2.9
|
||||
min_ansible_version: "2.9"
|
||||
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- buster
|
||||
- bullseye
|
||||
- bookworm
|
||||
|
||||
galaxy_tags:
|
||||
- ipfailover
|
||||
|
|
|
@ -5,13 +5,17 @@
|
|||
- ansible-role-keepalived
|
||||
vars:
|
||||
keepalived_vrrp_scripts:
|
||||
- name: hello
|
||||
hello:
|
||||
script: /bin/true
|
||||
fall: 3
|
||||
interval: 10
|
||||
rise: 5
|
||||
keepalived_track_files:
|
||||
master:
|
||||
file: /tmp/master
|
||||
weight: 42
|
||||
keepalived_vrrp_instances:
|
||||
- name: test
|
||||
test:
|
||||
state: master
|
||||
interface: eth0
|
||||
virtual_router_id: 5
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: debian10
|
||||
image: nishiki/debian10:molecule
|
||||
- name: debian12
|
||||
image: code.waks.be/nishiki/molecule:debian12
|
||||
privileged: true
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
command: /bin/systemd
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
- name: debian11
|
||||
image: nishiki/debian11:molecule
|
||||
image: code.waks.be/nishiki/molecule:debian11
|
||||
privileged: true
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
command: /bin/systemd
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
|
|
|
@ -13,6 +13,7 @@ def test_config_file(host):
|
|||
assert path.mode == 0o600
|
||||
assert path.contains('priority 200')
|
||||
assert path.contains('interval 10')
|
||||
assert path.contains('track_file master {')
|
||||
|
||||
def test_service(host):
|
||||
service = host.service('keepalived')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
- name: install package
|
||||
- name: Install package
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- keepalived
|
||||
|
@ -8,19 +8,19 @@
|
|||
until: result is succeeded
|
||||
tags: keepalived
|
||||
|
||||
- name: copy configuration file
|
||||
- name: Copy configuration file
|
||||
ansible.builtin.template:
|
||||
src: keepalived.conf.j2
|
||||
dest: /etc/keepalived/keepalived.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
notify: restart keepalived
|
||||
notify: Restart keepalived
|
||||
tags: keepalived
|
||||
|
||||
- name: enable and start the service
|
||||
- name: Enable and start the service
|
||||
ansible.builtin.service:
|
||||
name: keepalived
|
||||
state: started
|
||||
enabled: yes
|
||||
enabled: true
|
||||
tags: keepalived
|
||||
|
|
|
@ -9,18 +9,26 @@ global_defs {
|
|||
notification_email_from {{ keepalived_mail_from }}
|
||||
smtp_server {{ keepalived_smtp_server }}
|
||||
}
|
||||
{% for vrrp_script in keepalived_vrrp_scripts %}
|
||||
{% for vrrp_script_name, vrrp_script in keepalived_vrrp_scripts.items() %}
|
||||
|
||||
vrrp_script {{ vrrp_script.name }}
|
||||
vrrp_script {{ vrrp_script_name }} {
|
||||
script "{{ vrrp_script.script }}"
|
||||
interval {{ vrrp_script.interval|default(2) }}
|
||||
fall {{ vrrp_script.fall|default(2) }}
|
||||
rise {{ vrrp_script.rise|default(2) }}
|
||||
weight {{ vrrp_script.weight|default(1) }}
|
||||
}
|
||||
{% endfor %}
|
||||
{% for vrrp_instance in keepalived_vrrp_instances %}
|
||||
{% for track_file_name, track_file in keepalived_track_files.items() %}
|
||||
|
||||
vrrp_instance {{ vrrp_instance.name }} {
|
||||
track_file {{ track_file_name }} {
|
||||
file "{{ track_file.file }}"
|
||||
weight {{ track_file.weight|default(1) }}
|
||||
}
|
||||
{% endfor %}
|
||||
{% for vrrp_instance_name, vrrp_instance in keepalived_vrrp_instances.items() %}
|
||||
|
||||
vrrp_instance {{ vrrp_instance_name }} {
|
||||
state {{ vrrp_instance.state|upper }}
|
||||
interface {{ vrrp_instance.interface }}
|
||||
virtual_router_id {{ vrrp_instance.virtual_router_id }}
|
||||
|
@ -46,9 +54,16 @@ vrrp_instance {{ vrrp_instance.name }} {
|
|||
{% endfor %}
|
||||
}
|
||||
{% endif %}
|
||||
{% if 'track_files' in vrrp_instance %}
|
||||
track_file {
|
||||
{% for script in vrrp_instance.track_files %}
|
||||
{{ script }}
|
||||
{% endfor %}
|
||||
}
|
||||
{% endif %}
|
||||
{% if 'notify' in vrrp_instance %}
|
||||
{% for state, script in vrrp_instance.notify.items() %}
|
||||
notify_{{ state }} "{{ script }}"
|
||||
notify_{{ state }} "{{ script|trim }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue