Skip to content

Instantly share code, notes, and snippets.

@g0053
Forked from vovanmix/mariadb.yml
Created November 20, 2018 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g0053/b5bde2afa147003846aad59f4bc6b084 to your computer and use it in GitHub Desktop.
Save g0053/b5bde2afa147003846aad59f4bc6b084 to your computer and use it in GitHub Desktop.
Install mariadb via ansible on centOS
--- # Install mariadb via ansible on centOS
- hosts: appserver
user: test
sudo: yes
vars:
mysql_root_password: passwd
tasks:
- name: Install MYSQL
yum:
name: mariadb-server #debian: mysql-server
state: present
- name: Install the Python MySQL Support Libraries
yum: pkg=MySQL-python state=latest
- name: start mysql server and enable it on reboot
service: name=mariadb state=started enabled=true #debian: mysql
- name: update mysql root password for all root accounts
mysql_user:
name: root
host: "{{ item }}"
password: "{{ mysql_root_password }}"
login_user: root
login_password: "{{ mysql_root_password }}"
check_implicit_admin: yes
priv: "*.*:ALL,GRANT"
with_items:
- "{{ ansible_hostname }}"
- 127.0.0.1
- ::1
- localhost
- name: Copy the root credentials as .my.cnf file
template: src=root.cnf.j2 dest=~/.my.cnf mode=0600
- name: Create a New Test DB called MyNewDB
mysql_db: name=MyNewDB state=present login_user=root login_password={{ mysql_root_password }}
#
#
#templates/root.cnf.j2
#
#[client]
#user=root
#password={{ mysql_root_pass }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment