230 lines
6.9 KiB
YAML
230 lines
6.9 KiB
YAML
---
|
|
# ============================================
|
|
# PostgreSQL Installation (vm-postgres uniquement)
|
|
# ============================================
|
|
- name: Installation et configuration de PostgreSQL
|
|
hosts: postgres
|
|
become: true
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
- name: Installer les dépendances système
|
|
apt:
|
|
name:
|
|
- wget
|
|
- gnupg2
|
|
- lsb-release
|
|
- ca-certificates
|
|
- apt-transport-https
|
|
- acl # Nécessaire pour become_user
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Ajouter la clé GPG du dépôt PostgreSQL
|
|
apt_key:
|
|
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
|
|
state: present
|
|
|
|
- name: Ajouter le dépôt PostgreSQL
|
|
apt_repository:
|
|
repo: "deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main"
|
|
state: present
|
|
filename: pgdg
|
|
|
|
- name: Installer PostgreSQL {{ postgres_version }}
|
|
apt:
|
|
name:
|
|
- postgresql-{{ postgres_version }}
|
|
- postgresql-contrib-{{ postgres_version }}
|
|
- python3-psycopg2
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: S'assurer que PostgreSQL est démarré
|
|
systemd:
|
|
name: postgresql
|
|
state: started
|
|
enabled: yes
|
|
|
|
- name: Définir le mot de passe du user postgres
|
|
postgresql_user:
|
|
name: postgres
|
|
password: "{{ postgres_password }}"
|
|
state: present
|
|
become_user: postgres
|
|
|
|
- name: Créer les bases de données PostgreSQL
|
|
postgresql_db:
|
|
name: "{{ item.name }}"
|
|
owner: postgres
|
|
state: present
|
|
loop: "{{ postgres_databases }}"
|
|
become_user: postgres
|
|
|
|
- name: Configurer pg_hba.conf pour autoriser le backend
|
|
blockinfile:
|
|
path: "/etc/postgresql/{{ postgres_version }}/main/pg_hba.conf"
|
|
block: |
|
|
# Connexions locales
|
|
local all postgres peer
|
|
host all postgres 127.0.0.1/32 scram-sha-256
|
|
# Connexions backend LAN
|
|
host all postgres 192.168.1.0/24 scram-sha-256
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
|
notify: Redémarrer PostgreSQL
|
|
tags:
|
|
- reload
|
|
|
|
- name: Configurer PostgreSQL pour écouter sur toutes les interfaces
|
|
lineinfile:
|
|
path: "/etc/postgresql/{{ postgres_version }}/main/postgresql.conf"
|
|
regexp: "^#?listen_addresses"
|
|
line: "listen_addresses = '*'"
|
|
state: present
|
|
notify: Redémarrer PostgreSQL
|
|
tags:
|
|
- reload
|
|
|
|
handlers:
|
|
- name: Redémarrer PostgreSQL
|
|
systemd:
|
|
name: postgresql
|
|
state: restarted
|
|
tags:
|
|
- reload
|
|
|
|
# ============================================
|
|
# Redis Installation (vm-redis uniquement)
|
|
# ============================================
|
|
- name: Installation et configuration de Redis
|
|
hosts: redis
|
|
become: true
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
- name: Installer Redis
|
|
apt:
|
|
name:
|
|
- redis-server
|
|
- python3-redis
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Créer le répertoire de backup Redis
|
|
file:
|
|
path: /var/lib/redis/backup
|
|
state: directory
|
|
owner: redis
|
|
group: redis
|
|
mode: "0755"
|
|
|
|
- name: Configurer Redis - bind address (accepter connexions réseau)
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^bind"
|
|
line: "bind 127.0.0.1 192.168.1.62"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer Redis - port
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^port"
|
|
line: "port {{ redis_port }}"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer Redis - maxmemory
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^# ?maxmemory"
|
|
line: "maxmemory {{ redis_maxmemory }}"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer Redis - maxmemory-policy
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^# ?maxmemory-policy"
|
|
line: "maxmemory-policy {{ redis_maxmemory_policy }}"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer Redis - requirepass
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^# ?requirepass"
|
|
line: "requirepass {{ redis_password }}"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Activer AOF (Append Only File) pour Redis
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^appendonly"
|
|
line: "appendonly yes"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer la fréquence de sync AOF
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^# ?appendfsync"
|
|
line: "appendfsync everysec"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Activer la persistance RDB (snapshots)
|
|
blockinfile:
|
|
path: /etc/redis/redis.conf
|
|
block: |
|
|
save 900 1
|
|
save 300 10
|
|
save 60 10000
|
|
marker: "# {mark} ANSIBLE MANAGED RDB PERSISTENCE"
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer le nom du fichier AOF
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^appendfilename"
|
|
line: 'appendfilename "appendonly.aof"'
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Désactiver le mode protégé Redis
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^protected-mode"
|
|
line: "protected-mode no"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Configurer le répertoire de travail Redis
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^dir"
|
|
line: "dir /var/lib/redis"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: Définir le niveau de log
|
|
lineinfile:
|
|
path: /etc/redis/redis.conf
|
|
regexp: "^loglevel"
|
|
line: "loglevel notice"
|
|
state: present
|
|
notify: Redémarrer Redis
|
|
|
|
- name: S'assurer que Redis est démarré
|
|
systemd:
|
|
name: redis-server
|
|
state: started
|
|
enabled: yes
|
|
|
|
handlers:
|
|
- name: Redémarrer Redis
|
|
systemd:
|
|
name: redis-server
|
|
state: restarted
|