mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
Cleaner Dependencies e.g. for Sugarizer, Moodle, Node-Red, PBX, Elgg
This commit is contained in:
parent
106558aca9
commit
027832889b
88 changed files with 1212 additions and 909 deletions
183
roles/mysql/tasks/install.yml
Normal file
183
roles/mysql/tasks/install.yml
Normal file
|
@ -0,0 +1,183 @@
|
|||
# Stanzas as of 2020-02-04:
|
||||
#
|
||||
# - 4 base install
|
||||
# - Remove the last 3 above, as CentOS & Fedora no longer supported ?
|
||||
# - 6 double timeout for slow CPUs
|
||||
# - 7 DB config
|
||||
# - 2 record as installed
|
||||
|
||||
- name: 'Install MySQL packages: mariadb-server, mariadb-client, and 9 php packages (debuntu)'
|
||||
package:
|
||||
name:
|
||||
- mariadb-server
|
||||
- mariadb-client
|
||||
- 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 # Was below
|
||||
- php{{ php_version }}-xmlrpc
|
||||
state: present
|
||||
when: is_debuntu | bool
|
||||
|
||||
# - name: Install package 'php{{ php_version }}-xml' (debuntu) # WAS: (ubuntu or debian 9+)
|
||||
# package:
|
||||
# name: "php{{ php_version }}-xml"
|
||||
# state: present
|
||||
# when: is_debuntu | bool
|
||||
# #when: is_ubuntu or (is_debian and not is_debian_8)
|
||||
|
||||
#- name: Install php-xml-parser (debian-8)
|
||||
# package:
|
||||
# name: php-xml-parser
|
||||
# state: present
|
||||
# when: is_debian_8 | bool
|
||||
|
||||
- name: "Install packages: mysql, MySQL-python and 9 php packages (OS's other than debuntu)"
|
||||
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
|
||||
|
||||
- include_tasks: centos.yml
|
||||
when: ansible_distribution == "CentOS"
|
||||
|
||||
- include_tasks: fedora.yml
|
||||
when: ansible_distribution == "Fedora"
|
||||
|
||||
|
||||
# 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:
|
||||
# https://github.com/iiab/iiab/issues/1802
|
||||
# https://mariadb.com/kb/en/library/what-to-do-if-mariadb-doesnt-start/#systemd
|
||||
|
||||
- name: Check if /lib/systemd/system/mariadb.service exists
|
||||
stat:
|
||||
path: /lib/systemd/system/mariadb.service
|
||||
register: mariadb_unit_file
|
||||
|
||||
- name: Copy pkg's /lib/systemd/system/mariadb.service to /etc/systemd/system/ to be customized (CREATES TIMESTAMPED BACKUPS OF /etc/systemd/system/mariadb.service e.g. IF OPERATOR CUSTOMIZED IT, EVEN DESPITE WARNING BELOW!)
|
||||
copy:
|
||||
force: yes
|
||||
backup: yes
|
||||
src: /lib/systemd/system/mariadb.service
|
||||
dest: /etc/systemd/system/
|
||||
when: mariadb_unit_file.stat.exists
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- name: Set systemd boot timeout to 180 seconds for slow machines, in /etc/systemd/system/mariadb.service
|
||||
lineinfile:
|
||||
path: /etc/systemd/system/mariadb.service
|
||||
insertafter: '^\[Service\]$'
|
||||
regexp: "^TimeoutStartSec="
|
||||
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"
|
||||
# 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"
|
||||
when: mariadb_unit_file.stat.exists
|
||||
|
||||
|
||||
# 7 STANZAS BELOW...could later be put into setup.yml or config.yml or or provision.yml ?
|
||||
|
||||
# Name of MySQL service varies by OS, so hardcoded in /opt/iiab/iiab/vars/<OS>.yml (formerly in roles/0-init/tasks/main.yml)
|
||||
- name: Start MySQL systemd service ({{ mysql_service }}) to permit configuration
|
||||
systemd:
|
||||
name: "{{ mysql_service }}"
|
||||
daemon_reload: yes
|
||||
state: restarted
|
||||
|
||||
- name: Install /root/.my.cnf file from template, with root password credentials
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/.my.cnf
|
||||
owner: root
|
||||
mode: '0600'
|
||||
|
||||
# 'localhost' needs to be the last item for idempotency, see
|
||||
# http://ansible.cc/docs/modules.html#mysql-user
|
||||
# unfortunately it still doesn't work
|
||||
- name: Update MySQL root password for localhost root accounts
|
||||
mysql_user:
|
||||
name: root
|
||||
host: localhost
|
||||
password: "{{ mysql_root_password }}"
|
||||
priv: "*.*:ALL,GRANT"
|
||||
|
||||
- name: Update MySQL root password for all remaining root accounts (127.0.0.1, ::1)
|
||||
mysql_user:
|
||||
name: root
|
||||
host: "{{ item }}"
|
||||
password: "{{ mysql_root_password }}"
|
||||
priv: "*.*:ALL,GRANT"
|
||||
with_items:
|
||||
#- "{{ iiab_hostname }}.{{ iiab_domain }}"
|
||||
- 127.0.0.1
|
||||
- ::1
|
||||
|
||||
- name: Delete anonymous MySQL server user for {{ ansible_hostname }}
|
||||
mysql_user:
|
||||
user: ""
|
||||
host: "{{ ansible_hostname }}"
|
||||
state: absent
|
||||
|
||||
- name: Delete anonymous MySQL server user for localhost
|
||||
mysql_user:
|
||||
user: ""
|
||||
state: absent
|
||||
|
||||
- name: Remove the MySQL 'test' database
|
||||
mysql_db:
|
||||
db: test
|
||||
state: absent
|
||||
|
||||
|
||||
# RECORD MySQL AS INSTALLED
|
||||
|
||||
- name: "Set 'mysql_installed: True'"
|
||||
set_fact:
|
||||
mysql_installed: True
|
||||
|
||||
- name: "Add 'mysql_installed: True' to {{ iiab_state_file }}"
|
||||
lineinfile:
|
||||
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
|
||||
regexp: '^mysql_installed'
|
||||
line: 'mysql_installed: True'
|
|
@ -1,194 +1,46 @@
|
|||
# TO DO:
|
||||
# - Validate input vars mysql_install & mysql_enabled
|
||||
# - Put ~13 stanzas just below into install.yml
|
||||
# - Triggered by... 'when: mysql_installed is undefined'
|
||||
# - Eliminate stale Fedora/CentOS code & gratuitous when: is_debuntu clauses?
|
||||
# - Put ~8 stanzas below that into enable-or-disable.yml
|
||||
# "How do i fail a task in Ansible if the variable contains a boolean value?
|
||||
# I want to perform input validation for Ansible playbooks"
|
||||
# https://stackoverflow.com/questions/46664127/how-do-i-fail-a-task-in-ansible-if-the-variable-contains-a-boolean-value-i-want/46667499#46667499
|
||||
|
||||
- name: 'Install MySQL packages: mariadb-server, mariadb-client, and 8 php packages (debuntu)'
|
||||
package:
|
||||
name:
|
||||
- mariadb-server
|
||||
- mariadb-client
|
||||
- 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
|
||||
when: is_debuntu | bool
|
||||
# We assume 0-init/tasks/validate_vars.yml has DEFINITELY been run, so no need
|
||||
# to re-check whether vars are defined here. As Ansible vars cannot be unset:
|
||||
# https://serverfault.com/questions/856729/how-to-destroy-delete-unset-a-variable-value-in-ansible
|
||||
|
||||
- name: Install package 'php{{ php_version }}-xml' (debuntu) # WAS: (ubuntu or debian 9+)
|
||||
package:
|
||||
name: "php{{ php_version }}-xml"
|
||||
state: present
|
||||
when: is_debuntu | bool
|
||||
#when: is_ubuntu or (is_debian and not is_debian_8)
|
||||
- name: Assert that "mysql_install is sameas true" (boolean not string etc)
|
||||
assert:
|
||||
that: mysql_install is sameas true
|
||||
fail_msg: "PLEASE SET 'mysql_install: True' e.g. IN: /etc/iiab/local_vars.yml"
|
||||
quiet: yes
|
||||
|
||||
#- name: Install php-xml-parser (debian-8)
|
||||
# package:
|
||||
# name: php-xml-parser
|
||||
# state: present
|
||||
# when: is_debian_8 | bool
|
||||
- name: Assert that "mysql_enabled | type_debug == 'bool'" (boolean not string etc)
|
||||
assert:
|
||||
that: mysql_enabled | type_debug == 'bool'
|
||||
fail_msg: "PLEASE GIVE VARIABLE 'mysql_enabled' A PROPER (UNQUOTED) ANSIBLE BOOLEAN VALUE e.g. IN: /etc/iiab/local_vars.yml"
|
||||
quiet: yes
|
||||
|
||||
- name: "Install packages: mysql, MySQL-python and 9 php packages (OS's other than debuntu)"
|
||||
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
|
||||
|
||||
- include_tasks: centos.yml
|
||||
when: ansible_distribution == "CentOS"
|
||||
|
||||
- include_tasks: fedora.yml
|
||||
when: ansible_distribution == "Fedora"
|
||||
- debug:
|
||||
var: mysql_install
|
||||
- debug:
|
||||
var: mysql_enabled
|
||||
- debug:
|
||||
var: mysql_installed
|
||||
|
||||
|
||||
# 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:
|
||||
# https://github.com/iiab/iiab/issues/1802
|
||||
# https://mariadb.com/kb/en/library/what-to-do-if-mariadb-doesnt-start/#systemd
|
||||
|
||||
- name: Check if /lib/systemd/system/mariadb.service exists
|
||||
stat:
|
||||
path: /lib/systemd/system/mariadb.service
|
||||
register: mariadb_unit_file
|
||||
|
||||
- name: Copy pkg's /lib/systemd/system/mariadb.service to /etc/systemd/system/ to be customized (CREATES TIMESTAMPED BACKUPS OF /etc/systemd/system/mariadb.service e.g. IF OPERATOR CUSTOMIZED IT, EVEN DESPITE WARNING BELOW!)
|
||||
copy:
|
||||
force: yes
|
||||
backup: yes
|
||||
src: /lib/systemd/system/mariadb.service
|
||||
dest: /etc/systemd/system/
|
||||
when: mariadb_unit_file.stat.exists
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- name: Set systemd boot timeout to 180 seconds for slow machines, in /etc/systemd/system/mariadb.service
|
||||
lineinfile:
|
||||
path: /etc/systemd/system/mariadb.service
|
||||
insertafter: '^\[Service\]$'
|
||||
regexp: "^TimeoutStartSec="
|
||||
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"
|
||||
# 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"
|
||||
when: mariadb_unit_file.stat.exists
|
||||
- name: Install MySQL if 'mysql_installed' not defined, e.g. in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml
|
||||
include_tasks: install.yml
|
||||
when: mysql_installed is undefined
|
||||
|
||||
|
||||
# RECORD MySQL AS INSTALLED
|
||||
|
||||
- name: "Set 'mysql_installed: True'"
|
||||
set_fact:
|
||||
mysql_installed: True
|
||||
|
||||
- name: "Add 'mysql_installed: True' to {{ iiab_state_file }}"
|
||||
lineinfile:
|
||||
dest: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
|
||||
regexp: '^mysql_installed'
|
||||
line: 'mysql_installed: True'
|
||||
|
||||
|
||||
# Name of MySQL service varies by OS, so hardcoded in /opt/iiab/iiab/vars/<OS>.yml (formerly in roles/0-init/tasks/main.yml)
|
||||
- name: Enable & Start MySQL systemd service ({{ mysql_service }}) if mysql_enabled
|
||||
- name: Enable & Start MySQL ({{ mysql_service }}) systemd service, if mysql_enabled
|
||||
systemd:
|
||||
name: "{{ mysql_service }}"
|
||||
daemon_reload: yes
|
||||
state: restarted
|
||||
state: started
|
||||
enabled: yes
|
||||
when: mysql_enabled | bool
|
||||
|
||||
- name: Install /root/.my.cnf file from template, with root password credentials, if mysql_enabled
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/.my.cnf
|
||||
owner: root
|
||||
mode: '0600'
|
||||
when: mysql_enabled | bool
|
||||
|
||||
# 'localhost' needs to be the last item for idempotency, see
|
||||
# http://ansible.cc/docs/modules.html#mysql-user
|
||||
# unfortunately it still doesn't work
|
||||
- name: Update MySQL root password for localhost root accounts, if mysql_enabled
|
||||
mysql_user:
|
||||
name: root
|
||||
host: localhost
|
||||
password: "{{ mysql_root_password }}"
|
||||
priv: "*.*:ALL,GRANT"
|
||||
when: mysql_enabled | bool
|
||||
|
||||
- name: Update MySQL root password for all remaining root accounts (127.0.0.1, ::1) if mysql_enabled
|
||||
mysql_user:
|
||||
name: root
|
||||
host: "{{ item }}"
|
||||
password: "{{ mysql_root_password }}"
|
||||
priv: "*.*:ALL,GRANT"
|
||||
with_items:
|
||||
#- "{{ iiab_hostname }}.{{ iiab_domain }}"
|
||||
- 127.0.0.1
|
||||
- ::1
|
||||
when: mysql_enabled | bool
|
||||
|
||||
- name: Delete anonymous MySQL server user for {{ ansible_hostname }}, if mysql_enabled
|
||||
mysql_user:
|
||||
user: ""
|
||||
host: "{{ ansible_hostname }}"
|
||||
state: absent
|
||||
when: mysql_enabled | bool
|
||||
|
||||
- name: Delete anonymous MySQL server user for localhost, if mysql_enabled
|
||||
mysql_user:
|
||||
user: ""
|
||||
state: absent
|
||||
when: mysql_enabled | bool
|
||||
|
||||
- name: Remove the MySQL 'test' database, if mysql_enabled
|
||||
mysql_db:
|
||||
db: test
|
||||
state: absent
|
||||
when: mysql_enabled | bool
|
||||
|
||||
# we had to start mysql in order to configure it, now turn if off if not enabled
|
||||
- name: Config is done but now DISABLE MySQL service, if not mysql_enabled
|
||||
# We had to start MySQL in order to configure it, now turn if off if not enabled
|
||||
- name: Disable & Stop MySQL ({{ mysql_service }}) systemd service, if not mysql_enabled
|
||||
systemd:
|
||||
name: "{{ mysql_service }}"
|
||||
enabled: no
|
||||
|
@ -198,7 +50,7 @@
|
|||
|
||||
- name: Add 'mysql' variable values to {{ iiab_ini_file }}
|
||||
ini_file:
|
||||
path: "{{ iiab_ini_file }}"
|
||||
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
|
||||
section: mysql
|
||||
option: "{{ item.option }}"
|
||||
value: "{{ item.value | string }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue