Skip to content

Instantly share code, notes, and snippets.

@vovanmix
Last active September 8, 2020 18:59
Show Gist options
  • Save vovanmix/0a2ea225692645ef770e to your computer and use it in GitHub Desktop.
Save vovanmix/0a2ea225692645ef770e 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 }}
@kasplat
Copy link

kasplat commented Jul 31, 2018

Great playbook! Quick note: running this directly had an error because mysql_user and template are conflicting commands. I did not need a to create that file, so I removed the template line, but for others I believe you can also just put a "-" to the left of template and it should work fine.

@jakemalley
Copy link

It looks like the error is because line 30 needs to be outdented 4 spaces, currently it is inside the "with_items" block.

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