How to get SHA of extracted code using available git module?

I would like to keep the commit verification hash SHA-1for the code version with Ansible for the time being.

I want set_factthis version to use in a different role.

+4
source share
1 answer

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.

+10
source

All Articles