首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vagrant Ansible provisioning SSH错误

Vagrant Ansible provisioning SSH错误
EN

Stack Overflow用户
提问于 2014-10-09 02:51:57
回答 4查看 9.6K关注 0票数 7

我正在尝试做一些Vagrant/Ansible的事情,但从一开始就遇到了问题。这是我的Vagrantfile:

代码语言:javascript
复制
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.network "private_network", ip: "192.168.6.66"

  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "site.yml"
  end
end

site.yml只是简单地

代码语言:javascript
复制
---
- name: Bring up server with MySQL, Nginx, and PHP-FPM
  hosts: all
  remote_user: root

  roles:
    - common

而common/task/main.yml是

代码语言:javascript
复制
---
- name: Update apt
  apt: update_cache=yes

在执行vagrant up时,输出为

代码语言:javascript
复制
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: ansible-provision_default_1412793587231_72507
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Checking for host entries
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/bram/Projects/Brammm/ansible-provision
==> default: Running provisioner: ansible...

PLAY [Bring up server with MySQL, Nginx, and PHP-FPM] ************************* 

GATHERING FACTS *************************************************************** 
fatal: [default] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue

TASK: [common | Update apt] *************************************************** 
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/bram/site.retry

default                    : ok=0    changed=0    unreachable=1    failed=0   

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

如果我查看.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory,,我会看到以下内容:

代码语言:javascript
复制
default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200

我希望那里的IP与private_network中设置的IP相同?我已经盯着这个看了一个多小时了,我是不是做错了什么?我有一种感觉,IP设置得不是很好。我可以ping 192.168.6.66

EN

回答 4

Stack Overflow用户

发布于 2015-06-12 06:08:44

这里的问题是,您的site.yml覆盖了ansible将用于root的远程用户。但是,您没有提供它的私钥,也没有提供密码。

因此,我修复的方法是将ansible_ssh_user设置为"vagrant",因为它是默认的已知用户,如果remote_user没有被覆盖,ansible的行为将与vagrant ssh相同。并将sudo设置为true,因为"vagrant“用户是sudoer,而不是su。

代码语言:javascript
复制
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.network "private_network", ip: "192.168.6.66"

  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "site.yml"
    ansible.extra_vars = { ansible_ssh_user: 'vagrant' }
    ansible.sudo = true
    #ansible.verbose = 'vvvv'
  end
end

请参考“为什么ANSIBLE PROVISIONER以错误的用户身份连接?”第Ansible Provisioning of Vagrant Documentation

票数 5
EN

Stack Overflow用户

发布于 2014-10-09 03:25:24

Vagrant将创建自己的ansible清单文件(如您所见),缺省值为127.0.0.1和2200。

您需要使用ansible.inventory_path指定ansible清单文件

与Vagrant配合使用的一个非常简单的清单文件可能如下所示:

默认ansible_ssh_host=192.168.111.222,其中上述IP地址是在Vagrantfile中设置的地址:

config.vm.network :private_network,ip:"192.168.111.222“

来自https://docs.vagrantup.com/v2/provisioning/ansible.html

票数 0
EN

Stack Overflow用户

发布于 2016-02-08 17:34:43

我让Ansible在Vagrant1.7上尝试以root身份连接,可能是因为一些单独的部署repo group vars默认值。可能的修复方法:

根据changelog,默认情况下,

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26264288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档