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中.