【问题标题】:How to use Ansible git module pull a branch with local changes?如何使用 Ansible git 模块拉出具有本地更改的分支?
【发布时间】:2016-12-16 06:19:12
【问题描述】:

我的 git 工作区很脏,有一些本地修改。当我使用命令git pull origin master 时,它工作正常,因为没有冲突。

但是当我尝试使用 Ansible 时 git: repo=xxxx dest=xxx version={{branch}} 我得到了错误:

存储库中存在本地修改 (force=no)

如果我添加force=yes,那么我将丢失我的本地修改。

如何使用 Ansible git 模块保留本地更改并从 git 中提取最新提交。

【问题讨论】:

    标签: git ansible ansible-playbook devops


    【解决方案1】:

    你无法使用 git 模块来实现它。

    Ansible 检查the result of:

    git status --porcelain
    

    和aborts task execution,如果跟踪文件有本地更改,除非force参数设置为true。

    【讨论】:

    • 那么,唯一的办法是使用shell命令还是尽量保持工作空间干净?
    • 是的。 Git 模块不允许这样做,并且没有其他模块调用git pull。
    • 非常感谢 :)
    【解决方案2】:

    你可以使用类似的东西:

    git: repo=xxxx dest=xxx version={{branch}} force=no
    ignore_errors: yes
    

    见https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#ignoring-failed-commands

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 2019-08-09
      • 2017-05-28
      • 2022-01-23
      • 1970-01-01
      • 2021-07-31
      • 2012-12-20
      • 2017-06-21
      相关资源
      最近更新 更多