{"id":19442612,"url":"https://github.com/lean-delivery/ansible-role-mysql","last_synced_at":"2025-04-25T00:32:01.674Z","repository":{"id":33308759,"uuid":"143075933","full_name":"lean-delivery/ansible-role-mysql","owner":"lean-delivery","description":"Ansible Role - MySQL and MariaDB","archived":false,"fork":false,"pushed_at":"2022-07-15T06:41:06.000Z","size":99,"stargazers_count":29,"open_issues_count":3,"forks_count":14,"subscribers_count":18,"default_branch":"master","last_synced_at":"2023-03-02T07:11:47.243Z","etag":null,"topics":["ansible","ansible-role","database","mariadb","mysql","role"],"latest_commit_sha":null,"homepage":"https://galaxy.ansible.com/lean_delivery/mysql","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lean-delivery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-31T22:22:53.000Z","updated_at":"2023-03-02T07:11:47.244Z","dependencies_parsed_at":"2022-07-12T16:10:27.794Z","dependency_job_id":null,"html_url":"https://github.com/lean-delivery/ansible-role-mysql","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lean-delivery%2Fansible-role-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lean-delivery%2Fansible-role-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lean-delivery%2Fansible-role-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lean-delivery%2Fansible-role-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lean-delivery","download_url":"https://codeload.github.com/lean-delivery/ansible-role-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223975025,"owners_count":17234735,"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","ansible-role","database","mariadb","mysql","role"],"created_at":"2024-11-10T15:40:06.215Z","updated_at":"2024-11-10T15:40:06.895Z","avatar_url":"https://github.com/lean-delivery.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Role: MySQL\n[![License](https://img.shields.io/badge/license-Apache-green.svg?style=flat)](https://raw.githubusercontent.com/lean-delivery/ansible-role-mysql/master/LICENSE)\n[![Build status](https://gitlab.com/lean-delivery/ansible-role-mysql/badges/master/pipeline.svg)](https://gitlab.com/lean-delivery/ansible-role-mysql/-/commits/master)\n[![Galaxy](https://img.shields.io/badge/galaxy-lean__delivery.mysql-blue.svg)](https://galaxy.ansible.com/lean_delivery/mysql)\n![Ansible](https://img.shields.io/ansible/role/d/35413.svg)\n![Ansible](https://img.shields.io/badge/dynamic/json.svg?label=min_ansible_version\u0026url=https%3A%2F%2Fgalaxy.ansible.com%2Fapi%2Fv1%2Froles%2F35413%2F\u0026query=$.min_ansible_version)\n\n## Summary\n\nThis role installs and configures MySQL or MariaDB server on RHEL/CentOS servers.\n\n## Role tasks\n\n  - Installs MySQL/MariaDB\n  - Reset root password for mysql\n  - Create db and users\n\n## Requirements\n\n  - Supported versions:\n      - Oracle Mysql\n          - 5.5\n          - 5.6\n          - 5.7\n          - 8.0\n      - Mariadb\n          - 10.3\n          - 10.4\n          - 10.5\n  - Supported OS:\n      - RHEL\n          - 7\n          - 8\n      - CentOS\n          - 7\n          - 8\n      - Ubuntu\n          - 18.04\n      - Debian\n          - 9\n          - 10\n\n## Role Variables\n\nAvailable variables are listed below, along with default values:\n\nMysql/MariaDB repository settings:\n\n    mysql_repo: *default value depends on OS*   \n    mysql_gpgkey: *default value depends on OS*   \n    mysql_apt_keyserver: *default value depends on OS*  \n    mysql_repofile: /etc/yum.repos.d/mysql.repo|/etc/yum.repos.d/mariadb.repo\n    mysql_apt_key_id: *default value depends on OS*   \n    mysql_repo_disable_list: *default - undefined*. For CentOS 8 it's now list of `AppStream` and `Stream-AppStream`.\n\n    mysql_packages:\n      - mysql-community-server   # (mysql-community-server/MariaDB-server)\n      - mysql-community-client   # (mysql-community-client/MariaDB-client)\n      \nIf you want to select a specific minor version of package, you can enter appropriate package name, for instance:\n\n    mysql_packages:\n      - mysql-community-server-8.0.16-2.el7.x86_64\n      - mysql-community-client-8.0.16-2.el7.x86_64\n\nAlternatively, you can define the packages as a list of external urls by setting the variable `mysql_artifacts`, e.g.:\n\n    mysql_artifacts:\n      - https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb\n      - https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server_5.7.31-1ubuntu18.04_amd64.deb\n      \n### NOTE: *This option was tested only for deb-based packages at the moment.*\n                                 # (MariaDB-common)\n    mysql_daemon: mysqld         # (mysqld/mariadb)\n    mysql_version: 5.7           # (for mysql = 5.5/5.6/5.7; for mariadb = last (10.5) )\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    mysql_user_home: /root\n    mysql_user_name: root\n    mysql_user_password: root\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    mysql_root_home: /root\n    mysql_root_username: root\n    mysql_root_password: root\n\nThe MySQL root user account details.\n\n    mysql_config_file: *default value depends on OS*\n    mysql_config_include_dir: *default value depends on OS*\n    \nThe main my.cnf configuration file and include directory.\n\n    overwrite_global_mycnf: true\n\nWhether the global my.cnf should be overwritten each time this role is run. Setting this to `no` tells Ansible to only create the `my.cnf` file if it doesn't exist. This should be left at its default value (`yes`) if you'd like to use this role's variables to configure MySQL.\n\n    mysql_config_include_files: []\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    mysql_databases: []\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\n    mysql_users: []\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: yes`)\n  - `encrypted` (defaults to `no`)\n  - `priv` (defaults to `*.*:USAGE`)\n  - `append_privs` (defaults to `no`)\n  - `state`  (defaults to `present`)\n\nThe formats of these are the same as in the `mysql_user` module.\n\n    mysql_port: \"3306\"\n    mysql_bind_address: '0.0.0.0'\n    mysql_datadir: /var/lib/mysql\n    mysql_socket: *default value depends on OS*\n    mysql_pid_file: *default value depends on OS*\n\nDefault MySQL connection configuration.\n\n    mysql_log_file_group: mysql *adm on Debian*\n    mysql_log: \"\"\n    mysql_log_error: *default value depends on OS*\n    mysql_syslog_tag: *default value depends on OS*\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    mysql_slow_query_log_enabled: false\n    mysql_slow_query_log_file: *default value depends on OS*\n    mysql_slow_query_time: 2\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    mysql_key_buffer_size: \"256M\"\n    mysql_max_allowed_packet: \"64M\"\n    mysql_table_open_cache: \"256\"\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    mysql_server_id: \"1\"\n    mysql_max_binlog_size: \"100M\"\n    mysql_binlog_format: \"ROW\"\n    mysql_expire_logs_days: \"10\"\n    mysql_replication_role: ''\n    mysql_replication_master: ''\n    mysql_replication_user: []\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 `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\n## additional_parameters\nAlso you can set other parametrs, which are not listed here and it will be written to the configuration file `my.cnf`. \n\nExample:\n```yaml\n     additional_parameters:\n        - name: mysql_expire_logs_days\n          value: 11\n```\n#\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## Dependencies\n\nDue to new breaking changes in MySQL 8.0 we included modified module `mysql_user`. It's shipping with that role and resides in `library` directory. Current Ansible module `mysql_user` is not compatible with latest changes but fixes are already in place and new Ansible release 2.8 should not require customized module to run.\n\n## Example Playbooks\n\n### Installing MySQL 5.7 version:\n```yaml\n- hosts: db-servers\n  roles:\n    - role: lean_delivery.mysql\n  vars:\n    mysql_root_password: Super_P@s$0rd\n    mysql_databases:\n      - name: example2_db\n        encoding: latin1\n        collation: latin1_general_ci\n    mysql_users:\n      - name: example2_user\n        host: \"%\"\n        password: Sime32_U$er_p@ssw0rd\n        priv: \"example2_db.*:ALL\"\n    mysql_port: 3306\n    mysql_bind_address: '0.0.0.0'\n    mysql_daemon: mysqld\n    mysql_version: 5.7\n``` \n\n### Installing MySQL 8.0 version:\n```yaml\n- hosts: db-servers\n  roles:\n    - role: lean_delivery.mysql\n  vars:\n    mysql_root_password: 88TEM-veDRE\u003c888serd\n    mysql_databases:\n      - name: example2_db\n        encoding: latin1\n        collation: latin1_general_ci\n    mysql_users:\n      - name: example2_user\n        host: \"%\"\n        password: Sime32-SRRR-password\n        priv: \"example2_db.*:ALL\"\n    mysql_port: 3306\n    mysql_bind_address: '0.0.0.0'\n    mysql_daemon: mysqld\n    mysql_version: 8.0\n    mysql_packages:\n      - mysql-server\n``` \n\n### Installing MariaDB:\n```yaml\n- hosts: db-servers\n  roles:\n    - role: lean_delivery.mysql\n  vars:\n    mysql_root_password: 88TEM-veDRE\u003c888serd\n    mysql_databases:\n      - name: example2_db\n        encoding: latin1\n        collation: latin1_general_ci\n    mysql_users:\n      - name: example2_user\n        host: \"%\"\n        password: Sime32-SRRR-password\n        priv: \"example2_db.*:ALL\"\n    mysql_port: 3306\n    mysql_bind_address: '0.0.0.0'\n    mysql_daemon: mariadb\n``` \n\n\n__Note__: CentOS always do password reset via `rescue` section: It should be noted that the play continues if a rescue section completes successfully as it ‘erases’ the error status (but not the reporting), this means it will appear in the **playbook statistics** ONLY.\n\n**ATTENTION!** Note that override parameters in playbook have to be set as `role parameters` (see example above). Parameters set as usual hostvars or inventory parameters will not supercede default role parameters set by role scenario depending on OS version etc. \n\n## License\nApache\n\n\n## Author Information\nauthors:\n\n  - Lean Delivery Team team@lean-delivery.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flean-delivery%2Fansible-role-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flean-delivery%2Fansible-role-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flean-delivery%2Fansible-role-mysql/lists"}