修复Packer Provisions Shell Could not get lock /var/lib/dpkg/lock-frontend - open
修复Packer Provisions Shell Could not get lock /var/lib/dpkg/lock-frontend - open问题
问题背景
在使用packer打包镜像的时候, 需要安装ansible, 而安装ansible之前, 主要
apt update
燃鹅, packer报错说
amazon-ebs: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
amazon-ebs: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
解决方案
Provision 加一步, 先 sleep 5分钟, 等系统开机时候的安全检查结束了, 便可成功
"provisioners": [
{
"type": "shell",
"inline": [
"sleep 300",
"sudo apt-get install -y ansible"
]
},
如果不确定需要多久, 可以用另外的方法, 可以缩减时间.
{
"type": "shell",
"inline": [
"while sudo lsof /var/lib/dpkg/lock-frontend ; do sleep 10; done;",
"sudo apt-get install -y ansible"
]
},
参考链接
https://joelvasallo.com/?p=544 https://github.com/geerlingguy/packer-boxes/issues/7#issuecomment-358931370