Created
May 25, 2017 11:20
-
-
Save mahemoff/e21eecf4c4e27da5f2ae14265127245a to your computer and use it in GitHub Desktop.
Ansible: Restart server only if config changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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