sup*_*ize 5 ansible ansible-2.x
我接管了一个在Ansible上运行的项目,用于服务器配置和管理.我对Ansible相当新,但是由于良好的文档,我正在理解它.我仍然有一个错误,其输出如下:
失败:[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'])=> {"失败":true,"item":["software-properties-common","python-pycurl","openssh-server"," ufw","无人值守 - 升级","vim","curl","git","ntp"],"msg":"无法锁定apt以进行独占操作"}
该剧本运行sudo: yes
所以我不明白为什么我收到此错误(看起来像一个权限错误).知道怎么追查这个吗?
- 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
Run Code Online (Sandbox Code Playgroud)
剧本:
- hosts: build.url.com
sudo: yes
roles:
- { role: postgresql, tags: postgresql }
- { role: ruby, tags: ruby }
- { role: build, tags: build }
Run Code Online (Sandbox Code Playgroud)
Dan*_*l F 13
我刚刚在新虚拟机上遇到了同样的问题。我尝试了很多方法,包括重试apt
命令,但最终唯一的方法是删除无人值守的升级。
我在raw
这里使用命令,因为此时 VM 没有安装 Python,所以我需要先安装它,但我需要一个可靠 apt
的。
由于它是一个虚拟机,我正在通过将其重置为快照来测试剧本,系统日期已关闭,这迫使我使用该date -s
命令,以便在apt
命令期间不会出现 SSL 证书问题。这date -s
触发了无人值守升级。
所以这个剧本片段基本上是与在新系统中禁用无人值守升级相关的部分。它们是我在新系统上发出的第一个命令。
- name: Disable timers for unattended upgrade, so that none will be triggered by the `date -s` call.
raw: systemctl disable --now {{item}}
with_items:
- 'apt-daily.timer'
- 'apt-daily-upgrade.timer'
- name: Reload systemctl daemon to apply the new changes
raw: systemctl daemon-reload
# Syncing time is only relevant for testing, because of the VM's outdated date.
#- name: Sync time
# raw: date -s "{{ lookup('pipe', 'date') }}"
- name: Wait for any possibly running unattended upgrade to finish
raw: systemd-run --property="After=apt-daily.service apt-daily-upgrade.service" --wait /bin/true
- name: Purge unattended upgrades
raw: apt-get -y purge unattended-upgrades
- name: Update apt cache
raw: apt-get -y update
- name: If needed, install Python
raw: test -e /usr/bin/python || apt-get -y install python
Run Code Online (Sandbox Code Playgroud)
apt
由于无人值守升级导致的锁定问题,其他任何事情都会导致命令随机失败。
在配置Ubuntu(以及可能的其他一些发行版)时,这是一种非常常见的情况.您尝试在后台运行自动更新时运行Ansible(这是在设置新计算机后立即执行的操作).由于APT使用信号量,Ansible被踢出局.
该剧本没问题,最简单的验证方法是稍后运行(自动更新过程完成后).
对于永久性解决方案,您可能希望: