Browse Source

Cleanup/additions/improvements: - Broke variables out into distro / defaults files - Add mysql_root_password to defaults (empty) - Add mysql_users variable with comment about how to use it - Add Debian OS family support - Update package lists to be variables - Add enable to tasks (removed from handler so it now works) - Add processing of mysql_users so additional user accounts are setup by the role

- Add flag for mysql_secure_installation being complete which can cause breakage with other tasks if not careful
master
Mike Crosson 5 years ago
parent
commit
57fde7b95c
6 changed files with 48 additions and 9 deletions
  1. +3
    -0
      defaults/main.yml
  2. +1
    -1
      handlers/main.yml
  3. +34
    -8
      tasks/main.yml
  4. +4
    -0
      vars/Arch.yml
  5. +5
    -0
      vars/Debian.yml
  6. +1
    -0
      vars/default.yml

+ 3
- 0
defaults/main.yml View File

@ -1,3 +1,6 @@
mysql_secure_installation_done: False
mysql_root_password: ''
#mysql_users: {} # Add host/group var with a dictionay of user:password entries
mysqld:
- socket: "/run/mysqld/mysqld.sock"
- bind-address: "127.0.0.1"

+ 1
- 1
handlers/main.yml View File

@ -15,4 +15,4 @@
action: file dest=/tmp/mysql_secure_installation state=absent
- name: restart mysql
action: service name=mysqld state=restarted enabled=yes
action: service name="{{ mysql_daemon }}" state=restarted

+ 34
- 8
tasks/main.yml View File

@ -1,21 +1,27 @@
---
- name: download maria db (mysql) and clients
- include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_os_family}}.yml"
- default.yml
- name: install maria db (mysql) and clients
tags:
- pkg_download
yaourt: name={{ item }} download_only=yes
- pkg_install
pacman: name={{ item }} state=present
notify:
- mysql_secure_installation
with_items:
- mariadb
- mariadb-clients
- "{{ mysql_package_list_arch }}"
when: ansible_os_family == "Arch"
- name: install maria db (mysql) and clients
tags:
- pkg_install
pacman: name={{ item }} state=present
apt: name={{ item }} state=present
notify:
- mysql_secure_installation
with_items:
- mariadb
- mariadb-clients
- "{{ mysql_package_list_debian }}"
- name: write config
tags:
@ -30,3 +36,23 @@
action: template src=client.cnf.j2 dest=/etc/mysql/client.cnf
notify:
- restart mysql
- name: enable mysql/mariadb service
tags:
- pkg_config
service: name="{{ mysql_daemon }}" enabled=yes
- name: setup non-root users
tags:
- pkg_config
mysql_user: "name={{ item.key }} password={{ item.value }}"
with_dict: mysql_users
when: not mysql_secure_installation_done
- name: setup non-root users
tags:
- pkg_config
mysql_user: "name={{ item.key }} password={{ item.value }}
login_user=root login_password={{ mysql_root_password }}"
with_dict: mysql_users
when: mysql_secure_installation_done

+ 4
- 0
vars/Arch.yml View File

@ -0,0 +1,4 @@
mysql_package_list_arch:
- mariadb
- mariadb-clients
mysql_daemon: mysqld

+ 5
- 0
vars/Debian.yml View File

@ -0,0 +1,5 @@
mysql_package_list_debian:
- mariadb-server
- mariadb-client
- python-mysqldb
mysql_daemon: mysql

+ 1
- 0
vars/default.yml View File

@ -0,0 +1 @@
default.yml