【问题标题】:how to avoid ansible git module storing credentials?如何避免 ansible git 模块存储凭据?
【发布时间】:2020-01-07 09:00:08
【问题描述】:

我正在观察 ansible git 模块在使用以下模块时正在存储凭据(uname/pwd) 如何解决这个问题?请指教

- name: pull v016 repo from git
    git: repo=https://{{ githubuser }}:{{ githubpassword|urlencode }}@git.abc.com/abc/abc.git
         dest=/tmp/test/abc
         accept_hostkey=yes
         update=yes
         clone=no
         force=yes
         remote=origin
         version=20190524v016

我尝试使用 git-credential-cache 来避免以纯文本形式存储密码,但它没有按预期工作

作为权宜之计,我使用 git set-url 命令来避免其他人在运行 playbook 时遇到问题

【问题讨论】:

  • 为什么不使用 SSH 密钥对和 SSH URL?
  • 您好,感谢您的建议,根据我收集的阅读文档,要使用 ssh 密钥对和 URL,有先决条件,例如,要在远程系统上启用 ssh 代理转发,这可能并不容易检查和配置如果我错了请纠正我!

标签: git ansible


【解决方案1】:

如果您不能使用更好的解决方案 SSH 密钥对,您可以使用提示并参考用户名/密码。

取自documentation

在运行 playbook 时,您可能希望提示用户进行某些操作 输入,并且可以使用“vars_prompt”部分来完成。

此方法的常见用途可能是要求您提供敏感数据 不想录音。

---
- hosts: all
  vars_prompt:

    - name: username
      prompt: "What is your username?"
      private: no

    - name: password
      prompt: "What is your password?"

  tasks:

    - debug:
        msg: 'Logging in as {{ username }}'

另外值得注意的是,默认情况下用户输入是隐藏的,文档也建议这样做。

【讨论】:

  • 是的,这正是我目前在剧本中所拥有的...... vars_prompt: - name: "githubuser" prompt: "Enter your github username" private: no - name: "githubpassword" prompt :“输入您的 github 密码” 私人:是但它仍然会缓存凭据,当另一个用户尝试运行 playbook 时,它会给出如下错误 Authentication failed for 'mohan....... '
猜你喜欢
  • 1970-01-01
  • 2016-09-29
  • 2010-09-12
  • 2018-01-30
  • 2019-10-04
  • 1970-01-01
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
相关资源
最近更新 更多