--- - name: "Update the my.cnf" template: "src=etc_mysql_my.cnf.j2 dest=/etc/mysql/my.cnf owner=root mode=0644" register: "config_file" notify: - "Restart percona" - name: "Ensure that percona is running and enabled" service: name: "mysql" state: "started" enabled: "yes" register: mysql_service # This service restart is needed when changing default mysql_datadir, mysql_native_password # and other settings. So better restart when the my.cnf file changes # Restart when my.cnf has changed and it has not been restarted by the above task - name: "Restart mysql to apply changes done in my.cnf file" service: name: "mysql" state: "restarted" when: - config_file.changed - mysql_service is defined - not mysql_service.changed