gpt4 book ai didi

git - ansible:git 模块挂起

转载 作者:IT王子 更新时间:2023-10-29 01:12:31 28 4
gpt4 key购买 nike

我正在使用 Ansible,但我很难让 git 模块正常工作。我读过几篇遇到同样问题的人的帖子,我查看了 ansible 文档,好吧,我几乎尝试了所有方法。我找到了一个清晰的教程,在他们使用 git 之前我一直遵循该教程,但是当我使用我的存储库时我又遇到了问题...:/git 任务只是挂起...没有错误,它只是卡住了!

这是我的主机文件:

[web]
dev1 ansible_ssh_host=10.0.0.101 ansible_ssh_user=root

这是在我电脑上的 virtualbox 上运行的 vagrant VM。

我从本教程中获取剧本并完成了所有步骤,直到第 08 步:https://github.com/leucos/ansible-tuto/tree/master/step-08

我在我的 VM 上运行它,它工作正常,然后我添加了一个任务“部署我的代码”以使用我的存储库......但是这个任务不起作用。它是 bitbucket 上的私有(private)存储库。有区别吗?

- hosts: web
tasks:

- name: Deploy our awesome application
action: git repo=https://github.com/leucos/ansible-tuto-demosite.git dest=/var/www/awesome-app
tags: deploy

- name: Deploy my code
action: git repo=https://YAmikep@bitbucket.org/YAmikep/djangotutorial.git dest=/var/www/my-app
tags: deploy

用户、运行 ansible 的用户或 key 等可能有问题,但我来回尝试了几个小时,现在我更加困惑了……我只是不知道该怎么做现在调试它并找出问题所在和我遗漏的内容。

谢谢。

最佳答案

git 模块可能挂起的原因有几个,但最有可能的是 git clone 命令正在等待确认是否应将主机 key 添加到服务器的已知主机。要验证这是否是问题,请使用标志执行 ansible:--verbose,以便它以详细模式运行,这将为您提供有关错误的更多信息。

如果您确认已知主机是问题所在,那么您有两个选择:

解决方案 1:

为了避免 git 出现这个问题模块使用 accept_hostkey 参数。

- name: ensure jquery repo is available
git: git@github.com:jquery/jquery.git version=master accept_hostkey=True

解决方案 2:

使用 ansible-sshknownhosts使用核心前的第三方模块git模块:

- name: ensure github is a known host
action: sshknownhosts host=github.com state=present

- name: ensure jquery repo is available
git: git@github.com:jquery/jquery.git version=master accept_hostkey=True

由于 knownhosts 不是核心 ansible 模块,您需要先安装它,请引用 github repo docs有关如何安装它的更多信息。


另一种解决方案是禁用 ssh 主机 key 检查,但这会带来安全隐患,因此除非您真的知道自己在做什么,否则最好避免这种情况。

关于git - ansible:git 模块挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136358/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com