###############################################################################
# Install and configure MySql defaults
###############################################################################
---

- name: Update APT cache
  action: apt update_cache=true

- name: Install MySql
  action: apt pkg={{ item }} force=yes state=present
  with_items: 
    - mysql-server
    - libmysqlclient-dev

# 'localhost' needs to be the last item for idempotency, see
# http://ansible.cc/docs/modules.html#mysql-user
- name: update mysql root password for all root accounts
  mysql_user: name=root host=$item password=$root_db_password
  with_items:
    - $ansible_hostname
    - 127.0.0.1
    - ::1
    - localhost

#- name: copy .my.cnf file with root password credentials
#  template: src=templates/root/.my.cnf dest=/root/.my.cnf owner=root mode=0600

- name: ensure anonymous users are not in the database
  mysql_user: name='' host=$item state=absent
  with_items:
    - localhost
    - $inventory_hostname

- name: remove the test database
  mysql_db: name=test state=absent
