Add all files needed to bring up VM and run agaric.com locally

This commit is contained in:
benjamin melançon 2018-08-20 10:45:20 -04:00
parent 52c8b60bac
commit 4d2bc0ee24
742 changed files with 24037 additions and 0 deletions

View file

@ -0,0 +1,75 @@
---
- name: Copy my.cnf global MySQL configuration.
template:
src: my.cnf.j2
dest: "{{ mysql_config_file }}"
owner: root
group: root
mode: 0644
force: "{{ overwrite_global_mycnf }}"
notify: restart mysql
- name: Verify mysql include directory exists.
file:
path: "{{ mysql_config_include_dir }}"
state: directory
owner: root
group: root
mode: 0755
when: mysql_config_include_files | length
- name: Copy my.cnf override files into include directory.
template:
src: "{{ item.src }}"
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
owner: root
group: root
mode: 0644
force: "{{ item.force | default(False) }}"
with_items: "{{ mysql_config_include_files }}"
notify: restart mysql
- name: Create slow query log file (if configured).
command: "touch {{ mysql_slow_query_log_file }}"
args:
creates: "{{ mysql_slow_query_log_file }}"
warn: no
when: mysql_slow_query_log_enabled
- name: Create datadir if it does not exist
file:
path: "{{ mysql_datadir }}"
state: directory
owner: mysql
group: mysql
mode: 0755
setype: mysqld_db_t
- name: Set ownership on slow query log file (if configured).
file:
path: "{{ mysql_slow_query_log_file }}"
state: file
owner: mysql
group: mysql
mode: 0640
when: mysql_slow_query_log_enabled
- name: Create error log file (if configured).
command: "touch {{ mysql_log_error }}"
args:
creates: "{{ mysql_log_error }}"
warn: no
when: mysql_log == "" and mysql_log_error != ""
- name: Set ownership on error log file (if configured).
file:
path: "{{ mysql_log_error }}"
state: file
owner: mysql
group: mysql
mode: 0640
when: mysql_log == "" and mysql_log_error != ""
- name: Ensure MySQL is started and enabled on boot.
service: "name={{ mysql_daemon }} state=started enabled={{ mysql_enabled_on_startup }}"
register: mysql_service_configuration

View file

@ -0,0 +1,8 @@
---
- name: Ensure MySQL databases are present.
mysql_db:
name: "{{ item.name }}"
collation: "{{ item.collation | default('utf8_general_ci') }}"
encoding: "{{ item.encoding | default('utf8') }}"
state: present
with_items: "{{ mysql_databases }}"

View file

@ -0,0 +1,29 @@
---
# Variable configuration.
- include: variables.yml
# Setup/install tasks.
- include: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
static: no
- include: setup-Debian.yml
when: ansible_os_family == 'Debian'
static: no
- include: setup-Archlinux.yml
when: ansible_os_family == 'Archlinux'
static: no
- name: Check if MySQL packages were installed.
set_fact:
mysql_install_packages: "{{ (rh_mysql_install_packages is defined and rh_mysql_install_packages.changed)
or (deb_mysql_install_packages is defined and deb_mysql_install_packages.changed)
or (arch_mysql_install_packages is defined and arch_mysql_install_packages.changed) }}"
# Configure MySQL.
- include: configure.yml
- include: secure-installation.yml
- include: databases.yml
- include: users.yml
- include: replication.yml

View file

