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

问题描述

我正在使用Ansible,并且我很难让git模块正常工作。
我已经阅读了几篇有同样问题的人的帖子,我看了一下文档,我尝试了几乎所有的东西。
我找到了一个清楚的教程,我一直遵循,直到他们使用git,但是当我使用我的存储库时,我遇到了问题...:/
git任务挂起...没有错误,它只是卡住!



这是我的主机文件:

  [web] 
dev1 ansible_ssh_host = 10.0.0.101 ansible_ssh_user = root

这是一个在virtualbox上运行的流浪VM在我的电脑上。



我从本教程中学习了这本手册,并执行了所有步骤直到步骤08:



我在我的虚拟机上运行它,它工作正常,然后添加一个任务部署我的代码以使用我的存储库...但这个任务不起作用。它是bitbucket上的私有存储库。它有什么不同?

   -  hosts:web 
任务:

- 名称:部署我们的应用程序
action:git repo = https://github.com/leucos/ansible-tuto-demosite.git dest = / var / www / awesome-app
tags:deploy

- name:部署我的代码
action:git repo = https://YAmikep@bitbucket.org/YAmikep/djangotutorial.git dest = / var / www / my-app
标签:部署

用户可能会遇到某些问题,或者用户正在运行ansible或keys,等等,但是我反复尝试了好几个小时,而现在我更加困惑......我只是不知道该怎么做才能调试它,并找出错误以及我错过了什么。



谢谢。

解决方案

有几个原因可能导致git模块挂起,但最可能的是,如果主机密钥应该添加到y中, git clone 命令正在等待确认我们服务器的已知主机。要验证这是否是问题,执行符合以下标志的命令: - verbose ,以便它以详细模式运行,这将为您提供有关该错误的更多信息。

如果您确认已知的主机存在问题,那么您有两种选择:

解决方案1 ​​

为避免出现模块使用 accept_hostkey 参数。

  -  name:确保jquery repo可用
git:git@github.com:jquery / jquery.git version = master accept_hostkey = True






解决方案2

使用第三方模块在使用核心模块模块之前:

   -  name:确保github是一个已知的主机
操作:sshknownhosts host = github.com state = present

- name:确保jquery repo可用
git:git@github.com:jquery / jquery.git version = master accept_hostkey = True

由于 knownhosts 不是核心模块,您需要先安装它,请参阅以获取更多信息,以了解如何安装它。






另一个解决方案是禁用ssh主机密钥检查,但这具有安全性所以除非你真的知道自己在做什么,否则最好避免这种情况。


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!

Here is my host file:

[web]
dev1 ansible_ssh_host=10.0.0.101 ansible_ssh_user=root

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

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

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

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.

Thanks.

解决方案

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:

Solution 1:

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


Solution 2:

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

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.


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