Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ansible script to install mySQL
- hosts: webservers
user: vagrant
sudo: true
vars_files:
- vars.yml
tasks:
- name: Install MySQL
action: apt pkg=$item state=installed
with_items:
- mysql-server-core-5.5
- mysql-client-core-5.5
- libmysqlclient-dev
- python-mysqldb
- mysql-server
- mysql-client
- name: Start the MySQL service
action: service name=mysql state=started
- name: Remove the test database
mysql_db: name=test state=absent
- name: Create deploy user for mysql
mysql_user: user="deploy" host="%" password={{mysql_root_password}} priv=*.*:ALL,GRANT
- name: Ensure anonymous users are not in the database
mysql_user: user='' host=$item state=absent
with_items:
- 127.0.0.1
- ::1
- localhost
- name: Copy .my.cnf file with root password credentials
template: src=templates/.my.cnf dest=/etc/mysql/my.cnf owner=root mode=0600
- name: Update mysql root password for all root accounts
mysql_user: name=root host={{item}} password={{mysql_root_password}}
with_items:
- 127.0.0.1
- ::1
- localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment