Added all

This commit is contained in:
2026-05-20 18:52:35 +02:00
commit 2c6c4242ce
41 changed files with 868 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
---
- name: Instalar paquetes de la base de datos
ansible.builtin.apt:
name: "{{ packages_database }}"
state: present
update_cache: yes
notify: Reiniciar MySQL
- name: Corregir permisos de /etc/mysql/my.cnf
ansible.builtin.file:
path: /etc/mysql/my.cnf
owner: root
group: root
mode: '0644'
- name: Configurar /etc/mysql/my.cnf correctament
ansible.builtin.copy:
dest: /etc/mysql/my.cnf
content: |
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
owner: root
group: root
mode: '0644'
notify: Reiniciar MySQL
- name: Configurar bind-address per acceptar connexions remotes
ansible.builtin.lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '^bind-address'
line: 'bind-address = 0.0.0.0'
notify: Reiniciar MySQL
- name: Configurar mysqlx-bind-address
ansible.builtin.lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '^mysqlx-bind-address'
line: 'mysqlx-bind-address = 0.0.0.0'
notify: Reiniciar MySQL
- name: Assegurar que MySQL està en execució
ansible.builtin.service:
name: mysql
state: started
enabled: yes
- name: Flush handlers (reinicia MySQL abans de crear usuaris)
ansible.builtin.meta: flush_handlers
# ✅ Crear /root/.my.cnf perquè community.mysql pugui autenticar-se
- name: Crear /root/.my.cnf amb credencials de root
ansible.builtin.copy:
dest: /root/.my.cnf
content: |
[client]
user=root
password={{ db_root_password }}
owner: root
group: root
mode: '0600'
- name: DEBUG - Mostrar contrasenya que usa Ansible
ansible.builtin.debug:
msg: "db_root_password = '{{ db_root_password }}'"
- name: Crear la base de dades de WordPress
community.mysql.mysql_db:
name: "{{ db_name }}"
state: present
login_user: root
login_password: "{{ db_root_password }}"
- name: Crear l'usuari de WordPress amb accés remot
community.mysql.mysql_user:
name: "{{ db_user }}"
password: "{{ db_password }}"
priv: "{{ db_name }}.*:ALL"
host: "%"
state: present
login_user: root
login_password: "{{ db_root_password }}"
# ✅ Eliminar /root/.my.cnf per seguretat un cop acabat
- name: Eliminar /root/.my.cnf per seguretat
ansible.builtin.file:
path: /root/.my.cnf
state: absent