48 lines
1.3 KiB
YAML
48 lines
1.3 KiB
YAML
# apdb.yml
|
|
---
|
|
- hosts: all
|
|
become: true
|
|
tasks:
|
|
- name: 1. Installe une des dépendances d'une extension Ansible.
|
|
apt:
|
|
name: python3-pymysql
|
|
state: present
|
|
|
|
- name: 2. Créé la base de données vide.
|
|
community.mysql.mysql_db:
|
|
check_implicit_admin: true
|
|
name: sdis29
|
|
state: present
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
|
|
|
- name: 3. Créé l'utilisateur pour la BDD.
|
|
community.mysql.mysql_user:
|
|
name: reseau
|
|
password: Ilona21?
|
|
priv: 'sdis29.*:ALL,GRANT'
|
|
state: present
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
|
|
|
- name: 4. Vérifie si un répertoire db existe.
|
|
stat:
|
|
path: /home/debian/db
|
|
register: rept_stat
|
|
|
|
- name: 5. Créé le répertoire db pour le fichier sql.
|
|
command: mkdir /home/debian/db
|
|
when: rept_stat.stat.exists == false
|
|
|
|
- name: 6. Copie le fichier d'import de la base de données
|
|
template:
|
|
src: db/sdis29.sql
|
|
dest: /home/debian/db/sdis29.sql
|
|
|
|
- name: 7. Import de la base de données.
|
|
run_once: true
|
|
community.mysql.mysql_db:
|
|
state: import
|
|
name: all
|
|
encoding: utf8
|
|
target: db/sdis29.sql
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|