0

What specific syntax needs to be used to get Ansible to clone a git repository from Azure Repositories?

The repository URL is https://OrganizationName@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName and we are able to clone it manually in an interactive shell by providing a requested password which we possess as follows:

$ git clone https://OrganizationName@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName  
Password for 'https://OrganizationName@dev.azure.com':

However, the Ansible example task that we have from the official Ansible documentation does not include any mention of a password, as follows:

- name: Clone a repo 
  git:
    repo: https://OrganizationName@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName
    dest: /src/RepositoryName
CodeMed
  • 9,527
  • 70
  • 212
  • 364

1 Answers1

2

Your password must be in your repo link as below

--- 
- name: Clone repo playbook
  hosts: dev

  vars_prompt: 
    - name: "git_user" 
      prompt: "Enter your git username" 
      private: no
    - name: "git_password" 
      prompt: "Password for 'https://OrganizationName@dev.azure.com'"
      private: yes 

  tasks:
  - name: Clone a repo 
    git:
      repo: https://{{ git_user | urlencode }}:{{ git_password | urlencode }}@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName
      dest: /src/RepositoryName
gary lopez
  • 1,823
  • 7
  • 15
  • I just edited my answer I hope it could be useful for you. – gary lopez Nov 04 '20 at 00:17
  • When you use `vars_prompt` and execute your playbook, ansible ask you by both variables and you have to write them in your console. Other way could be add both variables in your `myVars.yaml` file and just add once the file in `vars_files` block. Try it and if you have some problems i'll help you gladly – gary lopez Nov 04 '20 at 01:40