ansible/roles/database/tasks/secure_install.yml (30 lines of code) (raw):
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
---
# The following works but its not idemmpotent
- name: Set password for root user
mysql_user:
# you can get socket path from /etc/mysql/mysql.conf.d/mysqld.cnf
check_implicit_admin: yes
login_unix_socket: /var/run/mysqld/mysqld.sock # default path
login_user: root
login_password: "{{ custos_core_spring_datasource_password }}"
name: root
password: "{{ custos_core_spring_datasource_password }}"
priv: '*.*:ALL,GRANT'
host: 'localhost'
state: present
become: yes
- name: Copy .my.cnf file
template: src=my.cnf.j2 dest="{{ user_home }}/.my.cnf"
become: yes
become_user: "{{ user }}"
- name: Removes all anonymous user accounts
mysql_user: name='' host_all=yes state=absent login_password="{{ custos_core_spring_datasource_password }}"
become: yes
become_user: "{{ user }}"
- name: Secures the MySQL root user for all hosts
mysql_user: user=root login_password="{{ custos_core_spring_datasource_password }}" host_all=yes
become: yes
become_user: "{{ user }}"
- name: Removes the MySQL test database
mysql_db: db=test state=absent login_password="{{ custos_core_spring_datasource_password }}"
become: yes
become_user: "{{ user }}"
...