本文介绍了使用Ansible Git模块时如何传递用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Ansible的Git模块克隆,推入或拉入内部托管的私有git存储库时(例如,在GitLab实例上),我如何指定用户名和密码来通过Git服务器进行身份验证?
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.
推荐答案
您可以使用以下内容:
---
- 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
注意::如果您的密码还包含特殊字符@,#,$等,则在此处使用{{ githubpassword | urlencode }}
Note: {{ githubpassword | urlencode }}
is used here, if your password also contains special characters @,#,$ etc
然后执行以下剧本:
ansible-playbook -i hosts github.yml -e "githubuser=arbabname" -e "githubpassword=xxxxxxx"
这篇关于使用Ansible Git模块时如何传递用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!