---
# Here are the few steps that I have performed to get the `debconf` setting information:
#
# - downloaded the mysql-apt-repo from the mysql official site(named: mysql-apt-config_0.6.0-1_all.deb)
# - Find the `debconf` setting information after installing this `deb` package
#
# # debconf-show mysql-apt-config
# * mysql-apt-config/select-server: mysql-5.6
#   mysql-apt-config/unsupported-platform: abort
#   mysql-apt-config/repo-codename: precise
# * mysql-apt-config/select-product: Apply
#   mysql-apt-config/select-tools:
#   mysql-apt-config/repo-distro: ubuntu
#
# - Even to get more information about the `debconf` options of the package:
#
# # debconf-get-selections|grep mysql-apt-config
# mysql-apt-config  mysql-apt-config/select-server  select  mysql-5.6
# mysql-apt-config  mysql-apt-config/unsupported-platform select  abort
# mysql-apt-config  mysql-apt-config/repo-codename  select  precise
# mysql-apt-config  mysql-apt-config/select-product select  Apply
# mysql-apt-config  mysql-apt-config/select-tools select
# mysql-apt-config  mysql-apt-config/repo-distro  select  ubuntu
#
# - After the installation, I have checked the `/etc/apt/sources.list.d` directory and found one file `mysql.list`
# with following contents:
#
# deb http://repo.mysql.com/apt/ubuntu/ precise mysql-apt-config
# deb http://repo.mysql.com/apt/ubuntu/ precise mysql-5.6
# deb-src http://repo.mysql.com/apt/ubuntu/ precise mysql-5.6
#
#
# Thought that instead of performing all those steps and get the repo, why not directly use this repo
# `deb http://repo.mysql.com/apt/ubuntu/ precise mysql-5.6`, I just picked this line and directly used it and it worked for us.

- name: Add MySQL community apt key
  apt_key:
    id: 8C718D3B5072E1F5
    keyserver: "{{ COMMON_EDX_PPA_KEY_SERVER }}"
    state: present
  when: ansible_distribution_release == 'precise'

# Despite ondrej's ppa having 12.04 support, we would need to do shenanigans and uninstalling
# to switch back cleanly without publishing a new base devstack box.  Easier to just clean this
# up with Ficus.
- name: Install MySQL from their community PPA
  apt_repository:
    repo: "deb http://repo.mysql.com/apt/ubuntu/ precise mysql-5.6"
    update_cache: yes
  when: ansible_distribution_release == 'precise'

- name: Install mysql-5.6 and dependencies
  apt:
    name: "{{ item }}"
    install_recommends: yes
    state: present
  with_items: "{{ mysql_debian_pkgs }}"

- name: Start mysql
  service:
    name: mysql
    state: started

- name: Ensure Anonymous user(s) does not exist
  mysql_user:
    name: ''
    host: "{{ item }}"
    state: absent
  with_items:
    - localhost
    - "{{ ansible_hostname }}"