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
|
extends: default
|
||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
.kitchen/*
|
.kitchen*
|
||||||
vendor/
|
vendor/
|
||||||
|
.forgejo/
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
line-length:
|
line-length:
|
||||||
max: 120
|
max: 120
|
||||||
level: warning
|
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]
|
## [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
|
## v1.1.0 - 2021-08-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
70
README.md
70
README.md
|
@ -1,32 +1,34 @@
|
||||||
# Ansible role: Keepalived
|
# 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)
|
[![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://git.yaegashi.fr/nishiki/ansible-role-keepalived/src/branch/master/LICENSE)
|
[![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
|
Install and configure Keepalived
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Ansible >= 2.9
|
- Ansible >= 2.9
|
||||||
* Debian
|
- Debian
|
||||||
* Buster
|
- Bullseye
|
||||||
* Bullseye
|
- Bookworm
|
||||||
|
|
||||||
## Role variables
|
## 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_mail_from | str | no | keepalived@test.local | from header for notification mail |
|
||||||
| keepalived_smtp_server | str | no | localhost | the smtp server |
|
| keepalived_smtp_server | str | no | localhost | the smtp server |
|
||||||
| keepalived_notification_mails | array | no | | the mail addresses to notify |
|
| keepalived_notification_mails | array | no | | the mail addresses to notify |
|
||||||
| keepalived_vrrp_instances | array | no | | the vrrp instances |
|
| keepalived_vrrp_instances | hash | no | | the vrrp instances |
|
||||||
| keepalived_vrrp_scripts | array | no | | the vrrp check scripts |
|
| keepalived_vrrp_scripts | hash | no | | the vrrp check scripts |
|
||||||
|
| keepalived_track_files | hash | no | | the track files |
|
||||||
|
|
||||||
### keepalived_vrrp_instances
|
### keepalived_vrrp_instances
|
||||||
|
|
||||||
| Name | Type | Required | Default | Comment |
|
| 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 |
|
| state | str | yes | | Initial state, MASTER or BACKUP |
|
||||||
| interface | str | yes | | interface for inside_network, bound by vrrp |
|
| interface | str | yes | | interface for inside_network, bound by vrrp |
|
||||||
| virtual_router_id | int | yes | | arbitrary unique number from 1 to 255 |
|
| 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` |
|
| authentication | hash | no | | use an authentication `deprecated` |
|
||||||
| virtual_ipaddresses | array | yes | | addresses add on change to MASTER, to BACKUP |
|
| virtual_ipaddresses | array | yes | | addresses add on change to MASTER, to BACKUP |
|
||||||
| track_scripts | array | no | | add a tracking script to the interface |
|
| 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 |
|
| notify | hash | no | | notify scripts, alert as above |
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: vip_ngninx
|
vip_ngninx:
|
||||||
state: master
|
state: master
|
||||||
interface: eth0
|
interface: eth0
|
||||||
virtual_router_id: 5
|
virtual_router_id: 5
|
||||||
|
@ -60,24 +63,41 @@ Example:
|
||||||
|
|
||||||
### keepalived_vrrp_scripts
|
### keepalived_vrrp_scripts
|
||||||
|
|
||||||
| Name | Type | Required | Default | Comment |
|
| 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 |
|
| script | str | yes | | path of the script to execute |
|
||||||
| interval | int | no | 2 | seconds between script invocations |
|
| interval | int | no | 2 | seconds between script invocations |
|
||||||
| fall | int | no | 2 | number of successes for KO transition |
|
| fall | int | no | 2 | number of successes for KO transition |
|
||||||
| rise | int | no | 2 | number of successes for OK transition |
|
| rise | int | no | 2 | number of successes for OK transition |
|
||||||
|
| weight | int | no | 1 | weigth of script |
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
- name: check_nginx
|
check_nginx:
|
||||||
script: /usr/local/bin/check_nginx
|
script: /usr/local/bin/check_nginx
|
||||||
fall: 3
|
fall: 3
|
||||||
rise: 5
|
rise: 5
|
||||||
interval: 10
|
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
|
## How to use
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -107,10 +127,10 @@ Example:
|
||||||
|
|
||||||
### Test with molecule and docker
|
### Test with molecule and docker
|
||||||
|
|
||||||
* install [docker](https://docs.docker.com/engine/installation/)
|
- install [docker](https://docs.docker.com/engine/installation/)
|
||||||
* install `python3` and `python3-pip`
|
- install `python3` and `python3-pip`
|
||||||
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
- install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||||
* run `molecule test`
|
- run `molecule test`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
keepalived_mail_from: keepalived@test.local
|
keepalived_mail_from: keepalived@test.local
|
||||||
keepalived_smtp_server: localhost
|
keepalived_smtp_server: localhost
|
||||||
keepalived_notification_mails: []
|
keepalived_notification_mails: []
|
||||||
keepalived_vrrp_instances: []
|
keepalived_vrrp_instances: {}
|
||||||
keepalived_vrrp_scripts: []
|
keepalived_vrrp_scripts: {}
|
||||||
|
keepalived_track_files: {}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
- name: restart keepalived
|
- name: Restart keepalived
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: keepalived
|
name: keepalived
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
---
|
---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
role_name: keepalived
|
role_name: keepalived
|
||||||
|
namespace: nishiki
|
||||||
author: Adrien Waksberg
|
author: Adrien Waksberg
|
||||||
company: Adrien Waksberg
|
company: Adrien Waksberg
|
||||||
description: Install and configure keepalived
|
description: Install and configure keepalived
|
||||||
license: Apache2
|
license: Apache2
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: "2.9"
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- buster
|
|
||||||
- bullseye
|
- bullseye
|
||||||
|
- bookworm
|
||||||
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- ipfailover
|
- ipfailover
|
||||||
|
|
|
@ -5,13 +5,17 @@
|
||||||
- ansible-role-keepalived
|
- ansible-role-keepalived
|
||||||
vars:
|
vars:
|
||||||
keepalived_vrrp_scripts:
|
keepalived_vrrp_scripts:
|
||||||
- name: hello
|
hello:
|
||||||
script: /bin/true
|
script: /bin/true
|
||||||
fall: 3
|
fall: 3
|
||||||
interval: 10
|
interval: 10
|
||||||
rise: 5
|
rise: 5
|
||||||
|
keepalived_track_files:
|
||||||
|
master:
|
||||||
|
file: /tmp/master
|
||||||
|
weight: 42
|
||||||
keepalived_vrrp_instances:
|
keepalived_vrrp_instances:
|
||||||
- name: test
|
test:
|
||||||
state: master
|
state: master
|
||||||
interface: eth0
|
interface: eth0
|
||||||
virtual_router_id: 5
|
virtual_router_id: 5
|
||||||
|
|
|
@ -2,19 +2,21 @@
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
platforms:
|
||||||
- name: debian10
|
- name: debian12
|
||||||
image: nishiki/debian10:molecule
|
image: code.waks.be/nishiki/molecule:debian12
|
||||||
privileged: true
|
privileged: true
|
||||||
volumes:
|
volumes:
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
cgroupns_mode: host
|
||||||
command: /bin/systemd
|
command: /bin/systemd
|
||||||
capabilities:
|
capabilities:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
- name: debian11
|
- name: debian11
|
||||||
image: nishiki/debian11:molecule
|
image: code.waks.be/nishiki/molecule:debian11
|
||||||
privileged: true
|
privileged: true
|
||||||
volumes:
|
volumes:
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
cgroupns_mode: host
|
||||||
command: /bin/systemd
|
command: /bin/systemd
|
||||||
capabilities:
|
capabilities:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
|
|
|
@ -13,6 +13,7 @@ def test_config_file(host):
|
||||||
assert path.mode == 0o600
|
assert path.mode == 0o600
|
||||||
assert path.contains('priority 200')
|
assert path.contains('priority 200')
|
||||||
assert path.contains('interval 10')
|
assert path.contains('interval 10')
|
||||||
|
assert path.contains('track_file master {')
|
||||||
|
|
||||||
def test_service(host):
|
def test_service(host):
|
||||||
service = host.service('keepalived')
|
service = host.service('keepalived')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
- name: install package
|
- name: Install package
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name:
|
name:
|
||||||
- keepalived
|
- keepalived
|
||||||
|
@ -8,19 +8,19 @@
|
||||||
until: result is succeeded
|
until: result is succeeded
|
||||||
tags: keepalived
|
tags: keepalived
|
||||||
|
|
||||||
- name: copy configuration file
|
- name: Copy configuration file
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: keepalived.conf.j2
|
src: keepalived.conf.j2
|
||||||
dest: /etc/keepalived/keepalived.conf
|
dest: /etc/keepalived/keepalived.conf
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: 0600
|
mode: 0600
|
||||||
notify: restart keepalived
|
notify: Restart keepalived
|
||||||
tags: keepalived
|
tags: keepalived
|
||||||
|
|
||||||
- name: enable and start the service
|
- name: Enable and start the service
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: keepalived
|
name: keepalived
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: true
|
||||||
tags: keepalived
|
tags: keepalived
|
||||||
|
|
|
@ -9,18 +9,26 @@ global_defs {
|
||||||
notification_email_from {{ keepalived_mail_from }}
|
notification_email_from {{ keepalived_mail_from }}
|
||||||
smtp_server {{ keepalived_smtp_server }}
|
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 }}"
|
script "{{ vrrp_script.script }}"
|
||||||
interval {{ vrrp_script.interval|default(2) }}
|
interval {{ vrrp_script.interval|default(2) }}
|
||||||
fall {{ vrrp_script.fall|default(2) }}
|
fall {{ vrrp_script.fall|default(2) }}
|
||||||
rise {{ vrrp_script.rise|default(2) }}
|
rise {{ vrrp_script.rise|default(2) }}
|
||||||
|
weight {{ vrrp_script.weight|default(1) }}
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% 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 }}
|
state {{ vrrp_instance.state|upper }}
|
||||||
interface {{ vrrp_instance.interface }}
|
interface {{ vrrp_instance.interface }}
|
||||||
virtual_router_id {{ vrrp_instance.virtual_router_id }}
|
virtual_router_id {{ vrrp_instance.virtual_router_id }}
|
||||||
|
@ -46,9 +54,16 @@ vrrp_instance {{ vrrp_instance.name }} {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if 'track_files' in vrrp_instance %}
|
||||||
|
track_file {
|
||||||
|
{% for script in vrrp_instance.track_files %}
|
||||||
|
{{ script }}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
{% if 'notify' in vrrp_instance %}
|
{% if 'notify' in vrrp_instance %}
|
||||||
{% for state, script in vrrp_instance.notify.items() %}
|
{% for state, script in vrrp_instance.notify.items() %}
|
||||||
notify_{{ state }} "{{ script }}"
|
notify_{{ state }} "{{ script|trim }}"
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue