Skip to content

Instantly share code, notes, and snippets.

@ihassin
Created December 24, 2013 00:17
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save ihassin/8106956 to your computer and use it in GitHub Desktop.
Save ihassin/8106956 to your computer and use it in GitHub Desktop.
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
@tejas-2232
Copy link

this is great. 👏
Thanks.
can you tell me for which OS this code is intended?

@shivapal98
Copy link

this is great. 👏
Thanks.
can you tell me for which OS this code is intended?

linux family

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment