- name: Install MariaDB
  apt:
    name: "{{ item }}"
    state: present
  loop:
    - mariadb-server
    - python3-pymysql

- name: Start and Enable MariaDB
  service:
    name: mysql
    state: started
    enabled: yes

- name: Set MariaDB root Password
  mysql_user:
    login_user: root
    login_password: "{{ mysql_root_password }}"
    user: root
    password: "{{ mysql_root_password }}"
    check_implicit_admin: yes
    login_unix_socket: /var/run/mysqld/mysqld.sock
  when: mysql_root_password is defined

- name: Create WordPress User
  mysql_user:
    login_user: root
    login_password: "{{ mysql_root_password }}"
    user: "{{ wp_db_user }}"
    password: "{{ wp_db_password }}"
    priv: "*.*:ALL"
    host: localhost
    state: present

- name: Create WordPress Database
  mysql_db:
    login_user: root
    login_password: "{{ mysql_root_password }}"
    name: "{{ wp_db_name }}"
    state: present
    encoding: utf8
    collation: utf8_general_ci
