{"id":13570242,"url":"https://github.com/geerlingguy/ansible-role-mysql","last_synced_at":"2025-04-10T23:27:26.220Z","repository":{"id":37733978,"uuid":"17306894","full_name":"geerlingguy/ansible-role-mysql","owner":"geerlingguy","description":"Ansible Role - MySQL","archived":false,"fork":false,"pushed_at":"2025-04-10T18:36:01.000Z","size":314,"stargazers_count":1088,"open_issues_count":20,"forks_count":877,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-04-10T19:56:29.756Z","etag":null,"topics":["ansible","database","mariadb","mysql","playbook","role"],"latest_commit_sha":null,"homepage":"https://galaxy.ansible.com/geerlingguy/mysql/","language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geerlingguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"geerlingguy","patreon":"geerlingguy"}},"created_at":"2014-03-01T03:31:50.000Z","updated_at":"2025-04-10T18:35:52.000Z","dependencies_parsed_at":"2024-07-16T23:17:56.050Z","dependency_job_id":"41251bb4-10d2-43bb-8ae6-ad739a1a4759","html_url":"https://github.com/geerlingguy/ansible-role-mysql","commit_stats":{"total_commits":313,"total_committers":63,"mean_commits":4.968253968253968,"dds":0.3929712460063898,"last_synced_commit":"9f580ee10411edc5a12345edeac3dd2c69e9834e"},"previous_names":[],"tags_count":95,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geerlingguy%2Fansible-role-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geerlingguy%2Fansible-role-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geerlingguy%2Fansible-role-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geerlingguy%2Fansible-role-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geerlingguy","download_url":"https://codeload.github.com/geerlingguy/ansible-role-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248314102,"owners_count":21082986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","database","mariadb","mysql","playbook","role"],"created_at":"2024-08-01T14:00:50.106Z","updated_at":"2025-04-10T23:27:26.147Z","avatar_url":"https://github.com/geerlingguy.png","language":"Jinja","funding_links":["https://github.com/sponsors/geerlingguy","https://patreon.com/geerlingguy"],"categories":["Jinja","Others","role","Reverse Proxy"],"sub_categories":["Databases"],"readme":"# Ansible Role: MySQL\n\n[![CI](https://github.com/geerlingguy/ansible-role-mysql/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-mysql/actions/workflows/ci.yml)\n\nInstalls and configures MySQL or MariaDB server on RHEL/CentOS or Debian/Ubuntu servers.\n\n## Requirements\n\nNo special requirements; note that this role requires root access, so either run it in a playbook with a global `become: true`, or invoke the role in your playbook like:\n\n```yaml\n- hosts: database\n  roles:\n    - role: geerlingguy.mysql\n      become: true\n```\n\n## Role Variables\n\nAvailable variables are listed below, along with default values (see `defaults/main.yml`):\n\n```yaml\nmysql_user_home: /root\nmysql_user_name: root\nmysql_user_password: root\n```\n\nThe home directory inside which Python MySQL settings will be stored, which Ansible will use when connecting to MySQL. This should be the home directory of the user which runs this Ansible role. The `mysql_user_name` and `mysql_user_password` can be set if you are running this role under a non-root user account and want to set a non-root user.\n\n```yaml\nmysql_root_home: /root\nmysql_root_username: root\nmysql_root_password: root\n```\n\nThe MySQL root user account details.\n\n```yaml\nmysql_root_password_update: false\n```\n\nWhether to force update the MySQL root user's password. By default, this role will only change the root user's password when MySQL is first configured. You can force an update by setting this to `true`.\n\n\u003e Note: If you get an error like `ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)` after a failed or interrupted playbook run, this usually means the root password wasn't originally updated to begin with. Try either removing  the `.my.cnf` file inside the configured `mysql_user_home` or updating it and setting `password=''` (the insecure default password). Run the playbook again, with `mysql_root_password_update` set to `yes`, and the setup should complete.\n\n\u003e Note: If you get an error like `ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES)` when trying to log in from the CLI you might need to run as root or sudoer.\n\n```yaml\nmysql_enabled_on_startup: true\n```\n\nWhether MySQL should be enabled on startup.\n\n```yaml\nmysql_config_file: *default value depends on OS*\nmysql_config_include_dir: *default value depends on OS*\n```\n\nThe main my.cnf configuration file and include directory.\n\n```yaml\noverwrite_global_mycnf: true\n```\n\nWhether the global my.cnf should be overwritten each time this role is run. Setting this to `false` tells Ansible to only create the `my.cnf` file if it doesn't exist. This should be left at its default value (`true`) if you'd like to use this role's variables to configure MySQL.\n\n```yaml\nmysql_config_include_files: []\n```\n\nA list of files that should override the default global my.cnf. Each item in the array requires a \"src\" parameter which is a path to a file. An optional \"force\" parameter can force the file to be updated each time ansible runs.\n\n```yaml\nmysql_databases: []\n```\n\nThe MySQL databases to create. A database has the values `name`, `encoding` (defaults to `utf8`), `collation` (defaults to `utf8_general_ci`) and `replicate` (defaults to `1`, only used if replication is configured). The formats of these are the same as in the `mysql_db` module.\n\nYou can also delete a database (or ensure it's not on the server) by setting `state` to `absent` (defaults to `present`).\n\n```yaml\nmysql_users: []\n```\n\nThe MySQL users and their privileges. A user has the values:\n\n  - `name`\n  - `host` (defaults to `localhost`)\n  - `password` (can be plaintext or encrypted—if encrypted, set `encrypted: true`)\n  - `encrypted` (defaults to `false`)\n  - `priv` (defaults to `*.*:USAGE`)\n  - `append_privs` (defaults to `false`)\n  - `state`  (defaults to `present`)\n  - `case_sensitive` (defaults to `false`)\n  - `update_password` (defaults to `always`)\n\nThe formats of these are the same as in the `mysql_user` module.\n\n```yaml\nmysql_packages:\n  - mysql\n  - mysql-server\n```\n\n(OS-specific, RedHat/CentOS defaults listed here) Packages to be installed. In some situations, you may need to add additional packages, like `mysql-devel`.\n\n```yaml\nmysql_enablerepo: \"\"\n```\n\n(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install later versions of MySQL.\n\n```yaml\nmysql_python_package_debian: python3-mysqldb\n```\n\n(Ubuntu/Debian only) If you need to explicitly override the MySQL Python package, you can set it here. Set this to `python-mysqldb` if using older distributions running Python 2.\n\n```yaml\nmysql_port: \"3306\"\nmysql_bind_address: '0.0.0.0'\nmysql_datadir: /var/lib/mysql\nmysql_socket: *default value depends on OS*\nmysql_pid_file: *default value depends on OS*\n```\n\nDefault MySQL connection configuration.\n\n```yaml\nmysql_log_file_group: mysql *adm on Debian*\nmysql_log: \"\"\nmysql_log_error: *default value depends on OS*\nmysql_syslog_tag: *default value depends on OS*\n```yaml\n\nMySQL logging configuration. Setting `mysql_log` (the general query log) or `mysql_log_error` to `syslog` will make MySQL log to syslog using the `mysql_syslog_tag`.\n\n```yaml\nmysql_slow_query_log_enabled: false\nmysql_slow_query_log_file: *default value depends on OS*\nmysql_slow_query_time: 2\n```\n\nSlow query log settings. Note that the log file will be created by this role, but if you're running on a server with SELinux or AppArmor, you may need to add this path to the allowed paths for MySQL, or disable the mysql profile. For example, on Debian/Ubuntu, you can run `sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld \u0026\u0026 sudo service apparmor restart`.\n\n```yaml\nmysql_key_buffer_size: \"256M\"\nmysql_max_allowed_packet: \"64M\"\nmysql_table_open_cache: \"256\"\n...\n```\n\nThe rest of the settings in `defaults/main.yml` control MySQL's memory usage and some other common settings. The default values are tuned for a server where MySQL can consume 512 MB RAM, so you should consider adjusting them to suit your particular server better.\n\n```yaml\nmysql_disable_log_bin: false\n```\n\nThis variable should be set to `true` if you don't need replication, or otherwise don't need a log of all MySQL's activity. If you leave it at the default value, disk space may be consumed at an alarming rate on highly-utlilized database servers!\n\n```yaml\nmysql_server_id: \"1\"\nmysql_max_binlog_size: \"100M\"\nmysql_binlog_format: \"ROW\"\nmysql_expire_logs_days: \"10\"\nmysql_replication_role: ''\nmysql_replication_master: ''\nmysql_replication_user: {}\n```\n\nReplication settings. Set `mysql_server_id` and `mysql_replication_role` by server (e.g. the master would be ID `1`, with the `mysql_replication_role` of `master`, and the slave would be ID `2`, with the `mysql_replication_role` of `slave`). The `mysql_replication_user` uses the same keys as individual list items in `mysql_users`, and is created on master servers, and used to replicate on all the slaves.\n\n`mysql_replication_master` needs to resolve to an IP or a hostname which is accessable to the Slaves (this could be a `/etc/hosts` injection or some other means), otherwise the slaves cannot communicate to the master.\n\nIf the replication master has different IP addresses where you are running ansible and where the mysql replica is running, you can *optionally* specify a `mysql_replication_master_inventory_host` to access the machine (e.g. you run ansible on your local machine, but the mysql master and replica need to communicate on a different network)\n\n```yaml\nmysql_hide_passwords: false\n```\n\nDo you need to hide tasks' output which contain passwords during the execution ?\n\n### MariaDB usage\n\nThis role works with either MySQL or a compatible version of MariaDB. On RHEL/CentOS 7+, the mariadb database engine was substituted as the default MySQL replacement package. No modifications are necessary though all of the variables still reference 'mysql' instead of mariadb.\n\n#### Ubuntu 14.04 and 16.04 MariaDB configuration\n\nOn Ubuntu, the package names are named differently, so the `mysql_package` variable needs to be altered. Set the following variables (at a minimum):\n\n    mysql_packages:\n      - mariadb-client\n      - mariadb-server\n      - python-mysqldb\n\n## Dependencies\n\nIf you have `ansible` installed (e.g. `pip3 install ansible`), none.\n\nIf you have only installed `ansible-core`, be sure to require `community.mysql` in your `collections/requirements.yml` or install it manually with `ansible-galaxy collection install community.mysql`.\n\n## Example Playbook\n\n    - hosts: db-servers\n      become: true\n      vars_files:\n        - vars/main.yml\n      roles:\n        - { role: geerlingguy.mysql }\n\n*Inside `vars/main.yml`*:\n\n    mysql_root_password: super-secure-password\n    mysql_databases:\n      - name: example_db\n        encoding: latin1\n        collation: latin1_general_ci\n    mysql_users:\n      - name: example_user\n        host: \"%\"\n        password: similarly-secure-password\n        priv: \"example_db.*:ALL\"\n\n## License\n\nMIT / BSD\n\n## Author Information\n\nThis role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeerlingguy%2Fansible-role-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeerlingguy%2Fansible-role-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeerlingguy%2Fansible-role-mysql/lists"}