使用 Ansible Git 模块时如何传递用户名和密码? [英] How do I pass username and password while using Ansible Git module?

查看:33
本文介绍了使用 Ansible Git 模块时如何传递用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Ansible 的 Git 模块克隆、推送或拉取内部托管的私有 git 存储库(例如在 GitLab 实例上)时,如何指定用户名和密码以通过 Git 服务器进行身份验证?

我在文档中没有看到任何方法可以做到这一点.

解决方案

你可以这样使用:

---- 主持人:所有收集事实:没有变成:是任务:- 名称:安装 git 包易于:名称: git- 名称:从 git 存储库获取更新的文件吉特:回购:"https://{{ githubuser |urlencode }}:{{ github密码 |urlencode }}@github.com/privrepo.git"目标:/tmp

注意: {{ githubpassword |urlencode }} 在这里使用,如果您的密码还包含特殊字符@,#,$ 等

然后执行以下剧本:

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

<块引用>

注意:确保将凭据放入 ansible 保管库或传递它安全方式

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.

解决方案

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

这篇关于使用 Ansible Git 模块时如何传递用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