Ansible git模块没有检出分支

时间:2015-06-12 09:17:41

标签: git ansible

我正在使用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 个答案:

答案 0 :(得分:7)

我将再回答一个问题。 depth=5是杀手。如果您想访问所有不同版本,请不要使用它;)

答案 1 :(得分:0)

它是配置文件中webapp_version的值,可能是罪魁祸首。我以这种方式使用它并测试了它适用于master和release / 1.0值的代码。   - 名称:签出源代码      混帐:       DEST = / TMP /转储       力= YES       KEY_FILE = ghtest       repo=git@github.com:Myrepo / test.git       更新= YES       版本='释放/ 1.0'      register:git_output

答案 2 :(得分:-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's documentation about this issue)。