Working to clone a git repository that requires credentials because it is private (to complicate it more, it has a submodule that is also private, but this is a secondary question). I would like to clone in the remote but not giving it the rights to write in the repo. So, maybe wrong, I discarded to use ssh key but https with login/passwd.
- name: "git clone"
git:
repo: https://{{ username | urlencode }}:{{ password | urlencode }}@gitlab.com/(...)/repo.git
dest: {{ sources_dir }}/repo.git
update: yes
This seems to work, but when I check the remote I see the credentials leaked there.
$ cd repo.git
$ git remote -v
origin https://<username>:<password>@gitlab.com/(...)/repo.git
The alternative I'm working with, expect
doesn't seem to catch the responses.
- name: "git clone"
expect:
chdir: {{ sources_dir }}
command: git clone repo: https://gitlab.com/(...)/repo.git repo.git
responses:
(?i)username: {{ username | urlencode }}
(?i)password: {{ password | urlencode }}
The output seems to be something like:
Cloning into 'repo.git'...
Username for 'https://gitlab.com': Password for 'https://<username>@gitlab.com':
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.com/(...)/repo.git/
Checked that the password (stored in a ansible-vault) is correct, from this answer seems that the username is catch (because it is printed in the stdout) but the auth fails anyway.
The general question is how this clone can be made without transferring rights to the place of the clone over the repo? And also understand how this regex in the responses would work. Also some information about ansible with git submodules could be nice, but I'll try further investigation from my side.
Thanks