在我的情况下,Ansible一直“挂起”,因为apt-get试图询问我一个问题!我是如何发现这个问题的?我去目标服务器上运行了
ps -aef | grep apt
命令,然后在适当的“卡住”的
apt-get
命令上执行了
kill
命令。
在我执行该命令之后,我的Ansible Playbook立即恢复正常,并使用
ansible-playbook -vvv
选项报告结果:
" ==> Deleted (by you or by a script) since installation.",
" ==> Package distributor has shipped an updated version.",
" What would you like to do about it ? Your options are:",
" Y or I : install the package maintainer's version",
" N or O : keep your currently-installed version",
" D : show the differences between the versions",
" Z : start a shell to examine the situation",
" The default action is to keep your current version.",
"*** buildinfo.txt (Y/I/N/O/D/Z) [default=N] ? "
阅读了那些有用的诊断输出后,我立刻意识到需要一些适当的dpkg选项(例如,请参见这篇DevOps文章)。在我的情况下,我选择了:
apt:
name: '{{ item }}'
state: latest
update_cache: yes
dpkg_options: 'force-overwrite,force-confnew'
loop: '{{ my_packages }}'
此外,不要忘记使用类似于以下命令清理已终止的Ansible会话,否则您的安装可能仍然会失败:
sudo dpkg --configure -a