5
votes

Hi I want to execute the following as ansible task to pull the latest commit id on local:

  - name: get latest git commit id
    local_action: "command git rev-parse HEAD"
    register: git_commit_id

but I'm getting a warning because I'm using command. Since git is an ansible core module: http://docs.ansible.com/ansible/git_module.html

How can I execute this using git module?

2

2 Answers

2
votes

If you put this in your vars file:

base: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"

and then use the variable {{base}} in your playbook that should do it.

0
votes

You can try and see if "running an ansible local task in a remote playbook" applies in your case, using delegation and the shell module:

local_action: <module_name> <arguments>
# in your case
local_action: shell git rev-parse HEAD