@ -0,0 +1,54 @@
---
- name: Ensure replication user exists on master.
mysql_user:
name: "{{ mysql_replication_user.name }}"
host: "{{ mysql_replication_user.host | default('%') }}"
password: "{{ mysql_replication_user.password }}"
priv: "{{ mysql_replication_user.priv | default('*.*:REPLICATION SLAVE,REPLICATION CLIENT') }}"
state: present
when: >
(mysql_replication_role == 'master')
and mysql_replication_user
and (mysql_replication_master != '')
- name: Check slave replication status.
mysql_replication:
mode: getslave
login_user: "{{ mysql_replication_user.name }}"
login_password: "{{ mysql_replication_user.password }}"
ignore_errors: true
register: slave
when: >
mysql_replication_role == 'slave'
and (mysql_replication_master != '')
- name: Check master replication status.
mysql_replication: mode=getmaster
delegate_to: "{{ mysql_replication_master }}"
register: master
when: >
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')
- name: Configure replication on the slave.
mysql_replication:
mode: changemaster
master_host: "{{ mysql_replication_master }}"
master_user: "{{ mysql_replication_user.name }}"
master_password: "{{ mysql_replication_user.password }}"
master_log_file: "{{ master.File }}"
master_log_pos: "{{ master.Position }}"
ignore_errors: True
when: >
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')
and mysql_replication_user
- name: Start replication.
mysql_replication: mode=startslave
when: >
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')

View file

@ -0,0 +1,80 @@
---
- name: Get MySQL version.
command: 'mysql --version'
register: mysql_cli_version
changed_when: false
- name: Ensure default user is present.
mysql_user:
name: "{{ mysql_user_name }}"
host: 'localhost'
password: "{{ mysql_user_password }}"
priv: '*.*:ALL,GRANT'
state: present
when: mysql_user_name != mysql_root_username
# Has to be after the password assignment, for idempotency.
- name: Copy user-my.cnf file with password credentials.
template:
src: "user-my.cnf.j2"
dest: "{{ mysql_user_home }}/.my.cnf"
owner: "{{ mysql_user_name }}"
mode: 0600
when: mysql_user_name != mysql_root_username and (mysql_install_packages | bool or mysql_user_password_update)
- name: Disallow root login remotely
command: 'mysql -NBe "{{ item }}"'
with_items:
- DELETE FROM mysql.user WHERE User='{{ mysql_root_username }}' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
changed_when: false
- name: Get list of hosts for the root user.
command: mysql -NBe "SELECT Host FROM mysql.user WHERE User = '{{ mysql_root_username }}' ORDER BY (Host='localhost') ASC"
register: mysql_root_hosts
changed_when: false
check_mode: no
when: mysql_install_packages | bool or mysql_root_password_update
# Note: We do not use mysql_user for this operation, as it doesn't always update
# the root password correctly. See: https://goo.gl/MSOejW
# Set root password for MySQL >= 5.7.x.
- name: Update MySQL root password for localhost root account (5.7.x).
shell: >
mysql -u root -NBe
'ALTER USER "{{ mysql_root_username }}"@"{{ item }}" IDENTIFIED WITH mysql_native_password BY "{{ mysql_root_password }}";'
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
when: ((mysql_install_packages | bool) or mysql_root_password_update) and ('5.7.' in mysql_cli_version.stdout)
# Set root password for MySQL < 5.7.x.
- name: Update MySQL root password for localhost root account (< 5.7.x).
shell: >
mysql -NBe
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}");'
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
when: ((mysql_install_packages | bool) or mysql_root_password_update) and ('5.7.' not in mysql_cli_version.stdout)
# Has to be after the root password assignment, for idempotency.
- name: Copy .my.cnf file with root password credentials.
template:
src: "root-my.cnf.j2"
dest: "{{ mysql_root_home }}/.my.cnf"
owner: root
group: root
mode: 0600
when: mysql_install_packages | bool or mysql_root_password_update
- name: Get list of hosts for the anonymous user.
command: mysql -NBe 'SELECT Host FROM mysql.user WHERE User = ""'
register: mysql_anonymous_hosts
changed_when: false
check_mode: no
- name: Remove anonymous MySQL users.
mysql_user:
name: ""
host: "{{ item }}"
state: absent
with_items: "{{ mysql_anonymous_hosts.stdout_lines|default([]) }}"
- name: Remove MySQL test database.
mysql_db: "name='test' state=absent"

View file

@ -0,0 +1,12 @@
---
- name: Ensure MySQL Python libraries are installed.
pacman: "name=mysql-python state=present"
- name: Ensure MySQL packages are installed.
pacman: "name={{ item }} state=present"
with_items: "{{ mysql_packages }}"
register: arch_mysql_install_packages
# Init the database if mysql is newly installed
- command: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
when: arch_mysql_install_packages.changed

