Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ansible: Restart server only if config changed
- name: Backup original my.cnf
copy: remote_src=true src=/etc/mysql/my.cnf dest=/tmp/my.cnf.recent
- name : Update my.cnf
template: src=my.cnf.j2 dest=/etc/mysql/my.cnf owner=mysql mode=0644
# diff returns error code if different, so we ignore "errors"
- name: Check if my.cnf changed
command: diff /etc/mysql/my.cnf /tmp/my.cnf.recent
ignore_errors: true
register: mysql_diff
- name: Restart MySQL service if my.cnf changed
service: name=mysql state=restarted
when: "{{mysql_diff.rc}} > 0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment