5

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 Answers 2

2

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

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
3
  • not sure I follow, you are still using "shell" module and not "git" module. I get the same warning. Note that the "command" module works too, I just get a warning and was wondering if I can get rid of warning (not supress it)
    – Ankit
    May 10, 2016 at 21:45
  • @Ankit What warning do you get?
    – VonC
    May 11, 2016 at 5:59
  • 2
    [WARNING]: Consider using git module rather than running git I've temporarily disabled it using: local_action: "shell git rev-parse HEAD warn=no"
    – Ankit
    May 13, 2016 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.