gpt4 book ai didi

ubuntu - Ansible apt 任务 : Failed to Lock apt for Exclusive Operation

转载 作者:行者123 更新时间:2023-12-04 17:49:38 29 4
gpt4 key购买 nike

我编写了一个 Ansible 剧本,其中包括运行 apt-get dist-upgrade。我确保在剧本的顶部有 become: truebecome_user: root 以获得运行升级的 sudo 访问权限。这在我的 Vagrant VM 上本地运行良好,但在我们的生产系统 (Ubuntu 16.04) 上运行时,我们收到以下错误:

无法锁定 apt 进行独占操作

我们目前的解决方法是通过 SSH 连接到机器,然后手动运行 sudo apt-get dist-upgrade。然后退出 SSH session 并再次运行 ansible playbook,它就可以工作了。

我们剧本中的其他任务需要 sudo 访问权限并且工作正常。只是 apt 命令失败了。我们已尝试重新启动机器并将 become: truebecome_user: root 替换为 sudo: yes 无济于事。

关于如何解决这个问题有什么想法吗?我将在下面包含我们剧本的相关部分。

- become: true
become_user: root
name: Setup the mongo database servers
hosts: sgmongo-{{ customer }}-ciadmin
tasks:
-
name: Ensure OS is upgraded with all patches
apt: upgrade=dist update_cache=yes

最佳答案

我通过像这样使用 Ansible 调用 shell 脚本来做到这一点:

- script: ./files/bash_scripts/monitor_automatic_updates_status.sh

Ansible 调用的相关脚本在这里:

#!/bin/bash  
#Debian automatically checks for updates on first boot. This ensures that has completed before continuing.
#If it hasn't finished in 10 minutes, the script will exit ungracefully.
timeout=$(($(date +%s) + 600))

while pgrep apt > /dev/null; do

time=$(date +%s)

if [[ $time -ge $timeout ]];
then
exit 1
fi

sleep 1
done;
exit 0

它只是不断地检查 apt 是否在系统上运行。并且,当它最终完成运行时,允许 Ansible 继续。

关于ubuntu - Ansible apt 任务 : Failed to Lock apt for Exclusive Operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46098634/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com