ssh配置导致Ansible并发失败

  Ansible并发失败原因,  fork=100. 执行playbook时候没有并发

vim /usr/lib/python2.7/site-packages/ansible/runner/connection_plugins/ssh.py

299     ┊   if C.HOST_KEY_CHECKING and not_in_host_file:
300     ┊   ┊   # lock around the initial SSH connectivity so the user prompt about whether to add
301     ┊   ┊   # the host to known hosts is not intermingled with multiprocess output.
302     ┊   ┊   fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_EX)
303     ┊   ┊   fcntl.lockf(self.runner.output_lockfile, fcntl.LOCK_EX)
304          
305     ┊   # create process
306     ┊   (p, stdin) = self._run(ssh_cmd, in_data)

以上代码可以看出, 如果ansible配置HOST_KEY_CHECKING=true. 并且要链接的机器没有在~/.ssh/known_hosts里面, 一个进程就会锁死~/.ssh/known_hosts文件. 这样ansible就不能并发.

检查自己的ssh conf. 发现"    UserKnownHostsFile /dev/null"

这样就不会有机器在~/.ssh/known_hosts中, 所以每个task都不能并发.

最终解决方案:

host_key_checking = False 在ansible.cfg中.

posted @ 2016-03-15 13:51  mxking  阅读(2671)  评论(0编辑  收藏  举报