Premier commit

This commit is contained in:
gitea committed 2026-10-18 16:41:04 +02:00
commit 518c7ab04b
49 files changed
+1120

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
MariaDB installation with Ansible
=========
A brief description of the role goes here.
Requirements
------------
Ansible server + clients.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
https://pierreau.fr/pro/
https://www.linkedin.com/in/pierreau/
https://www.facebook.com/pierreau.pro
+2
View File
@@ -0,0 +1,2 @@
---
# defaults file for MariaDB
+3
View File
@@ -0,0 +1,3 @@
[client]
user=root
password=Ansible
+5
View File
@@ -0,0 +1,5 @@
CREATE TABLE mytable (
index_id INT NOT NULL AUTO_INCREMENT,
field1 VARCHAR(64),
PRIMARY KEY (index_id)
);
+1
View File
@@ -0,0 +1 @@
INSERT INTO mytable (field1) VALUES ('Texte1'),('Valeur1'),('Info3');
+7
View File
@@ -0,0 +1,7 @@
---
# handlers file for MariaDB
- name: restart mariadb
service:
name: mariadb
state: restarted
+29
View File
@@ -0,0 +1,29 @@
galaxy_info:
author: Pierre ROYER
description: Ansible role to deploy and manage MariaDB
min_ansible_version: 2.10
platforms:
- name: RedHat
versions:
- all
- name: Rocky Linux
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
version: "1.0"
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: MIT
galaxy_tags: []
dependencies: []
+22
View File
@@ -0,0 +1,22 @@
---
# MariaDB/tasks/backup_database.yml
- name: "Set timestamp of the backup"
set_fact:
now: "{{ lookup('pipe', 'date +%d%m%Y-%H:%M') }}"
- name: "Create a backup directory"
file:
path: "/tmp/{{ app_name }}/backups/{{ now }}/"
mode: 0777
owner: ansible
state: directory
- name: Backup the database
mysql_db:
name: "{{ mariadb_database }}"
state: dump
login_user: root
login_password: "{{ mariadb_root_password }}"
target: "/tmp/{{ app_name }}/backups/{{ now }}/{{ backup_file }}"
@@ -0,0 +1,38 @@
---
# MariaDB/tasks/configure_database.yml
- name: Remove {{ mariadb_database }} database
mysql_db:
name: "{{ mariadb_database }}"
state: absent
# après Update MariaDB root password
login_user: root
login_password: "{{ mariadb_root_password }}"
- name: Create {{ mariadb_database }} database
mysql_db:
name: "{{ mariadb_database }}"
state: present
login_user: root
login_password: "{{ mariadb_root_password }}"
- name: "Copy /files/{{ mariadb_table }} to hosts"
copy:
src: "{{ role_path }}/files/{{ mariadb_table }}"
dest: "/tmp/"
owner: "ansible"
group: "ansible"
- name: Create {{ mariadb_table }} table in {{ mariadb_database }} database
mysql_db:
name: "{{ mariadb_database }}"
login_user: root
login_password: "{{ mariadb_root_password }}"
target: "/tmp/{{ mariadb_table }}"
state: import
notify: restart mariadb
#- name: Remove mysql database
# mysql_db:
# name: "{{ mariadb_database }}"
# state: absent
+20
View File
@@ -0,0 +1,20 @@
---
# MariaDB/tasks/import_sql.yml
- name: "Copy Script.sql"
copy:
src: "{{ role_path }}/files/{{ sql_script_file }}"
dest: "/tmp/"
owner: "ansible"
group: "ansible"
- name: Import SQL script
mysql_db:
name: "{{ mariadb_database }}"
state: import
login_user: root
login_password: "{{ mariadb_root_password }}"
target: "/tmp/{{ sql_script_file }}"
# target: "{{ role_path }}/files/{{ sql_script_file }}"
notify: restart mariadb
+58
View File
@@ -0,0 +1,58 @@
---
# MariaDB/tasks/install_mariadb.yml
- name: Install MariaDB on RedHat based systems
package:
name: "{{ item }}"
state: present
with_items:
- mariadb-server
- mariadb
- python3-PyMySQL
when: (ansible_distribution == "Red Hat Entreprise Linux") or
(ansible_distribution == "Rocky") or
(ansible_distribution == "Fedora") or
(ansible_distribution == "AlmaLinux") or
(ansible_distribution == "openSUSE Leap")
- name: Install MariaDB on Debian/Ubuntu systems
package:
name: "{{ item }}"
state: present
with_items:
- mariadb-server
- mariadb-client
- python3-mysqldb
when: (ansible_distribution == "Ubuntu") or
(ansible_distribution == "Debian")
- name: Start and enable MariaDB service
service:
name: mariadb
state: started
enabled: yes
# mysql_secure_installation
#- name: Update MariaDB root password
# mysql_user: name=root host=localhost password={{mariadb_root_password}}
# with_items:
# - 127.0.0.1
# - ::1
# - VM
# mysql_secure_installation
- name: Update MariaDB root password
community.mysql.mysql_user:
login_user: root
login_password: ''
user: root
password: "{{ mariadb_root_password }}"
# mysql_secure_installation
- name: Remove MySQL test database
mysql_db:
name: test
state: absent
# après Update MariaDB root password
login_user: root
login_password: "{{ mariadb_root_password }}"
+9
View File
@@ -0,0 +1,9 @@
---
# MariaDB/tasks/main.yml
- include_tasks: install_mariadb.yml
- include_tasks: configure_database.yml
- include_tasks: import_sql.yml
- include_tasks: backup_database.yml
#- include_tasks: restore_database.yml
+10
View File
@@ -0,0 +1,10 @@
---
- name: Restore database from backup
mysql_db:
name: "{{ mariadb_database }}"
state: import
login_user: root
login_password: "{{ mariadb_root_password }}"
target: "{{ role_path }}/files/{{ backup_file }}"
notify: restart mariadb
+2
View File
@@ -0,0 +1,2 @@
localhost
+5
View File
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- MariaDB
+8
View File
@@ -0,0 +1,8 @@
---
# vars file for MariaDB
mariadb_root_password: "r00t_p@sswd"
mariadb_database: "MariaDB"
mariadb_table: "Create_table.sql"
sql_script_file: "Import.sql"
app_name: "MariaDB"
backup_file: "Backup.sql"