From 6c9fbf5983468861c8f9eb83cfb7f773bd2dda2a Mon Sep 17 00:00:00 2001 From: Rosario-Francesco Polito Date: Thu, 20 Jan 2022 16:08:51 +0100 Subject: [PATCH] installing and configuring db --- group_vars/all/vars.yml | 6 +++++- my.cnf | 2 +- tasks/shopware.yml | 44 ++++++++++++----------------------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml index 912c1e7..29fcc59 100644 --- a/group_vars/all/vars.yml +++ b/group_vars/all/vars.yml @@ -1 +1,5 @@ -username: YOUR_USERNAME \ No newline at end of file +username: rpolito +shopware_root_username: root +shopware_root_pass: rootpass +shopware_db_username: shopware +shopware_db_pass: shopware_pw \ No newline at end of file diff --git a/my.cnf b/my.cnf index 088d375..e3a4ed8 100644 --- a/my.cnf +++ b/my.cnf @@ -21,6 +21,6 @@ # Import all .cnf files from configuration directory !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mariadb.conf.d/ -#[client] +[client] user=root password=rootpass diff --git a/tasks/shopware.yml b/tasks/shopware.yml index 1c23c34..bb80b71 100644 --- a/tasks/shopware.yml +++ b/tasks/shopware.yml @@ -26,49 +26,29 @@ - name: update mariadb root user mysql_user: login_unix_socket: /var/run/mysqld/mysqld.sock - #login_host: "{{shopware_db_username}}" - login_user: "root" - login_password: "rootpass" - name: "{{shopware_db_username}}" - password: "{{shopware_db_pass}}" + login_user: "{{shopware_root_username}}" + login_password: "{{shopware_root_pass}}" + name: "{{shopware_root_username}}" + password: "{{shopware_root_pass}}" check_implicit_admin: yes state: present +- name: Restart service httpd, in all cases + ansible.builtin.service: + name: mariadb + state: restarted + - name: Make sure service is started and enabled systemd: name: mariadb state: started enabled: yes -- name: Delete all anonymous SQL user accounts - mysql_user: - user: "" - host_all: yes - state: absent - - name: Remove the SQL test database - mysql_db: + community.mysql.mysql_db: db: "test" state: absent - -- name: Change root user password on first run - mysql_user: - login_user: root - login_password: '' - name: root - password: "{{ shopware_db_pass }}" - priv: "*.*:ALL,GRANT" - host: "{{ item }}" - with_items: - - "{{ ansible_hostname }}" - - "127.0.0.1" - - "::1" - - "localhost" - -- name: Make sure user exists - shell: - cmd: "mysql -uroot -p{{ shopware_db_pass }} -e\"CREATE USER IF NOT EXISTS '{{ shopware_db_username }}'@'localhost' IDENTIFIED BY '{{ shopware_db_pass }}' REQUIRE SSL;\" -N -B" - register: result + config_file: /etc/mysql/my.cnf - name: Create Database become: yes @@ -80,6 +60,8 @@ - name: Create user with password, all database privileges and 'WITH GRANT OPTION' shopware database become: yes community.mysql.mysql_user: + login_user: "{{shopware_root_username}}" + login_password: "{{shopware_root_pass}}" state: present name: "{{shopware_db_username}}" password: "{{shopware_db_pass}}"