I would like to store the currently checked out commit SHA-1
hash for the version of code with Ansible.
I want to set_fact
of this version for use in another role.
The git
module in Ansible returns this information for you, you just need to register it in a variable (variable is gitresult
in 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 }}"
Running :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With