Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass username and password while using Ansible Git module?

While doing clone, push or pull of a private git repository hosted internally (e.g. on a GitLab instance) with Ansible's Git module, how do I specify username and password to authenticate with the Git server?

I don't see any way to do this in the documentation.

like image 728
karthik v Avatar asked Jun 15 '16 17:06

karthik v


People also ask

How do I stop Git from asking for username and password?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.


1 Answers

You can use something like this:

--- - hosts: all    gather_facts: no   become: yes   tasks:     - name: install git package       apt:         name: git      - name: Get updated files from git repository        git:          repo: "https://{{ githubuser | urlencode }}:{{ githubpassword | urlencode }}@github.com/privrepo.git"         dest: /tmp 

Note: {{ githubpassword | urlencode }} is used here, if your password also contains special characters @,#,$ etc

Then execute the following playbook:

ansible-playbook -i hosts github.yml -e "githubuser=arbabname" -e "githubpassword=xxxxxxx" 

Note: Make sure you put the credentials in ansible vaults or pass it secure way

like image 110
Arbab Nazar Avatar answered Oct 20 '22 18:10

Arbab Nazar