linux - Ansible:没有密码的sudo

标签 linux ansible sudo

我想在没有 sudo 密码的情况下使用用户 sa1 运行 ansible:

第一次成功:

[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
}

请帮忙!

最佳答案

这是不可靠的,这是您服务器的配置。确保 ansible 用户在没有密码的情况下允许使用 sudo。

  1. 为此登录服务器
  2. 使用 sudo visudo 打开 sudoers 文件
  3. 确保你有这样一行:centos ALL=(ALL) NOPASSWD:ALL
  4. centos 替换为您的用户
  5. 保存文件

您可以通过运行从服务器本身尝试:

sudo -u [yourusername] sudo echo "success"

如果这可行,它也应该适用于 ansible。

关于linux - Ansible:没有密码的sudo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37434598/

相关文章:

continuous-integration - ansible inventory文件位置是/etc/ansible/hosts还是/etc/hosts?

python - 使用 Ansible 启用 Apache 站点

bash - sudo'd mysqldump over ssh 语法?

bash - 如何通过 sudo 命令使用 for 循环运行脚本

php - 如何在没有密码的情况下从 php 脚本运行 sudo su?

linux - 如何在 upstart 中正确启动 Node 服务器,以便 apn 正常工作

java - 通过代码编辑Linux网络配置文件("/etc/network/interfaces")

mysql - 如何使用 Ansible 和 Vagrant 安装 MySQL 5.7?

linux - 获取在 Linux 系统上使用的正确以太网接口(interface)

linux - 从 SSH-Shell 启动 Gnome-Application