Ansible:没有密码的sudo [英] Ansible: sudo without password

查看:469
本文介绍了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.

  1. 要登录到服务器
  2. 使用sudo visudo
  3. 打开sudoers文件
  4. 确保您有这样的一行:centos ALL=(ALL) NOPASSWD:ALL
  5. 用您的用户替换centos
  6. 保存文件
  1. To do that login to the server
  2. Open the sudoers file with sudo visudo
  3. Make sure you have a line something like this: centos ALL=(ALL) NOPASSWD:ALL
  4. Replace centos with the your user
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