Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clone an empty bare repository with Ansible git module?

Tags:

git

ansible

I have an empty and bare repository which I'm trying to clone with Ansible, but the git module is trying to checkout master and thus fails, since there is no such refspec in an empty repo.

My only way to get this working has been a shell command to just clone the repo.

like image 516
deiga Avatar asked Jul 03 '16 10:07

deiga


1 Answers

I tried in every way and the only way that worked was to add ignore_errors: true and than check what made the Ansible module to fail. I know it is not optimal but it works and we are not letting all the errors to pass thru:

- git: repo=<YOUR REPO> dest=<DEST>
  ignore_errors: true
  register: output
- name: check the error that failed the git module
  fail: msg="{{ output.msg }}"
  when: "'Failed to checkout branch master' not in output.msg"

BTW I filter the output.msg and not the output.stderr because for some reason on that specific error it goes out to the .msg but not to the .stderr.

like image 85
Moises Rezonzew Avatar answered Oct 20 '22 04:10

Moises Rezonzew