gtheys
gtheys

Reputation: 521

Ansible git module not checking out a branch

I'm using ansible to checkout my webapplication on EC2 web instances. My code is as followed:

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

As long as webapp_version = masterit works perfectly. But as soon as I put a SHA1 or Branch name it will fail.

TASK: [webapp | Checkout the source code]
************************************* 
failed: [52.17.69.83] => {"failed": true}
msg: Failed to checkout some-branch

It's quite strange.

I use:

› ansible --version
ansible 1.9.1
  configured module search path = None

Upvotes: 11

Views: 9918

Answers (3)

gtheys
gtheys

Reputation: 521

And again I will answer one of my own questions. The depth=5 was the killer. Well don't use it if you want to have access to all your different versions ;)

Upvotes: 7

VSK
VSK

Reputation: 469

It is the value of the webapp_version in your config file which might be a culprit. I used it in this fashion and tested the code it works for both master and release/1.0 values.

 - name: Checkout the source code
     git:
      dest=/tmp/dump
      force=yes
      key_file=ghtest
      [email protected]:Myrepo/test.git
      update=yes
      version='release/1.0'
     register: git_output

Upvotes: 0

Antonis Christofides
Antonis Christofides

Reputation: 6939

This has nothing to do with git. Your YAML is wrong (I'm surprised it doesn't give you a parsing error). You should either write it like this:

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

i.e. with a > after the git:, which tells YAML to concatenate the following lines into a single line, or like this:

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

i.e. using colons instead of equal signs. In this case the quotes around {{ webapp_dir }} are important (see ansible's documentation about this issue).

Upvotes: -2

Related Questions