Compare commits

..

7 Commits

10 changed files with 50 additions and 115 deletions

View File

@@ -13,22 +13,17 @@ keepalived_ipv6: ""
keepalived_peers: [] keepalived_peers: []
keepalived_notify_enable: false keepalived_notify_script_enabled: false
keepalived_notify_pre: {}
keepalived_notify_is_master: {}
keepalived_notify_is_backup: {}
keepalived_notify_is_fault: {}
keepalived_notify_by_default: {}
keepalived_track_scripts: [] keepalived_track_scripts: []
# Example: # Exemple:
# - name: check_haproxy_8080 # - name: check_haproxy_8080
# command: /usr/bin/nc -zv 127.0.0.1 8080 # command: /usr/bin/nc -zv 127.0.0.1 8080
# - name: check_haproxy_8081 # - name: check_haproxy_8081
# command: /usr/bin/nc -zv 127.0.0.1 8081 # command: /usr/bin/nc -zv 127.0.0.1 8081
keepalived_track_processes: [] keepalived_track_processes: []
# Example: # Exemple:
# - name: check_haproxy # - name: check_haproxy
# search: /usr/sbin/haproxy # search: /usr/sbin/haproxy
# quorum: 2 # quorum: 2

View File

@@ -1,7 +1,7 @@
--- ---
# handlers file for keepalived # handlers file for keepalived
- name: Restart keepalived.service - name: Redémarrer keepalived.service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
state: restarted state: restarted

View File

@@ -1,7 +1,7 @@
galaxy_info: galaxy_info:
namespace: ykn namespace: ykn
author: pulsar89.5 author: pulsar89.5
description: Deploy keepalived description: Rôle de déploiement de keepalived
license: GPL-3.0-or-later license: GPL-3.0-or-later
@@ -14,3 +14,10 @@ galaxy_info:
dependencies: dependencies:
- role: users - role: users
vars:
users_role_keepalived:
- name: keepalived_script
comment: "Dedicated user for keepalived script"
update_password: on_create
password_lock: true
shell: /bin/bash

View File

@@ -1,37 +0,0 @@
---
# tasks file for keepalived
- name: Deploy configuration
ansible.builtin.template:
src: keepalived.j2
dest: /etc/keepalived/keepalived.conf
owner: root
group: root
mode: u=rw,g=r,o=r
become: true
notify: Restart keepalived.service
- name: Deploy sudoers configuration
ansible.builtin.template:
src: sudoers.j2
dest: /etc/sudoers.d/keepalived_script
owner: root
group: keepalived_script
mode: u=rwx,g=rx,o=
validate: /usr/sbin/visudo -cf %s
when:
- keepalived_notify_enable
- keepalived_sudoers_cmd | length > 0
become: true
notify: Restart keepalived.service
- name: Deploy notify script
ansible.builtin.template:
src: notify.bash.j2
dest: /etc/keepalived/notify.bash
owner: root
group: keepalived_script
mode: u=rwx,g=rx,o=
when: keepalived_notify_enable
become: true
notify: Restart keepalived.service

View File

@@ -1,7 +0,0 @@
---
# tasks file for keepalived
- name: Install keepalived
ansible.builtin.apt:
name: keepalived
become: true

View File

@@ -1,10 +1,39 @@
--- ---
# tasks file for keepalived # tasks file for keepalived
- name: Import installation tasks - name: Installer le paquet
ansible.builtin.import_tasks: ansible.builtin.apt:
file: installation.yml name: keepalived
become: true
- name: Import configuration tasks - name: Déployer la configuration
ansible.builtin.import_tasks: ansible.builtin.template:
file: configuration.yml owner: root
group: root
mode: u=rw,g=r,o=r
src: keepalived.j2
dest: /etc/keepalived/keepalived.conf
become: true
notify: Redémarrer keepalived.service
- name: Déployer les scripts
ansible.builtin.copy:
src: keepalived/notify.sh
dest: /etc/keepalived/
owner: keepalived_script
group: keepalived_script
mode: u=rx,g=rx,o=
when: keepalived_notify_script_enabled
become: true
notify: Redémarrer keepalived.service
- name: Déployer le fichier de configuration de sudoers
ansible.builtin.copy:
src: keepalived/sudoers
dest: /etc/sudoers.d/keepalived
owner: root
group: root
mode: u=rw,g=r,o=r
validate: /usr/sbin/visudo -cf %s
when: "'keepalived/sudoers' is file"
become: true

View File

@@ -20,7 +20,7 @@ global_defs {
{% for script in keepalived_track_scripts %} {% for script in keepalived_track_scripts %}
vrrp_script {{ script.name }} { vrrp_script {{ script.name }} {
script "{{ script.command }}" script {{ script.command }}
interval {{ script.interval }} interval {{ script.interval }}
} }
{% endfor %} {% endfor %}
@@ -64,8 +64,8 @@ vrrp_instance VIP_{{ keepalived_uid }} {
} }
{% endif %} {% endif %}
{% if keepalived_notify_enable %} {% if keepalived_notify_script_enabled %}
notify /etc/keepalived/notify.bash notify /etc/keepalived/notify.sh
{% endif %} {% endif %}
{% if keepalived_track_scripts | length > 0 %} {% if keepalived_track_scripts | length > 0 %}

View File

@@ -1,38 +0,0 @@
#!/bin/bash
# {{ ansible_managed }}
TYPE=$1
NAME=$2
STATE=$3
{% if keepalived_notify_pre | length > 0 %}
{{ keepalived_notify_pre }}
{% endif %}
# Use keepalived state
case $STATE in
{% if keepalived_notify_is_master | length > 0 %}
"MASTER")
{{ keepalived_notify_is_master | indent(4) }}
exit 0
;;
{% endif %}
{% if keepalived_notify_is_backup | length > 0 %}
"BACKUP")
{{ keepalived_notify_is_backup | indent(4) }}
exit 0
;;
{% endif %}
{% if keepalived_notify_is_fault | length > 0 %}
"FAULT")
{{ keepalived_notify_is_fault | indent(4) }}
exit 0
;;
{% endif %}
{% if keepalived_notify_by_default | length > 0 %}
*)
{{ keepalived_notify_by_default | indent(4) }}
exit 1
;;
{% endif %}
esac

View File

@@ -1,5 +0,0 @@
# {{ ansible_managed }}
{% for cmd in keepalived_sudoers_cmd %}
keepalived_script ALL=(ALL) NOPASSWD:{{ cmd }}
{% endfor %}

View File

@@ -1,9 +0,0 @@
---
# vars file for keepalived
users:
- name: keepalived_script
comment: "Dedicated user for keepalived script"
update_password: on_create
password_lock: true
shell: /bin/bash