2018-10-31 08:07:38 +00:00
- name: 'Install MySQL packages : mariadb-server, mariadb-client, python-mysqldb and 8 php packages (debuntu)'
2018-10-28 16:03:35 +00:00
package :
name :
- mariadb-server
- mariadb-client
2019-10-31 11:38:00 +00:00
# - python-mysqldb
2018-10-28 16:03:35 +00:00
- php{{ php_version }}
- php{{ php_version }}-mysql
- php-pear
- php{{ php_version }}-gd
- php{{ php_version }}-imap
- php{{ php_version }}-ldap
- php{{ php_version }}-odbc
#- php{{ php_version }}-xml
- php{{ php_version }}-xmlrpc
state : present
2019-05-24 22:33:10 +00:00
when : is_debuntu | bool
2018-10-28 16:03:35 +00:00
tags :
- download
2017-05-27 18:09:50 +00:00
2019-07-03 14:08:19 +00:00
- name : Install php{{ php_version }}-xml (ubuntu or debian 9+)
2018-10-28 16:03:35 +00:00
package :
name : "php{{ php_version }}-xml"
state : present
2019-07-03 14:08:19 +00:00
when : is_ubuntu or (is_debian and not is_debian_8)
2017-07-18 02:46:30 +00:00
2018-10-31 07:42:08 +00:00
- name : Install php-xml-parser (debian-8)
2018-10-28 16:03:35 +00:00
package :
2018-10-31 07:42:08 +00:00
name : php-xml-parser
2018-10-28 16:03:35 +00:00
state : present
2019-05-24 22:33:10 +00:00
when : is_debian_8 | bool
2017-07-18 02:46:30 +00:00
2018-10-31 07:42:08 +00:00
- name : "Install packages: mysql, MySQL-python and 9 php packages (OS's other than debuntu)"
2018-10-28 16:03:35 +00:00
package :
name :
- MySQL-python
- mysql
- php
- php-mysql
- php-pear
- php-gd
- php-imap
- php-ldap
- php-odbc
- php-xml
- php-xmlrpc
state : present
when : not is_debuntu
tags :
- download
2017-05-27 18:09:50 +00:00
2018-10-28 16:03:35 +00:00
- include_tasks : centos.yml
when : ansible_distribution == "CentOS"
tags :
- download
2017-05-27 18:09:50 +00:00
2018-10-28 16:03:35 +00:00
- include_tasks : fedora.yml
when : ansible_distribution == "Fedora"
tags :
- download
2017-05-27 18:09:50 +00:00
2019-07-03 18:06:57 +00:00
# 2019-07-03 @jvonau @holta: the next 50 lines (6 stanzas) double MariaDB's
# default boot timeout (90s to 180s) for slow CPUs like this Ubuntu 18.04.2 VM:
2019-07-03 16:57:05 +00:00
# https://github.com/iiab/iiab/issues/1802
# https://mariadb.com/kb/en/library/what-to-do-if-mariadb-doesnt-start/#systemd
2019-07-03 14:45:11 +00:00
- name : Check if /lib/systemd/system/mariadb.service exists
stat :
path : /lib/systemd/system/mariadb.service
register : mariadb_unit_file
2019-07-03 18:06:57 +00:00
- name : Copy pkg's /lib/systemd/system/mariadb.service to /etc/systemd/system/ to be customized (CREATES TIMETAMPED BACKUPS OF /etc/systemd/system/mariadb.service e.g. IF OPERATOR CUSTOMIZED IT, EVEN DESPITE WARNING BELOW!)
2019-07-03 16:57:05 +00:00
copy :
force : yes
2019-07-03 17:18:03 +00:00
backup : yes
2019-07-03 16:57:05 +00:00
src : /lib/systemd/system/mariadb.service
dest : /etc/systemd/system/
when : mariadb_unit_file.stat.exists
2019-07-03 15:48:54 +00:00
2019-07-03 16:57:05 +00:00
- name : Symlink /etc/systemd/system/mysql.service -> /etc/systemd/system/mariadb.service
file :
state : link
force : yes
src : /etc/systemd/system/mariadb.service
path : /etc/systemd/system/mysql.service
when : mariadb_unit_file.stat.exists
- name : Symlink /etc/systemd/system/mysqld.service -> /etc/systemd/system/mariadb.service
file :
state : link
force : yes
src : /etc/systemd/system/mariadb.service
path : /etc/systemd/system/mysqld.service
when : mariadb_unit_file.stat.exists
2019-07-03 18:06:57 +00:00
- name : "WARN OPERATOR: Changes made to /etc/systemd/system/mariadb.service WILL BE LOST whenever 'mysql' playbook is run"
lineinfile :
path : /etc/systemd/system/mariadb.service
insertbefore : BOF # Beginning of file
line : "# WARNING: CHANGES TO THIS FILE WILL BE REGULARLY *OVERWRITTEN* BY:\n# /opt/iiab/iiab/roles/mysql/tasks/main.yml\n"
when : mariadb_unit_file.stat.exists
2019-07-03 16:57:05 +00:00
- name : Set systemd boot timeout to 180 seconds for slow machines, in /etc/systemd/system/mariadb.service
2019-07-03 14:45:11 +00:00
lineinfile :
2019-07-03 16:57:05 +00:00
path : /etc/systemd/system/mariadb.service
2019-07-03 15:48:54 +00:00
insertafter : '^\[Service\]$'
2019-07-03 18:06:57 +00:00
regexp : "^TimeoutStartSec="
2019-07-03 18:44:11 +00:00
line : "\n# 2019-07-03: @jvonau @holta doubled MariaDB's default boot timeout, from\n# 90 seconds to 180 seconds, for slow machines like this Ubuntu 18.04.2 VM:\n# https://github.com/iiab/iiab/issues/1802\n# https://mariadb.com/kb/en/library/what-to-do-if-mariadb-doesnt-start/#systemd\nTimeoutStartSec=180\n"
2019-07-03 18:36:42 +00:00
# If the line above were to be run repeatedly (never happens here!) Ansible
# would pollute MariaDB's systemd unit file. As multi-line regexp's are
# not allowed (both regexp's should match, for idempotency). If nec, use
# the 1-liner below, or Ansible's 'blockinfile' which pollutes config files
# in its own way...surrounding blocks with marker lines.
# line: "TimeoutStartSec=180"
2019-07-03 14:45:11 +00:00
when : mariadb_unit_file.stat.exists
2019-07-03 14:08:19 +00:00
2019-07-03 18:06:57 +00:00
2019-07-03 14:25:19 +00:00
# Name of MySQL service varies by OS, so hardcoded in /opt/iiab/iiab/vars/<OS>.yml (formerly in roles/0-init/tasks/main.yml)
2019-07-03 14:08:19 +00:00
- name : Enable & Start MySQL systemd service ({{ mysql_service }}) if mysql_enabled
2018-10-31 07:42:08 +00:00
systemd :
2018-10-28 16:03:35 +00:00
name : "{{ mysql_service }}"
2019-07-03 14:25:19 +00:00
daemon_reload : yes
2019-07-03 16:07:37 +00:00
state : restarted
2018-10-28 16:03:35 +00:00
enabled : yes
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
# 'localhost' needs to be the last item for idempotency, see
# http://ansible.cc/docs/modules.html#mysql-user
# unfortunately it still doesn't work
2018-10-31 07:42:08 +00:00
- name : Update MySQL root password for localhost root accounts, if mysql_enabled
2018-10-28 16:03:35 +00:00
mysql_user :
name : root
2018-10-31 07:42:08 +00:00
host : localhost
2018-10-28 16:03:35 +00:00
password : "{{ mysql_root_password }}"
priv : "*.*:ALL,GRANT"
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Install .my.cnf file from template, with root password credentials, if mysql_enabled
2018-10-28 16:03:35 +00:00
template :
src : my.cnf.j2
dest : /root/.my.cnf
owner : root
mode : 0600
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Update MySQL root password for all remaining root accounts (127.0.0.1, ::1) if mysql_enabled
2018-10-28 16:03:35 +00:00
mysql_user :
name : root
host : "{{ item }}"
password : "{{ mysql_root_password }}"
priv : "*.*:ALL,GRANT"
with_items :
#- "{{ iiab_hostname }}.{{ iiab_domain }}"
- 127.0 .0 .1
- : : 1
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Delete anonymous MySQL server user for {{ ansible_hostname }}, if mysql_enabled
2018-10-28 16:03:35 +00:00
mysql_user :
user : ""
host : "{{ ansible_hostname }}"
state : absent
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Delete anonymous MySQL server user for localhost, if mysql_enabled
2018-10-28 16:03:35 +00:00
mysql_user :
user : ""
state : absent
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Remove the MySQL 'test' database, if mysql_enabled
2018-10-28 16:03:35 +00:00
mysql_db :
db : test
state : absent
2019-05-24 22:33:10 +00:00
when : mysql_enabled | bool
2017-05-27 18:09:50 +00:00
# we had to start mysql in order to configure it, now turn if off if not enabled
2018-10-31 07:42:08 +00:00
- name : Config is done but now DISABLE MySQL service, if not mysql_enabled
systemd :
2018-10-28 16:03:35 +00:00
name : "{{ mysql_service }}"
enabled : no
state : stopped
when : not mysql_enabled
2017-05-27 18:09:50 +00:00
2018-10-31 07:42:08 +00:00
- name : Add 'mysql' variable values to {{ iiab_ini_file }}
2018-10-28 16:03:35 +00:00
ini_file :
2018-10-31 07:42:08 +00:00
path : "{{ iiab_ini_file }}"
2018-10-28 16:03:35 +00:00
section : mysql
option : "{{ item.option }}"
value : "{{ item.value }}"
with_items :
- option : name
value : MySQL
- option : description
value : '"MySQL is a widely used free and open source (GPLv2) database, offered by most web hosting services, on a diversity of platforms."'
- option : enabled
value : "{{ mysql_enabled }}"