44

I am using ansible to deploy my app. I am cloning the app from github using the following:

- name: Deploy site files from Github repository
  sudo: yes
  git: repo=git@github.com:xyz/abc.git dest=/home/{{deploy_user}}/{{app_name}} key_file=/home/ubuntu/.ssh/id_rsa accept_hostkey=yes force=yes

I want to clone a specific branch from the repository. I read the documentation of ansible but couldn't find any option to clone a specific branch. It has an option to clone a version but not branch.

Ajeet Khan
  • 7,132
  • 8
  • 39
  • 64

2 Answers2

66

From the documentation:

version

What version of the repository to check out. This can be the full 40-character SHA-1 hash, the literal string HEAD, a branch name, or a tag name.

(emphasis mine)

JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226
  • Note: the docu is now at https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html#parameter-version – kghbln May 19 '21 at 09:59
40

Use version, here's the example from the docs:

- git:
    repo: git://foosball.example.org/path/to/repo.git
    dest: /srv/checkout
    version: dev
kqw
  • 19,513
  • 11
  • 64
  • 96
  • Note: the docu is now at https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html#parameter-version – kghbln May 19 '21 at 09:59