Skip to content

Instantly share code, notes, and snippets.

@doojin
Last active November 15, 2023 22:14
Show Gist options
  • Save doojin/85c476572c012a5b52eab349d86db002 to your computer and use it in GitHub Desktop.
Save doojin/85c476572c012a5b52eab349d86db002 to your computer and use it in GitHub Desktop.
Ansible: Minimal MySQL server setup
- name: Set up mysql server
hosts: mysql
become: yes
tasks:
- name: Install mysql server
apt:
pkg:
- mysql-server
- python3-mysqldb
state: present
update_cache: yes
cache_valid_time: 3600
- name: Start mysql service
service:
name: mysql
state: started
- name: Create mysql user
mysql_user:
name: '{{ mysql_user }}'
password: '{{ mysql_password }}'
priv: '*.*:ALL'
host: '%'
state: present
- name: Create mysql database
mysql_db:
name: '{{ mysql_database }}'
state: present
- name: Enable remote mysql access
ini_file:
dest: /etc/mysql/my.cnf
section: mysqld
option: bind-address
value: 0.0.0.0
notify:
- Restart mysql
handlers:
- name: Restart mysql
service:
name: mysql
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment