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的用户使用并且无需密码即可使用.
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
- 保存文件
- To do that login to the server
- Open the sudoers file with
sudo visudo
- Make sure you have a line something like this:
centos ALL=(ALL) NOPASSWD:ALL
- Replace
centos
with the your user - Save the file
您可以通过运行以下命令从服务器本身进行尝试:
You can try from the server itself by running:
sudo -u [yourusername] sudo echo "success"
如果这行得通,那么它也应该可以正常运行.
If this works it should work from ansible too.
这篇关于Ansible:没有密码的sudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文