Vagrant Ansible Provision SSH Error

I'm trying to make some tramp / Ansible, but ran into problems from the start. Here is my Vagrantfile:

# -*- 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 just

 --- - name: Bring up server with MySQL, Nginx, and PHP-FPM hosts: all remote_user: root roles: - common 

and common / tasks / main.yml

 --- - name: Update apt apt: update_cache=yes 

When doing vagrant up output

 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. 

If I look at .vagrant / provisioners / ansible / inventory / vagrant_ansible_inventory, I see the following:

 default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 

I would expect the IP address to be the same as in private_network? I looked at it for more than an hour, did I do something wrong? I have a feeling that IP is not setting properly or something like that. I can ping 192.168.6.66 .

+5
source share
4 answers

The problem that your site.yml is canceling the remote user may be using root. But you do not provide him with the private key and password.

Thus, I fixed that you need to set ansible_ssh_user to "vagrant", because by default it is a known user, and ansible will behave the same as vagrant ssh if remote_user is not redefined. And set sudo true because the roaming user is sudoer but not su.

 # -*- 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 

Please refer to the section "WHY A RESPONSIBLE PROVISOR IS CONNECTED AS AN INCORRECT USER?" section Illegal preparation of stray documentation

+4
source

Vagrant will create its own inventory file (which you saw) with default values ​​127.0.0.1 and 2200.

You need to specify an indispensable inventory file using ansible.inventory_path

A very simple inventory file for use with Vagrant might look like this:

default ansible_ssh_host = 192.168.111.222 If the above IP address is one set in your Vagrantfile:

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

From https://docs.vagrantup.com/v2/provisioning/ansible.html

0
source

I had Ansible on Vagrant 1.7 trying to connect as root , possibly due to some separate default repo group vars options. Possible fixes:

0
source

I had a similar problem where it would not be ssh on the server for some reason to provide.

vagrant ssh worked fine, but vagrant provision unable to generate ssh due to timeout.

I finally connected the dots and realized that this is actually due to the VPN client that my employer is using. The Cisco AnyConnect VPN client performs some kind of buggery function and makes it so that I need to reboot the entire workstation in order to be able to start it.

Fortunately, I do not need to connect to the VPN for many things, so this only happens occasionally for me.

0
source

Source: https://habr.com/ru/post/1204278/


All Articles