背景
目标机器是 ubuntu 26.04,ansible 脚本使用了 become 来提权操作
但是总是报错 Timeout (12s) waiting for privilege escalation prompt
原因
ubuntu 新版换用了 sudo-rs 导致旧版 ansible 不兼容
可参见 Ubuntu 26.04 默认 sudo-rs 的 sudoers 配置变更
解决方案
1. 升级 ansible
新版本 ansible 已经做了兼容
根据 validate sudo become plugin against sudo-rs · Issue #85837 · ansible/ansible
ansible-core 新版本已经修复了这个情况,并且最低反向移植到了 2.16
- 最新:似乎 Revert “sudo become plugin: add sudo-rs prompt support (#86175) (#869… · ansible/ansible@ccaba46 回滚了
根据 Releases and maintenance — Ansible Community Documentation 中的映射
也就是最低 ansible 9 就可以,如果不行,请重新安装一次,确保使用了更新的 ansible-core
最新:ansible 官方已经回滚了所有相关的改动,将问题提交到了上游 -p/–prompt behaviour breaks ansible · Issue #1461 · trifectatechfoundation/sudo-rs
看来他们认为是上游的问题,等待上游修复吧
2. 临时处理继续使用老旧 sudo
以下三种方案选一种
环境变量
export ANSIBLE_BECOME_EXE=sudo.ws兼容处理
1 2 3 4 5 6 7- name: Become to show id ansible.builtin.command: cmd: whoami become: true become_exe: "{{ 'sudo.ws' if ansible_facts.packages['sudo-rs'] is defined else 'sudo' }}" changed_when: false register: whoami_resultansible.cfg 处理,在 ansible.cfg 中添加
1 2[privilege_escalation] become_exe = sudo.ws