如何使用 ansible 执行 git pull/push

gra*_*lor 10 configuration-management ansible centos7

我正在尝试使用 ansible 进行 git pull/push。我在一台服务器上运行 ansible,并希望在远程主机上自动化或编排 git pull/push。

现在,由于我没有在 ansible doc 网站上找到 mmodule 来执行此操作,因此我决定使用脚本模块走脚本路线

当它开始运行脚本中调用的 git pull 时,问题是 ansible hags

有人知道如何使用 ansible 运行 git pull/push 吗?

谢谢

Pro*_*ken 18

就“拉”而言,Ansible 的 Git 模块将为您执行此操作,只需确保运行该命令的用户具有对 git 存储库的基于密钥的访问权限。

您可以通过将“sudo_user”参数添加到您的任务来指定命令运行的用户:

- name: Get stuff from git
  git:
    repo: git@github.com:you/your-git-repo.git
    dest: /opt/git-stuff
  sudo_user: <your user that has the ssh key>
Run Code Online (Sandbox Code Playgroud)

有关使用 sudo_user 的更多信息,请参阅https://docs.ansible.com/playbooks_intro.html

  • 这不是要克隆吗?我想要拉取仅更新更改..而不是克隆整个存储库 (4认同)
  • `src` 现在似乎已更改为 `repo`,仅供参考。 (3认同)
  • 来自http://docs.ansible.com/git_module.html:更新 - 如果否,请勿从原始存储库检索新修订(在 Ansible 1.2 中添加) 我的理解是,如果存储库已经存在,它将更新,否则它会克隆 (2认同)

Sou*_*dar 7

它应该是这样的:-

tasks: - name: pull from git git: repo: git@gitlab.com:xyz.git dest: /root/Development/abc update: yes version: master

注意:这里远程用户是root

  • 但是接受的答案似乎不起作用,git 没有名为 src 的参数,我使用 repo 代替。@ceejayoz (3认同)