【问题标题】:git add, commit, push using Ansible to Azure Repo使用 Ansible 向 Azure Repo 添加、提交、推送
【发布时间】:2020-11-05 00:35:31
【问题描述】:

开发人员刚刚完成了对 Dev 服务器上的某些代码的更改,该服务器使用 Ansible 从 Azure git 存储库收到了 git clone

在 Ansible 任务中必须使用什么特定语法来 addcommitpush 开发人员将代码从 Dev 服务器更改回同一 Azure git 存储库? p>

以下是@garylopez贡献的git clone Ansible 任务:

--- 
- name: Clone repo playbook
  hosts: dev

  vars_prompt: 
    - name: "git_password" 
      prompt: "Password for 'https://OrganizationName@dev.azure.com'"
      private: yes 

  tasks:
  - name: Clone a repo 
    git:
      repo: https://{{ git_user | urlencode }}:{{ git_password | urlencode }}@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName
      dest: /src/RepositoryName  

我们检查了 Ansible git 模块的 docs,但没有看到样板示例。

如果 Ansible git 模块不支持这一点,我们想象有人可能会在 Ansible 任务中诉诸某种 shell 命令解决方案。但我们在这里提出问题,希望可以在答案中提供最佳实践类型的方法。

【问题讨论】:

  • git 模块只会让您获得远程存储库的全新克隆以用于部署目的。通过添加到现有模块或提供新模块(一个示例:github.com/ansible-collections/community.general/pull/168)来向 ansible 提供添加/提交/推送功能已经有多种尝试。但据我所知,没有人能将其释放。现在,您将不得不走命令/shell 路线。

标签: git ansible azure-repos


【解决方案1】:

您可以使用 git 模块进行结帐和 shell 命令添加提交推送 https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html

【讨论】:

  • 不,我很确定你不能。查看您发布的 git_module 链接,模块描述显示“管理存储库的 git 签出以部署文件或软件” - 因此没有提及更新存储库,也没有此类参数可用。我很高兴被证明是错误的,但看起来你确实误解了这个模块(另见 Zeitounator 对这个问题的评论)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多