在Ansible的inventory文件中,确保在主机组中的每台服务器上都存在ansible_ssh_user和ansible_ssh_pass属性,这些属性应该与服务器登录的用户名和SSH密码匹配。如果服务器使用SSH密钥进行身份验证,则需要指定ansible_ssh_private_key_file属性。 示例代码:
[servers]
server1 ansible_ssh_user=username ansible_ssh_pass=password ansible_ssh_private_key_file=/path/to/private/key
server2 ansible_ssh_user=username ansible_ssh_pass=password ansible_ssh_private_key_file=/path/to/private/key
在使用该方法时,请确保在服务器上不允许使用密码身份验证,否则会引起安全问题。建议使用SSH密钥进行身份验证,以提高服务器的安全性。