本文介绍了ansible:git 模块挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Ansible and I am having a hard time making the git module works.I have read several posts of people having the same problem, I looked at the ansible doc, well I tried almost everything.I found a clear tutorial that I followed until they use git but again I have a problem when I use my repository... :/The git task just hangs... no error, it is just stuck!

这是我的主机文件:

[web]
dev1 ansible_ssh_host=10.0.0.101 ansible_ssh_user=root

这是一个运行在我电脑上的虚拟机上的流浪虚拟机.

This is a vagrant VM running on virtualbox on my computer.

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

I took the playbook from this tutorial and did all the steps until step 08: https://github.com/leucos/ansible-tuto/tree/master/step-08

我在我的虚拟机上运行它,它工作正常,然后我添加了一个任务部署我的代码"来使用我的存储库......但这个任务不起作用.它是 bitbucket 上的私有存储库.有区别吗?

I run it on my VM, it works fine, then I add one task "Deploy my code" to use my repository... but this task does not work. It is a private repository on bitbucket. Does it make a difference?

- 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,或者密钥等,但我来回尝试了几个小时,现在我更加困惑......我只是不知道该怎么做立即调试并找出问题所在以及我遗漏了什么.

There might be something with the user, or the user running ansible, or the keys, etc, but I tried back and forth for hours and I am even more confused now... I just do not know what to do to debug that now and find out what is wrong and what I am missing.

谢谢.

推荐答案

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

There are a couple of reasons why the git module might be hanging, but the most possible is that the git clone command is waiting for a confirmation if the host key should be added to your server's known hosts. To verify if this is the problem execute ansible with the flag: --verbose, so that it runs in verbose mode, this will give you more information about the error.

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

If you confirm that the known hosts is the problem, then you have two choices:

解决方案 1:

为了避免 git 模块出现这个问题,请使用 accept_hostkey代码>参数.

To avoid this problem with the git module use the accept_hostkey parameter.

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

解决方案 2:

在使用核心ansible-sshknownhosts第三方模块="http://docs.ansible.com/git_module.html">git 模块:

Use the ansible-sshknownhosts third-party module before using the core git module:

- 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 有关如何安装它的更多信息.

Since the knownhosts is not a core ansible module, you will need to install it first, please refer to the github repo docs for more information hon how to install it.

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

another solution would be to disable ssh host key checking, but this has security implications, so unless you really know what you are doing it is best to avoid this.

这篇关于ansible:git 模块挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:53