ansible-personal/roles/mariadb/tasks/main.yml
Alan Orth 201165cff6
Only update packages indexes if the cache is 1 hour old
I have added cache_valid_time=3600 for the first task in each
tag that could be possibly running apt-related commands. For ex,
the "nginx" tag is also in the "packages" tag, but sometimes you
run the nginx tag by itself (perhaps repeatadely), so you'd want
to limit the update unless the cache was 1 hour old
2016-08-22 15:33:57 +03:00

62 lines
2.0 KiB
YAML

---
- name: Add GPG key for MariaDB repo
apt_key: id=0xcbcb082a1bb943db url=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xcbcb082a1bb943db
tags: mariadb, packages
- name: Remove old repo file
file: path={{ item }} state=absent
with_items:
- /etc/apt/sources.list.d/sgp1_mirrors_digitalocean_com_mariadb_repo_10_1_debian.list
- /etc/apt/sources.list.d/sgp1_mirrors_digitalocean_com_mariadb_repo_10_1_ubuntu.list
tags: mariadb, packages
- name: Add MariaDB 10.1 repo
template: src=mariadb.list.j2 dest=/etc/apt/sources.list.d/mariadb.list owner=root group=root mode=0644
tags: mariadb, packages
- name: Install mariadb-server
apt: name={{ item }} state=present update_cache=yes cache_valid_time=3600
with_items:
- mariadb-server
- python-mysqldb # for ansible
tags: mariadb, packages
- name: Create system my.cnf
template: src=my.cnf.j2 dest=/etc/mysql/my.cnf owner=root group=root mode=0644
notify:
- restart mysql
tags: mariadb
- name: Start and enable MariaDB Service
service: name=mysql state=started enabled=true
tags: mariadb
# 'localhost' needs to be the last item for idempotency, see
# http://ansible.cc/docs/modules.html#mysql-user
- name: Update MariaDB root password for all root accounts
mysql_user: name=root host={{ item }} password={{ mariadb_root_password }}
with_items:
- "{{ inventory_hostname }}"
- 127.0.0.1
- ::1
- localhost
tags: mariadb
- name: Create .my.conf file with root credentials
template: src=.my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600
tags: mariadb
- name: Create MariaDB database(s)
mysql_db: db={{ item.name }} state=present encoding=utf8mb4
with_items: "{{ mariadb_databases }}"
when: mariadb_databases is defined
tags: mariadb
- name: Create MariaDB user(s)
mysql_user: name={{ item.user }} password={{ item.pass }} priv={{ item.name }}.*:ALL state=present
with_items: "{{ mariadb_databases }}"
when: mariadb_databases is defined
tags: mariadb
# vim: set ts=2 sw=2: