The module gitin Ansible returns this information for you, you just need to register it in a variable (the variable gitresultin the example below).
- hosts: web
tasks:
- name: Checkout repo
git:
repo=https://github.com/michalgasek/www-discogs.git
dest=/vagrant/checkout
update=yes
accept_hostkey=yes
register: gitresult
- debug: msg="SHA-1 before git update is {{ gitresult.before }}"
- debug: msg="SHA-1 after git update is {{ gitresult.after }}"
Launch:
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [192.168.2.201]
TASK [Checkout repo] ***********************************************************
ok: [192.168.2.201]
TASK [debug] *******************************************************************
ok: [192.168.2.201] => {
"msg": "SHA-1 before git update is 87544e2ea1c8dec30e5fc68302caa262b10affda"
}
TASK [debug] *******************************************************************
ok: [192.168.2.201] => {
"msg": "SHA-1 after git update is 87544e2ea1c8dec30e5fc68302caa262b10affda"
}
I hope it solves your problem.
source
share