Skip to content

Instantly share code, notes, and snippets.

@makmanalp
Created May 12, 2015 13:38
Show Gist options
  • Select an option

  • Save makmanalp/7faabe776c1d363c1bc0 to your computer and use it in GitHub Desktop.

Select an option

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
- 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
@makmanalp
Copy link
Author

I tried to do this without shelling out to git, but the git module in ansible seems quite limited. Better solutions appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment