--- - name: Include OS-specific variables. include_vars: "{{ ansible_os_family }}.yml" - name: Update postfix to the latest version (if extra repositories enabled). yum: > name=postfix state=latest enablerepo={{ mysql_enablerepo }} when: mysql_enablerepo != "" - name: Ensure MySQL packages are installed (RedHat). yum: > name={{ item }} state=installed enablerepo={{ mysql_enablerepo }} with_items: mysql_packages when: ansible_os_family == 'RedHat' - name: Ensure MySQL packages are installed (Debian). apt: > name={{ item }} state=installed with_items: mysql_packages when: ansible_os_family == 'Debian' - name: Copy my.cnf global MySQL configuration. template: > src=my.cnf.j2 dest=/etc/my.cnf owner=root group=root mode=644 notify: restart mysql - name: Ensure MySQL is started and enabled on boot. service: > name={{ mysql_daemon }} state=started enabled=yes - name: Check if .my.cnf file already exists. stat: "path={{ mysql_user_home }}/.my.cnf" register: mycnf_file # '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={{ mysql_root_password }} with_items: - 127.0.0.1 - ::1 - localhost when: mycnf_file.stat.exists == false # Has to be after the root password assignment, for idempotency. - name: Copy .my.cnf file with root password credentials. template: > src=python-my.cnf.j2 dest={{ mysql_user_home }}/.my.cnf owner=root group=root mode=600 - name: Delete anonymous MySQL user for localhost. mysql_user: > name="" state=absent - name: Remove the MySQL test database. mysql_db: > name="test" state=absent