Zack Williams | 49e8860 | 2020-10-14 22:17:13 -0700 | [diff] [blame] | 1 | --- |
| 2 | # mariadb tasks/main.yml |
| 3 | # |
| 4 | # SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org> |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
| 7 | - name: include OS-specific vars |
| 8 | include_vars: "{{ ansible_os_family }}.yml" |
| 9 | |
| 10 | - name: include OS-specific tasks |
| 11 | include_tasks: "{{ ansible_os_family }}.yml" |
| 12 | |
| 13 | - name: Enable MariaDB Service |
| 14 | service: |
| 15 | name: "{{ mariadb_service }}" |
| 16 | enabled: true |
| 17 | notify: |
| 18 | - start-mariadb |
| 19 | |
| 20 | - name: Flush handlers to start MariaDB |
| 21 | meta: flush_handlers |
| 22 | |
| 23 | # Secure the installation |
| 24 | |
| 25 | - name: Set root user password |
| 26 | mysql_user: |
| 27 | name: root |
| 28 | password: "{{ mariadb_root_password }}" |
| 29 | host_all: true |
| 30 | login_unix_socket: /var/run/mysqld/mysqld.sock |
| 31 | no_log: true |
| 32 | |
| 33 | - name: Create root ~/.my.cnf file to specify new password |
| 34 | template: |
| 35 | src: user.my.cnf.j2 |
| 36 | dest: "{{ ansible_env.HOME }}/.my.cnf" |
| 37 | owner: root |
| 38 | group: root |
| 39 | mode: 0600 |
| 40 | |
| 41 | - name: Remove all anonymous users |
| 42 | mysql_user: |
| 43 | name: '' |
| 44 | host_all: true |
| 45 | state: absent |
| 46 | no_log: true |
| 47 | |
| 48 | - name: Remove default test database |
| 49 | mysql_db: |
| 50 | name: test |
| 51 | state: absent |
| 52 | |
| 53 | # Create databases |
| 54 | - name: Create databases |
| 55 | mysql_db: |
| 56 | name: "{{ item.name }}" |
| 57 | with_items: "{{ mariadb_databases }}" |
| 58 | |
| 59 | # Create users |
| 60 | - name: Create users |
| 61 | mysql_user: |
| 62 | name: "{{ item.name }}" |
| 63 | password: "{{ item.password }}" |
| 64 | host: localhost |
| 65 | priv: "{{ item.priv }}" |
| 66 | no_log: true |
| 67 | with_items: "{{ mariadb_users }}" |