Ansible:无需密码的 sudo [英] Ansible: sudo without password
本文介绍了Ansible:无需密码的 sudo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在没有 sudo 密码的情况下使用用户 sa1 运行 ansible:
I want to run ansible with user sa1 without sudo password:
第一次还好:
[root@centos1 cp]# ansible cent2 -m shell -a "sudo yum -y install httpd"
cent2 | SUCCESS | rc=0 >>
第二次失败:
[root@centos1 cp]# ansible cent2 -s -m yum -a "name=httpd state=absent"
cent2 | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "",
"module_stdout": "sudo: a password is required\r\n",
"msg": "MODULE FAILURE",
"parsed": false
}
请帮忙!
推荐答案
这与您的服务器配置无关.确保 sudo 允许 ansible 在没有密码的情况下使用.
It's not ansible it's your server's configuration. Make sure that sudo is allowed for the user ansible is using without password.
- 为此登录到服务器
- 使用
sudo visudo
打开 sudoers 文件 - 确保你有这样一行:
centos ALL=(ALL) NOPASSWD:ALL
- 将
centos
替换为您的用户 - 保存文件
您可以通过运行以下命令从服务器本身尝试:
You can try from the server itself by running:
sudo -u [yourusername] sudo echo "success"
如果这行得通,它也应该从 ansible 工作.
If this works it should work from ansible too.
这篇关于Ansible:无需密码的 sudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文