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

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.

  • Can't checkout to a new branch - ansible git
  • How do I use remote machine's SSH keys in ansible git module
  • Ansible: Install package with pip from a private git repo
  • Ansible and Git Permission denied (publickey) at Git Clone
  • How to pull while deployment in ansible
  • ansible: git module is hanging
  • How is the git name determined when committing and pushing
  • github not showing last 9 commits
  • How can I revert a push to repository in GitHub
  • GIT pull from a bare repository
  • What's the easiest way in Git to “cherry pick” uncommitted changes to an individual file?
  • Managing the same project with TFS & Git
  • One Solution collect form web for “How do I clone an empty bare repository with Ansible git module?”

    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.

    Git Baby is a git and github fan, let's start git clone.