Created
May 12, 2015 13:38
-
-
Save makmanalp/7faabe776c1d363c1bc0 to your computer and use it in GitHub Desktop.
Ansible playbook to include in pre_tasks to complain on deploy if you haven't synced changes
This file contains hidden or 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: run git status | |
| local_action: shell git status | grep "up-to-date with 'origin/master'" | |
| ignore_errors: True | |
| register: git_up_to_date | |
| - name: fail if git not up to date | |
| local_action: fail msg="Please pull / push the latest changes to the playbooks repo before deploying." | |
| when: git_up_to_date | failed | |
| - name: run git diff | |
| local_action: command git status -s | |
| register: git_uncomitted_changes | |
| - name: fail if there are uncommitted changes | |
| local_action: fail msg="Please commit and push your changes to the playbooks repo before deploying, and make sure there are no unstaged files in the playbooks repo." | |
| when: git_uncomitted_changes.stdout|length > 0 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to do this without shelling out to git, but the git module in ansible seems quite limited. Better solutions appreciated!