--- # Set root password # UPDATE mysql.user SET Password=PASSWORD('mysecret') WHERE User='root'; # FLUSH PRIVILEGES; - name: Update database root password mysql_user: name: 'root' host: 'localhost' password: '{{ mysql_root_password }}' - name: Create /root/.my.cnf file with root credentials template: src : 'my.cnf.j2' dest : '/root/.my.cnf' owner: 'root' group: 'root' mode : '0600' - name: Delete anonymous database user mysql_user: user : "" host : '{{ item }}' state: 'absent' with_items: [ '{{ ansible_hostname }}', 'localhost' ] - name: Reload privilege tables command: 'mysql -ne "{{ item }}"' with_items: - FLUSH PRIVILEGES changed_when: False - name: Remove test database and access to it command: 'mysql -ne "{{ item }}"' with_items: - DROP DATABASE test - DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%' changed_when: False ignore_errors: True - name: Reload privilege tables command: 'mysql -ne "{{ item }}"' with_items: - FLUSH PRIVILEGES changed_when: False