Ansible:如何解决 "sudo: a password is required" 错误?
Ansible: how to solve "sudo: a password is required" error?
我有 9 台服务器,我正在尝试使用 ansible 安装软件包,我能够使用密码通过 ssh 进入其中 5 台服务器,而其他 4 台在通过 ssh'ng 进入它们时不询问任何密码。
但是我已经将 id_rsa.pub 密钥复制到所有 9 个服务器。
现在 ansible 脚本在 5 个服务器上工作正常,但剩下的 4 个服务器我收到以下错误消息。
fatal: [xxx0?]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Connection to xxx0? closed.\r\n", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE", "rc": 1}
我的Ansible.cfg
[defaults]
filter_plugins =./filter_plugins
roles_path = ./roles
sudo_user = root
host_key_checking = False
retry_files_enabled = False
password = ~/password.txt
timeout = 25
[ssh_connection]
ssh_args = -F ~/.ssh/config -o ControlMaster=no -o ControlPersist=30m
control_path = ~/.ssh/ansible-%%r@%%h:%%p
~/.ssh/config
Host xx0? xx0? xx0? xx0? xx0? xx0? xx0? xx0? xx0? .xyz.com
User yyy
Port 22
ansible 版本 = ansible 2.3.1.0
我该如何解决这个错误?
你得到一个错误:
sudo: a password is required
这并不意味着您无法连接到目标机器,这意味着您需要为 运行 具有提升权限的命令提供密码(或者您不能 运行一个完全提升权限的命令)。
反之,表示连接建立没有问题。
修复受影响机器上的 sudoers
配置。
主要问题是 ansible 任务需要 4 个服务器的密码,所以我导出询问 sudo 密码并且成功了。
由于密码原因,它失败了。
export ANSIBLE_ASK_SUDO_PASS=true
我有 9 台服务器,我正在尝试使用 ansible 安装软件包,我能够使用密码通过 ssh 进入其中 5 台服务器,而其他 4 台在通过 ssh'ng 进入它们时不询问任何密码。
但是我已经将 id_rsa.pub 密钥复制到所有 9 个服务器。
现在 ansible 脚本在 5 个服务器上工作正常,但剩下的 4 个服务器我收到以下错误消息。
fatal: [xxx0?]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Connection to xxx0? closed.\r\n", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE", "rc": 1}
我的Ansible.cfg
[defaults]
filter_plugins =./filter_plugins
roles_path = ./roles
sudo_user = root
host_key_checking = False
retry_files_enabled = False
password = ~/password.txt
timeout = 25
[ssh_connection]
ssh_args = -F ~/.ssh/config -o ControlMaster=no -o ControlPersist=30m
control_path = ~/.ssh/ansible-%%r@%%h:%%p
~/.ssh/config
Host xx0? xx0? xx0? xx0? xx0? xx0? xx0? xx0? xx0? .xyz.com
User yyy
Port 22
ansible 版本 = ansible 2.3.1.0
我该如何解决这个错误?
你得到一个错误:
sudo: a password is required
这并不意味着您无法连接到目标机器,这意味着您需要为 运行 具有提升权限的命令提供密码(或者您不能 运行一个完全提升权限的命令)。
反之,表示连接建立没有问题。
修复受影响机器上的 sudoers
配置。
主要问题是 ansible 任务需要 4 个服务器的密码,所以我导出询问 sudo 密码并且成功了。 由于密码原因,它失败了。
export ANSIBLE_ASK_SUDO_PASS=true