0

My question is that I want to copy a specific file from private git repository to remote server with ansible but I don't want to use ssh key. Do you know any alternative way like such as with api key? Like below code sample Im getting permission issue, so I want to add api key or sth else to get repo file.

---
- name: Sample
  hosts: localhost
  connection: local
  become: true
  tasks:
   - name: Copy
     become: yes
     git:
        repo: 'https://gitlab.com/sample-project/branch-a/sample.xml'
        dest: "/home/sample-file"
Dylan_
  • 53
  • 1
  • 11

1 Answers1

1

You can use

---
- name: Sample
  hosts: localhost
  connection: local
  become: true
  tasks:
   - name: Copy
     become: yes
     git: 
       repo: "https://{{ username| urlencode }}:{{ deploy_token | urlencode }}@gitlab.com/sample-project/branch-a/sample.xml"
       dest: /home/sample-file
Iron Bishop
  • 1,749
  • 1
  • 7
  • 16
  • So when I try to run with like `repo: "https://userA:sampleUBFuhb24hfagb48234@gitlab.com/sample-project/branch-a/sample.xml"` Im getting error now like this **\nfatal: unable to update url base from redirection:** Did I write correct syntax for the username and token? – Dylan_ Feb 14 '20 at 09:01
  • That error means the part after the @ is not understood as a valid repo. Try using `version: branch-a` to specify the branch, or switch to a `command: git archive ...` task instead of `git: ...` since you need a single file. – Iron Bishop Feb 14 '20 at 09:39
  • edited after @gitlab part and it works now, thank you. – Dylan_ Feb 14 '20 at 09:53