Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible配置错误!不可能使用SSH密码而不是密钥_Ssh_Vagrant_Ansible_Ansible Inventory - Fatal编程技术网

Ansible配置错误!不可能使用SSH密码而不是密钥

Ansible配置错误!不可能使用SSH密码而不是密钥,ssh,vagrant,ansible,ansible-inventory,Ssh,Vagrant,Ansible,Ansible Inventory,我想使用Ansible提供上一个节点中的三个节点 我的主机是Windows10 我的文件看起来像: Vagrant.configure(“2”)do | config| (1..3).每个do |索引| config.vm.define“node#{index}”do | node| node.vm.box=“ubuntu” node.vm.box=“../box/ubuntu_base.box” node.vm.network:专用_网络,ip:“192.168.10.#{10+索引}” 如果

我想使用Ansible提供上一个节点中的三个节点

我的主机是Windows10

我的文件看起来像:

Vagrant.configure(“2”)do | config|
(1..3).每个do |索引|
config.vm.define“node#{index}”do | node|
node.vm.box=“ubuntu”
node.vm.box=“../box/ubuntu_base.box”
node.vm.network:专用_网络,ip:“192.168.10.#{10+索引}”
如果索引=3
node.vm.provision:设置,类型::ansible|u local do | ansible|
ansible.playbook=“playbook.yml”
ansible.provisioning_path=“/vagrant/ansible”
ansible.inventory_path=“/vagrant/ansible/hosts”
ansible.limit=:全部
ansible.install_mode=:pip
ansible.version=“2.0”
结束
结束
结束
结束
结束
我的剧本看起来像:

---
#我的小剧本
-名字:我的小剧本
主机:Web服务器
收集事实:错误
角色:
-创建用户
我的主机文件如下所示:

[webserver]
192.168.10.11
192.168.10.12
[数据库服务器]
192.168.10.11
192.168.10.13
[全部:vars]
ansible_连接=ssh
ansible_ssh_user=流浪汉
ansible_ssh_pass=流浪汉
执行
vagrant up--provision
后,我得到以下错误:

Bringing machine 'node1' up with 'virtualbox' provider...
Bringing machine 'node2' up with 'virtualbox' provider...
Bringing machine 'node3' up with 'virtualbox' provider...
==> node3: Running provisioner: setup (ansible_local)...
    node3: Running ansible-playbook...

PLAY [My little playbook] ******************************************************

TASK [create_user : Create group] **********************************************
fatal: [192.168.10.11]: FAILED! => {"failed": true, "msg": "ERROR! Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}
fatal: [192.168.10.12]: FAILED! => {"failed": true, "msg": "ERROR! Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}

PLAY RECAP *********************************************************************
192.168.10.11              : ok=0    changed=0    unreachable=0    failed=1
192.168.10.12              : ok=0    changed=0    unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
我用
ansible.limit=:all
扩展了我的Vagrantfile,并将
[all:vars]
添加到主机文件中,但仍然无法通过错误

有人遇到过同样的问题吗?

这就是答案

我刚刚在负责资源调配的计算机上扩展了已知的_hosts文件,如下所示:

我修改过的文件中的代码段:

。。。
如果索引=3
node.vm.provision:pre,类型::shell,路径:“install.sh”
node.vm.provision:设置,类型::ansible|u local do | ansible|
...
My install.sh看起来像:

#将web/数据库主机添加到已知主机(IP在文件中定义)
ssh keyscan-H 192.168.10.11>/home/vagrant/.ssh/known_hosts
ssh keyscan-H 192.168.10.12>/home/vagrant/.ssh/known_hosts
ssh keyscan-H 192.168.10.13>/home/vagrant/.ssh/known_hosts
chown vagrant:vagrant/home/vagrant/.ssh/known_hosts
#重新加载ssh以加载已知主机
/etc/init.d/ssh重载

在项目目录中创建一个包含以下内容的文件
ansible/ansible.cfg
(即目标上
设置路径中的
ansible.cfg
):

[defaults]
host_key_checking = false


假设您的Vagrant box已经安装了
sshpass
,这是不清楚的,因为您问题中的错误消息表明它已安装(否则将是“错误!若要使用带有密码的“ssh”连接类型,您必须安装sshpass程序”),但您需要明确添加它(
sudo-apt-get-install-sshpass
),好像它不是

我使用的是Ansible 2.6.2版,而带有
host\u key\u checking=false的解决方案不起作用


添加环境变量
export-ANSIBLE\u HOST\u KEY\u CHECKING=False
跳过指纹检查。

此错误也可以通过简单地导出
ANSIBLE\u HOST\u KEY\u CHECKING
变量来解决

export ANSIBLE_HOST_KEY_CHECKING=False

来源:

Ubuntu 20.04上使用Ansible 2.9.6时,我遇到了类似的挑战

当我运行命令时:

ansible all -m ping -i inventory.txt
我得到一个错误:

目标|失败!=>{ “msg”:“不可能使用SSH密码而不是密钥,因为已启用主机密钥检查,并且sshpass不支持此操作。请将此主机的指纹添加到已知的\u hosts文件中以管理此主机。” }

以下是我如何修复它的方法

安装ansible时,它会创建一个名为
ansible.cfg
的文件,可以在
/etc/ansible
目录中找到该文件。只需打开该文件:

sudo nano /etc/ansible/ansible.cfg
取消对此行的注释以禁用SSH密钥主机检查

host_key_checking = False
现在保存文件,您现在应该没事了

注意:您还可以尝试将主机的指纹从您的计算机下载到服务器,将主机的指纹添加到您的
已知\u主机
文件中,这会提示您将主机的指纹保存到您的
已知\u主机
文件中:

promisepreston@ubuntu:~$ ssh myusername@192.168.43.240

The authenticity of host '192.168.43.240 (192.168.43.240)' can't be established.
ECDSA key fingerprint is SHA256:9Zib8lwSOHjA9khFkeEPk9MjOE67YN7qPC4mm/nuZNU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.43.240' (ECDSA) to the list of known hosts.

myusername@192.168.43.240's password: 
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-53-generic x86_64)
就这些


我希望这有助于运行下面的命令,它解决了我的问题


导出ANSIBLE\u HOST\u KEY\u CHECKING=False&&ANSIBLE playbook-i

shellscripting解决方案。ANSIBLE确保了一个更好的方法!要清楚,这都是流浪汉方面的问题,虽然不方便,但从安全角度来看,这实际上是正确的方法,其他方法实际上是解决方案。对于本地开发我的目的完全是为了更简单的禁用检查,我并不想遇到繁琐或迂腐的问题,只是觉得澄清一下对新事物了解的用户对安全的影响可能会更好。我只是担心称之为更好的方式可能会误导一些人。:)我不确定现在是否值得一个新的答案,但我刚刚注意到,在Ansible和Vagrant的官方文档中,他们推荐了Vagrant配置行
config.ssh.insert_key=false
。可能比ENV vars或.cfg操作更简单。@JasmineHegman,谢谢你的更新!我同意Vagrant配置比ENV var或.cfg更方便、更安全。这很奇怪,因为《Ok》中仍然引用了
host\u key\u checking
,关于这一点有一个公开的问题:它可能会让一些人感到困惑,因此,请将您的ansible.cfg放在与您的发明相同的文件夹中,然后运行它。多亏了@techraf,这一点得以实现。
ansible.cfg
文件位置是
/etc/ansible/ansible.cfg