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.

  • Ansible web server role versioning strategy for several environments
  • ansible: git module is hanging
  • creating jenkins jobs with ansible
  • How to get the SHA of the checked out code with ansible git module?
  • ansible - iterate all hosts and retrieve data from results
  • How to get an Ansible check to run only once in a playbook?
  • Git submodule update from post-receive hook
  • Is Git only for source control?
  • Gradle script to autoversion and include the commit hash in Android
  • Issue in sending new user notification in GitLab
  • Checking out a maven project from a git repository
  • git: need to parse commit messages looking for pattern and storing in list
  • 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.