infra/home/ansible/setup-wavelog-db.yml
2025-09-18 16:08:26 -05:00

47 lines
No EOL
1.5 KiB
YAML

---
- name: Setup Wavelog Database in MariaDB
hosts: lab02
become: true
vars:
mysql_container_id: 301
wavelog_password: "m4icNmGTRtOMgrNxsxEdrw"
tasks:
- name: Create Wavelog database and user
shell: |
pct exec {{ mysql_container_id }} -- bash -c "mysql -u root <<EOF
CREATE DATABASE IF NOT EXISTS wavelog;
CREATE USER IF NOT EXISTS 'wavelog'@'%' IDENTIFIED BY '{{ wavelog_password }}';
GRANT ALL PRIVILEGES ON wavelog.* TO 'wavelog'@'%';
FLUSH PRIVILEGES;
EOF"
register: db_creation
ignore_errors: yes
- name: If root needs password, try with socket authentication
shell: |
pct exec {{ mysql_container_id }} -- bash -c "mysql <<EOF
CREATE DATABASE IF NOT EXISTS wavelog;
CREATE USER IF NOT EXISTS 'wavelog'@'%' IDENTIFIED BY '{{ wavelog_password }}';
GRANT ALL PRIVILEGES ON wavelog.* TO 'wavelog'@'%';
FLUSH PRIVILEGES;
EOF"
when: db_creation.rc != 0
- name: Test Wavelog database connection
shell: |
pct exec {{ mysql_container_id }} -- mysql -u wavelog -p'{{ wavelog_password }}' -e "SELECT DATABASE();" wavelog
register: test_result
ignore_errors: yes
- name: Display result
debug:
msg: |
Database setup completed!
Host: 10.0.19.6
Port: 3306
Database: wavelog
Username: wavelog
Password: {{ wavelog_password }}
Test result: {{ test_result.stdout | default('Failed to connect') }}