Ansible git模块未检出分支

10

我正在使用ansible在EC2 web实例上检出我的Web应用程序。 我的代码如下:

- name: Checkout the source code
  git:
    accept_hostkey=yes
    depth=5
    dest={{ webapp_dir }}
    force=yes
    key_file=/var/tmp/webapp_deploy_key
    repo=git@github.com:MyRepo/web-app.git
    update=yes
    version={{ webapp_version }}
  register: git_output

只要 webapp_version = master,它就能完美运行。但是一旦我输入 SHA1 或分支名称,它就会失败。
TASK: [webapp | Checkout the source code]
************************************* 
failed: [52.17.69.83] => {"failed": true}
msg: Failed to checkout some-branch

我很奇怪。

我使用:

› ansible --version
ansible 1.9.1
  configured module search path = None
3个回答

7

我再次回答自己的一个问题。这里depth=5是致命的。如果您想要访问所有不同版本,请不要使用它;)


4
如果有其他人来到这里,我必须移除depth属性,然后在整个git目录上运行“rm -rf”命令,才能让它工作。 - winduptoy
谢谢 @WindUpToy!这起到了作用! - bastianwegge
好的,深度不是问题,除非你确实想要在那里检出不同的分支。在我的情况下,只需删除 src 然后重新运行即可,无论是否采用深度选项。 - Anderson Santos

0

可能是您配置文件中的webapp_version值有问题。我以这种方式使用它并测试了代码,它适用于主版本和发布/1.0版本。

 - name: Checkout the source code
     git:
      dest=/tmp/dump
      force=yes
      key_file=ghtest
      repo=git@github.com:Myrepo/test.git
      update=yes
      version='release/1.0'
     register: git_output

1
我之前也尝试过像你一样显式地做,但也不起作用。我可以看到服务器上除了主分支之外没有其他分支... - gtheys

-2

这与git无关。你的YAML格式是错误的(我很惊讶它没有给你一个解析错误)。你应该像这样写:

- name: Checkout the source code
  git: >
    accept_hostkey=yes
    depth=5
    dest={{ webapp_dir }}

即在 git: 后面加上 >,告诉 YAML 将以下行连接成一行,或者像这样:
- name: Checkout the source code
  git:
    accept_hostkey: yes
    depth: 5
    dest: "{{ webapp_dir }}"

即使用冒号代替等号。在这种情况下,围绕{{ webapp_dir }}的引号很重要(请参见ansible文档中有关此问题的说明)。


1
我知道引号的问题。此外,> 不是必需的,因为我编写的 100 个任务都可以完美地工作而没有 >。这个检查是有效的,所以在我看来它不是语法错误。只有当我指定一个分支而不是主分支时,它才无法工作。但是为了测试你的建议,我尝试了一下,结果出现了相同的问题。因此,我可以得出结论,这不是语法错误。 - gtheys

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接