View file

@ -0,0 +1,29 @@
---
- name: Check if MySQL is already installed.
stat: path=/etc/init.d/mysql
register: mysql_installed
- name: Update apt cache if MySQL is not yet installed.
apt: update_cache=yes
when: mysql_installed.stat.exists == false
- name: Ensure MySQL Python libraries are installed.
apt: "name=python-mysqldb state=installed"
- name: Ensure MySQL packages are installed.
apt: "name={{ item }} state=installed"
with_items: "{{ mysql_packages }}"
register: deb_mysql_install_packages
# Because Ubuntu starts MySQL as part of the install process, we need to stop
# mysql and remove the logfiles in case the user set a custom log file size.
- name: Ensure MySQL is stopped after initial install.
service: "name={{ mysql_daemon }} state=stopped"
when: mysql_installed.stat.exists == false
- name: Delete innodb log files created by apt package after initial install.
file: path={{ mysql_datadir }}/{{item}} state=absent
with_items:
- "ib_logfile0"
- "ib_logfile1"
when: mysql_installed.stat.exists == false

View file

@ -0,0 +1,8 @@
---
- name: Ensure MySQL packages are installed.
yum: "name={{ item }} state=installed enablerepo={{ mysql_enablerepo }}"
with_items: "{{ mysql_packages }}"
register: rh_mysql_install_packages
- name: Ensure MySQL Python libraries are installed.
yum: "name=MySQL-python state=installed enablerepo={{ mysql_enablerepo }}"

View file

@ -0,0 +1,12 @@
---
- name: Ensure MySQL users are present.
mysql_user:
name: "{{ item.name }}"
host: "{{ item.host | default('localhost') }}"
password: "{{ item.password }}"
priv: "{{ item.priv | default('*.*:USAGE') }}"
state: "{{ item.state | default('present') }}"
append_privs: "{{ item.append_privs | default('no') }}"
encrypted: "{{ item.encrypted | default('no') }}"
with_items: "{{ mysql_users }}"
no_log: true

View file

@ -0,0 +1,63 @@
---
# Variable configuration.
- name: Include OS-specific variables.
include_vars: "{{ item }}"
with_first_found:
- files:
- "vars/{{ ansible_os_family }}.yml"
skip: true
when: ansible_os_family != "RedHat"
- name: Include OS-specific variables (RedHat).
include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
when: ansible_os_family == "RedHat"
- name: Define mysql_packages.
set_fact:
mysql_packages: "{{ __mysql_packages | list }}"
when: mysql_packages is not defined
- name: Define mysql_daemon.
set_fact:
mysql_daemon: "{{ __mysql_daemon }}"
when: mysql_daemon is not defined
- name: Define mysql_slow_query_log_file.
set_fact:
mysql_slow_query_log_file: "{{ __mysql_slow_query_log_file }}"
when: mysql_slow_query_log_file is not defined
- name: Define mysql_log_error.
set_fact:
mysql_log_error: "{{ __mysql_log_error }}"
when: mysql_log_error is not defined
- name: Define mysql_syslog_tag.
set_fact:
mysql_syslog_tag: "{{ __mysql_syslog_tag }}"
when: mysql_syslog_tag is not defined
- name: Define mysql_pid_file.
set_fact:
mysql_pid_file: "{{ __mysql_pid_file }}"
when: mysql_pid_file is not defined
- name: Define mysql_config_file.
set_fact:
mysql_config_file: "{{ __mysql_config_file }}"
when: mysql_config_file is not defined
- name: Define mysql_config_include_dir.
set_fact:
mysql_config_include_dir: "{{ __mysql_config_include_dir }}"
when: mysql_config_include_dir is not defined
- name: Define mysql_socket.
set_fact:
mysql_socket: "{{ __mysql_socket }}"
when: mysql_socket is not defined
- name: Define mysql_supports_innodb_large_prefix.
set_fact:
mysql_supports_innodb_large_prefix: "{{ __mysql_supports_innodb_large_prefix }}"
when: mysql_supports_innodb_large_prefix is not defined