---
# tasks file for ansible-mysql

- name: Preseed (always changes)
  when: mysql_root_password is defined
  debconf:
    name: mysql-server-5.5
    question: '{{ item }}'
    vtype: password
    value: '{{ mysql_root_password }}'
  with_items:
    - mysql-server/root_password
    - mysql-server/root_password_again
  register: mysql_debconf

- name: apt install
  apt:
    name: '{{ item }}'
    state: present
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - mysql-server-5.5
    - mysql-client-5.5
    - python-mysqldb
    - cron

- name: Reconfigure (if needed)
  when: mysql_debconf.changed
  command: /usr/sbin/dpkg-reconfigure --frontend noninteractive mysql-server-5.5

- name: Add daily backup job
  copy:
    src: backup.sh
    dest: /etc/cron.daily/mysql
    owner: root
    group: root
    mode: '0755'
