我正在尝试让 Ansible 和 Vagrant 正常工作。在一个文件夹(称为 Vagrant)中,我有一个 Vagrantfile、一个主机文件和一个ansible.cfg
包含以下内容的文件:
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# General Vagrant VM configuration.
config.vm.box = "geerlingguy/centos7"
config.ssh.insert_key = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider :virtualbox do |v|
v.memory = 256
v.linked_clone = true
end
# Server 1.
config.vm.define "server1" do |app|
app.vm.hostname = "server1.dev"
app.vm.network :private_network, ip: "192.168.0.10"
end
end
主机文件
[server1]
192.168.0.10
并ansible.cfg
归档
[defaults]
inventory = hosts
remote_user = vagrant
host_key_checking = False
ansible_ssh_private_key_file=<absolute_path_to_folder>/.vagrant/machines/server1/virtualbox/private_key
ansible_ssh_user=vagrant
当我运行以下命令时,它不起作用:
macbook-pro:Vagrant user1$ ansible server1 -m command -a uptime
192.168.0.10 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
文件夹中似乎没有私钥.vagrant/machines/server1/virtualbox
文件。
当我将ansible.cfg
文件更改为
[defaults]
inventory = hosts
remote_user = vagrant
host_key_checking = False
private_key_file = /Users/wauterw/.vagrant.d/insecure_private_key
有用。
如何使用/创建私钥.vagrant/machines/server1/virtualbox/private_key
而不是通用的insecure_private_key
?