diff --git a/.gitignore b/.gitignore index 1cd4c33..485dee6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,65 +1 @@ -# Test files -dump.sql.bz2 - -# VIM specific files -[._]*.s[a-w][a-z] -[._]s[a-w][a-z] -*.un~ -Session.vim -.netrwhist -*~ - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -# Sphinx documentation -docs/_build/ - +.idea diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 346b3a3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -language: python -python: "2.7" - -before_install: - - sudo apt-get update -qq - # Remove MySQL - - sudo apt-get -f install -o Dpkg::Options::="--force-overwrite" - - sudo apt-get remove --purge -s mysql\* - - sudo apt-get autoremove - - sudo apt-get autoclean - - sudo rm -rf /var/lib/mysql - - sudo truncate -s 0 /var/log/mysql/error.log - -install: - - pip install ansible - - - "printf '[defaults]\nroles_path = ../' > ansible.cfg" - -script: - # Check role systax - - "ansible-playbook -i tests/inventory tests/test.yml --syntax-check" - # Run role with ansible-playbook - - "ansible-playbook -i tests/inventory tests/test.yml --connection=local" - # Test role idempotence - - > - ansible-playbook -i tests/inventory tests/test.yml --connection=local - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) - # Test MySQL connection - - > - mysql -u root -preallylongpassword -e 'show databases;' - | grep -q 'performance_schema' - && (echo 'MySQL running normally' && exit 0) - || (echo 'MySQL not running' && exit 1) diff --git a/README.md b/README.md index 4a93463..d6d33a7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Ansible Role: Percona -Ansible playbook to install percona MySQL server in Debian/Ubuntu servers - -[![Build Status](https://api.travis-ci.org/overdrive3000/ansible-percona.svg)](https://travis-ci.org/overdrive3000/ansible-percona/) +Ansible playbook to install Percona MySQL server on Debian/Ubuntu servers ## Requirements diff --git a/defaults/main.yml b/defaults/main.yml index e2a198a..8916883 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,25 +1,42 @@ ---- -# Define root password for percona server -root_password: reallylongpassword +# file: mysql/defaults/main.yml -# Some defaults variables for percona server config file -port: 3306 -bind_address: 0.0.0.0 -max_allowed_packet: 16M -key_buffer: 16M -thread_stack: 192K -thread_cache_size: 8 -# Uncomment following vars if you want to log queries -sqldebug: true -log_slow_queries: log_slow_queries = /var/log/mysql/mysql-slow.log -long_query_time: long_query_time = 2 -log_queries_not_using_indexes: log-queries-not-using-indexes +# Basic settings +mysql_port: 3306 +mysql_bind_address: "0.0.0.0" +mysql_root_password: 'pass' +mysql_language: '/usr/share/mysql/' -# Define is a database must be created -create_app_db: true +# Fine Tuning +mysql_key_buffer: '16M' +mysql_max_allowed_packet: '128M' +mysql_thread_stack: '192K' +mysql_cache_size: 8 +mysql_myisam_recover: 'BACKUP' +mysql_max_connections: 100 +mysql_table_cache: 64 +mysql_thread_concurrency: 10 +mysql_query_cache_limit: '1M' +mysql_query_cache_size: '16M' +mysql_innodb_file_per_table: 'innodb_file_per_table' +mysql_character_set_server: 'utf8' +mysql_collation_server: 'utf8_general_ci' +mysql_mysqldump_max_allowed_packet: '128M' +mysql_isamchk_key_buffer: '16M' + +# InnoDB tuning +mysql_innodb_file_per_table: 'innodb_file_per_table' +mysql_innodb_flush_method: 'fdatasync' +mysql_innodb_buffer_pool_size: '128M' +mysql_innodb_flush_log_at_trx_commit: 1 +mysql_innodb_lock_wait_timeout: 50 +mysql_innodb_log_buffer_size: '1M' +mysql_innodb_log_file_size: '5M' + +# Create from a DB dump? +create_app_db: false db_name: mydatabase db_collation: utf8_general_ci db_user: myuser db_user_password: anotherreallylongpassword db_host: "%" -db_dump_file: "" +db_dump_file: "" \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml index beec690..ca8903e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,12 +1,13 @@ --- galaxy_info: - author: "Juan Mesa" - company: gochos - license: BSD + author: "Laurie Voss" + company: "npm Inc" + license: ISC min_ansible_version: 1.4 platforms: - name: Ubuntu versions: + - trusty - saucy - precise - name: Debian diff --git a/tasks/install.yml b/tasks/install.yml index e34e5c7..a1091ca 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -35,16 +35,7 @@ - name: remove test database mysql_db: name=test state=absent -- name: Create fnv1a_64 - shell: /usr/bin/mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" && touch /var/log/libfnv1a_udf.so.done creates=/var/log/libfnv1a_udf.so.done - -- name: Create fnv_64 - shell: /usr/bin/mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" && touch /var/log/libfnv_udf.so.done creates=/var/log/libfnv_udf.so.done - -- name: Create murmur_hash - shell: /usr/bin/mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'" && touch /var/log/libmurmur_udf.so.done creates=/var/log/libmurmur_udf.so.done - - name: Write custom server configuration - template: src=my.cnf.j2 dest=/etc/mysql/my.cnf owner=root mode=0622 + template: src=etc_mysql_my.cnf.j2 dest=/etc/mysql/my.cnf owner=root mode=0622 notify: - restart percona diff --git a/tasks/repo.yml b/tasks/repo.yml index e8dbed0..581dfb5 100644 --- a/tasks/repo.yml +++ b/tasks/repo.yml @@ -1,7 +1,7 @@ --- # file: tasks/repo.tml -- name: Obtianing percona public key +- name: Obtaining percona public key apt_key: url=http://www.percona.com/downloads/RPM-GPG-KEY-percona state=present diff --git a/templates/etc_mysql_my.cnf.j2 b/templates/etc_mysql_my.cnf.j2 new file mode 100644 index 0000000..8d3b326 --- /dev/null +++ b/templates/etc_mysql_my.cnf.j2 @@ -0,0 +1,100 @@ +# +# The MySQL database server configuration file. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +[client] +port = {{ mysql_port }} +socket = /var/run/mysqld/mysqld.sock + +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + +[mysqld] +# * Basic Settings +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = {{ mysql_port }} +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +# language is for pre-5.5. In 5.5 it is an alias for lc_messages_dir. +language = {{ mysql_language }} +bind-address = {{ mysql_bind_address }} +skip-external-locking + + +# * Fine Tuning +key_buffer = {{ mysql_key_buffer }} +max_allowed_packet = {{ mysql_max_allowed_packet }} +thread_stack = {{ mysql_thread_stack }} +thread_cache_size = {{ mysql_cache_size }} +myisam-recover = {{ mysql_myisam_recover }} +max_connections = {{ mysql_max_connections }} +table_open_cache = {{ mysql_table_cache }} +thread_concurrency = {{ mysql_thread_concurrency }} + +# ** Query Cache Configuration +query_cache_limit = {{ mysql_query_cache_limit }} +query_cache_size = {{ mysql_query_cache_size }} + +# ** Logging and Replication +#general_log_file = /var/log/mysql/mysql.log +#general_log = 1 +# +#log_slow_queries = /var/log/mysql/mysql-slow.log +#long_query_time = 2 +#log-queries-not-using-indexes +# +# The following can be used as easy to replay backup logs or for replication. +#server-id = 1 +#log_bin = /var/log/mysql/mysql-bin.log +expire_logs_days = 10 +max_binlog_size = 100M +#binlog_do_db = include_database_name +#binlog_ignore_db = include_database_name + +# ** InnoDB +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! +innodb_flush_log_at_trx_commit = {{ mysql_innodb_flush_log_at_trx_commit }} +innodb_buffer_pool_size = {{ mysql_innodb_buffer_pool_size }} +{% if mysql_innodb_flush_method != 'fdatasync': %} +innodb_flush_method = {{ mysql_innodb_flush_method }} +{% endif %} +innodb_lock_wait_timeout = {{ mysql_innodb_lock_wait_timeout }} +innodb_log_buffer_size = {{ mysql_innodb_log_buffer_size }} +innodb_log_file_size = {{ mysql_innodb_log_file_size }} +{{ mysql_innodb_file_per_table }} + +# ** Security Features +# Read the manual, too, if you want chroot! +# chroot = /var/lib/mysql/ +# +# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". +# ssl-ca=/etc/mysql/cacert.pem +# ssl-cert=/etc/mysql/server-cert.pem +# ssl-key=/etc/mysql/server-key.pem + +character_set_server = {{ mysql_character_set_server }} +collation_server = {{ mysql_collation_server }} + +[mysqldump] +quick +quote-names +max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }} + +[mysql] +#no-auto-rehash # faster start of mysql but no tab completition + +[isamchk] +key_buffer = {{ mysql_isamchk_key_buffer }} + +# +# * IMPORTANT: Additional settings that can override those from this file! +# The files must end with '.cnf', otherwise they'll be ignored. +# +!includedir /etc/mysql/conf.d/ \ No newline at end of file diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 deleted file mode 100644 index 6c1b5c9..0000000 --- a/templates/my.cnf.j2 +++ /dev/null @@ -1,130 +0,0 @@ -# NOTE: This file is automaticaly generated by Ansible -# please do not change any variable in this config file -# or will be override by ansible -# -# The MySQL database server configuration file. -# -# You can copy this to one of: -# - "/etc/mysql/my.cnf" to set global options, -# - "~/.my.cnf" to set user-specific options. -# -# One can use all long options that the program supports. -# Run program with --help to get a list of available options and with -# --print-defaults to see which it would actually understand and use. -# -# For explanations see -# http://dev.mysql.com/doc/mysql/en/server-system-variables.html - -# This will be passed to all mysql clients -# It has been reported that passwords should be enclosed with ticks/quotes -# escpecially if they contain "#" chars... -# Remember to edit /etc/mysql/debian.cnf when changing the socket location. -[client] -port = {{ port }} -socket = /var/run/mysqld/mysqld.sock - -# Here is entries for some specific programs -# The following values assume you have at least 32M ram - -# This was formally known as [safe_mysqld]. Both versions are currently parsed. -[mysqld_safe] -socket = /var/run/mysqld/mysqld.sock -nice = 0 - -[mysqld] -# -# * Basic Settings -# -user = mysql -pid-file = /var/run/mysqld/mysqld.pid -socket = /var/run/mysqld/mysqld.sock -port = {{ port }} -basedir = /usr -datadir = /var/lib/mysql -tmpdir = /tmp -lc-messages-dir = /usr/share/mysql -skip-external-locking -# -# Instead of skip-networking the default is now to listen only on -# localhost which is more compatible and is not less secure. -bind-address = {{ bind_address }} -# -# * Fine Tuning -# -key_buffer = {{ key_buffer }} # 16M -max_allowed_packet = {{ max_allowed_packet }} # 16M -thread_stack = {{ thread_stack }} # 192K -thread_cache_size = {{ thread_cache_size }} # 8 -# This replaces the startup script and checks MyISAM tables if needed -# the first time they are touched -myisam-recover = BACKUP -#max_connections = 100 -#table_cache = 64 -#thread_concurrency = 10 -# -# * Query Cache Configuration -# -query_cache_limit = 1M -query_cache_size = 16M -# -# * Logging and Replication -# -# Both location gets rotated by the cronjob. -# Be aware that this log type is a performance killer. -# As of 5.1 you can enable the log at runtime! -#general_log_file = /var/log/mysql/mysql.log -#general_log = 1 -# -# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. -# -# Here you can see queries with especially long duration -{% if sqldebug %} -{{ log_slow_queries }} -{{ long_query_time }} -{{ log_queries_not_using_indexes }} -{% endif -%} -# -# The following can be used as easy to replay backup logs or for replication. -# note: if you are setting up a replication slave, see README.Debian about -# other settings you may need to change. -#server-id = 1 -#log_bin = /var/log/mysql/mysql-bin.log -expire_logs_days = 10 -max_binlog_size = 100M -#binlog_do_db = include_database_name -#binlog_ignore_db = include_database_name -# -# * InnoDB -# -# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. -# Read the manual for more InnoDB related options. There are many! -# -# * Security Features -# -# Read the manual, too, if you want chroot! -# chroot = /var/lib/mysql/ -# -# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". -# -# ssl-ca=/etc/mysql/cacert.pem -# ssl-cert=/etc/mysql/server-cert.pem -# ssl-key=/etc/mysql/server-key.pem - - - -[mysqldump] -quick -quote-names -max_allowed_packet = 16M - -[mysql] -#no-auto-rehash # faster start of mysql but no tab completition - -[isamchk] -key_buffer = 16M - -# -# * IMPORTANT: Additional settings that can override those from this file! -# The files must end with '.cnf', otherwise they'll be ignored. -# -!includedir /etc/mysql/conf.d/ diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 2fbb50c..0000000 --- a/tests/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost diff --git a/tests/test.yml b/tests/test.yml deleted file mode 100644 index fa3843d..0000000 --- a/tests/test.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: all - user: vagrant - sudo: true - vars: - - db_name: mydb - - db_user: test - - db_host: localhost - - db_user_password: password - - sqldebug: false - roles: - - ansible-percona