可靠的git模块rev解析



嗨,我想执行以下任务作为ansible任务,以获取本地的最新提交id:

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

但我收到了警告,因为我正在使用command。由于git是一个可靠的核心模块:http://docs.ansible.com/ansible/git_module.html

如何使用git模块执行此操作?

如果你把它放在你的vars文件中:

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

然后在你的剧本中使用变量{{base}}

您可以尝试使用委派shell模块来查看"在远程剧本中运行可应答的本地任务"是否适用于您的情况:

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

最新更新