我可以访问具有有限sudo权限的非特权用户的CentOS框,即/etc/sudoers
dummy ALL=(root) NOPASSWD: /usr/bin/yum, /bin/rpm
使用yum部署playbook安装软件中的几个角色,任务的摘录可能如下:
---
- name: failing example
hosts: servers
remote_user: dummy
tasks:
- name: Install prerequisite packages
yum:
pkg: git
state: present
become: true
运行此任务会导致以下故障:
TASK [Install prerequisite packages] ****************************************
fatal: [xxx.xxx]: FAILED! => {"changed": false, "module_stderr": "Shared connection to xxx.xxx closed.\r\n", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE", "rc": 1}
在远程主机上运行sudo yum install git
,因为用户虚拟就像魅力一样。知道如何解决这个问题吗?我想ansible可能不会直接调用系统程序,因此sudoer配置不适用。