Ansible playbook 无法锁定 apt [英] Ansible playbook fails to lock apt
问题描述
我接手了一个在 Ansible 上运行的项目,用于服务器配置和管理.我对 Ansible 相当陌生,但多亏了良好的文档,我才开始了解它.我仍然有一个错误,它有以下输出:
I took over a project that is running on Ansible for server provisioning and management. I'm fairly new to Ansible but thanks to the good documentation I'm getting my head around it. Still I'm having an error which has the following output:
failed: [build] (item=[u'software-properties-common', u'python-pycurl', u'openssh-server', u'ufw', u'unattended-upgrades', u'vim', u'curl', u'git', u'ntp']) => {"failed": true, "item": ["software-properties-common", "python-pycurl", "openssh-server", "ufw", "unattended-upgrades", "vim", "curl", "git", "ntp"], "msg": "无法锁定 apt 进行排他操作"}
failed: [build] (item=[u'software-properties-common', u'python-pycurl', u'openssh-server', u'ufw', u'unattended-upgrades', u'vim', u'curl', u'git', u'ntp']) => {"failed": true, "item": ["software-properties-common", "python-pycurl", "openssh-server", "ufw", "unattended-upgrades", "vim", "curl", "git", "ntp"], "msg": "Failed to lock apt for exclusive operation"}
剧本是用 sudo: yes
运行的,所以我不明白为什么我会收到这个错误(看起来像一个权限错误).知道如何追踪这个吗?
The playbook is run with sudo: yes
so I don't understand why I'm getting this error (which looks like a permission error). Any idea how to trace this down?
- name: "Install very important packages"
apt: pkg={{ item }} update_cache=yes state=present
with_items:
- software-properties-common # for apt repository management
- python-pycurl # for apt repository management (Ansible support)
- openssh-server
- ufw
- unattended-upgrades
- vim
- curl
- git
- ntp
剧本:
- hosts: build.url.com
sudo: yes
roles:
- { role: postgresql, tags: postgresql }
- { role: ruby, tags: ruby }
- { role: build, tags: build }
推荐答案
这是配置 Ubuntu(可能还有其他一些发行版)时非常常见的情况.您尝试在后台运行自动更新时运行 Ansible(这是在设置新机器后立即发生的情况).由于 APT 使用信号量,Ansible 被踢出.
This is a very common situation when provisioning Ubuntu (and likely some other distributions). You try to run Ansible while automatic updates are running in background (which is what happens right after setting up a new machine). As APT uses semaphore, Ansible gets kicked out.
剧本没问题,最简单的验证方法是稍后运行(在自动更新过程完成后).
The playbook is ok and the easiest way to verify is to run it later (after automatic update process finishes).
对于永久解决方案,您可能需要:
For a permanent resolution, you might want to:
- 使用禁用自动更新的操作系统映像
- 在 Ansible playbook 中添加一个显式循环以重复失败的任务直到成功
这篇关于Ansible playbook 无法锁定 apt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!