Provision ubuntu/xenial64 using Vagrant and Ansible - vagrant

I'm trying to create an ubuntu/xenial64 vm with Vagrant and provision it using Ansible. Installed versions of tools are:
Vagrant: 2.0.0
Ansible: 2.3.2.0
Python: 2.7.10
Virtualbox: 5.1.30
These are the contents of directory in which I am running vagrant up:
├── Vagrantfile
└── playbooks
├── inventory
├── main.yml
└── vars.yml
These are the contents of Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.ssh.insert_key = true
config.vm.provider "virtualbox" do |v|
v.name = "ubuntu"
v.memory = 1024
v.cpus = 2
end
config.vm.hostname = "ubuntu"
config.vm.network :private_network, ip: "192.168.33.7"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/main.yml"
ansible.sudo = true
ansible.verbose = true
ansible.inventory_path = "playbooks/inventory"
ansible.compatibility_mode = "2.0"
end
end
playbooks/main.yml:
---
- hosts: ubuntu
become: yes
vars_files:
- vars.yml
roles:
- geerlingguy.docker
playbooks/inventory:
[ubuntu]
192.168.33.7
[ubuntu:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
playbooks/vars.yml:
docker_edition: 'ce'
docker_package: "docker-{{ docker_edition }}"
docker_package_state: present
When I run vagrant up the output is:
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.0.40
default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/danilo/tutorials/ansible ubuntu
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=/Users/danilo/tutorials/ansible ubuntu/.vagrant/machines/default/virtualbox/private_key -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars=ansible_user\=\'ubuntu\' --limit="default" --inventory-file=playbooks/inventory --become -v playbooks/main.yml
No config file found; using defaults
ERROR! Specified --limit does not match any hosts
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
However, vagrant ssh works as expected. Any ideas what I may be missing?

Firstly, if you use hosts: ubuntu then you must define named machine:
config.vm.define "ubuntu" do |ubuntu|
ubuntu.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/main.yml"
ansible.sudo = true
ansible.verbose = true
ansible.inventory_path = "playbooks/inventory"
ansible.compatibility_mode = "2.0"
end
end
Otherwise change to hosts: default in the play.
But then...
I have no idea why you try to provision via 192.168.33.7 - it seems completely unnecessary for this use case - you can remove the ansible.inventory_path from Vagrantfile
in the same inventory file you specify user vagrant which is not configured on ubuntu/xenial64 box
ansible.sudo is also not necessary in the Vagrantfile
running Ansible this way on ubuntu/xenial64 way will likely fail for the lack of Python 2

Related

Vagrant GuestAdditions seems to be installed (5.1.20) correctly, but not running

I want to copy one entire folder present on my windows machine to a vm hosting ubuntu/trusty64.
But every time I try to bring my vagrant up i get below error message.
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> 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 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Configuring proxy for Apt...
==> default: Configuring proxy environment variables...
[default] GuestAdditions seems to be installed (5.1.20) correctly, but not running.
vboxadd: unrecognized service
vboxadd-service: unrecognized service
bash: line 4: setup: command not found
==> default: Checking for guest additions in VM...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
setup
Stdout from the command:
Stderr from the command:
bash: line 4: setup: command not found
Note:
Ubuntu version is up to date as you can see in the third line.
Vagrant version : Vagrant 1.9.3
Windows version : Windows 7 Enterprise Service Pack 1
Oracle VirtualBox version : Version 5.1.20 r114628 (Qt5.6.2)
On running the command vbguest status i get
$ vagrant vbguest --status
[default] GuestAdditions seems to be installed (5.1.20) correctly, but not running.
My vagrant file contents are
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
config.ssh.insert_key = false
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "xxxxx"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
#config.vm.synced_folder "../data", "/vagrant_data" , "/vagrant"
config.vm.synced_folder ".", "/mydata", :mount_options => ['dmode=775','fmode=664']
#config.vm.synced_folder "./", "/vagrant", id: "vagrant-root", type: "nfs"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "xxxxx"
config.proxy.https = "xxxxx"
config.proxy.ftp = "xxxxx"
config.apt_proxy.http = "xxxxx"
config.apt_proxy.https = "xxxxx"
config.proxy.no_proxy = "xxxxx"
end
if !Vagrant.has_plugin?("vagrant-proxyconf")
system('vagrant plugin install vagrant-proxyconf')
raise("vagrant-proxyconf installed. Run command again.");
end
end
Please suggest
1. How can i correct this error?
2. Share the complete folder from windows to vm?
Connect the Guest VM using WinSCP. Copy the VBoxGuestAddition.iso from the host machine. In my case, the VBoxGuestAddition present in C:\ProgramFiles\Oracle\VirtualBox.
Once iso file copied to Guest VM, login to GUest VM using putty.
mkdir /media/GuestAdditionsISO
Then execute the below command
mount -o loop /path/of/VBoxGuestAddition.iso /media/GuestAdditionsISO
Once mount command executed successfully,
cd /media/GuestAdditionsISO
sudo ./VBoxLinuxGuestAddition.run
Then re-start the VM. This works for me

Vagrant runs wrong provisioning file when booting multiple machines

I have the following vagrantfile, which specifies 2 machines - the frontend and the backend box.
Vagrant.configure(2) do |config|
config.vm.box = "frontend"
config.vm.network "private_network", ip: "192.168.0.5"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
config.vm.communicator = "winrm"
config.vm.provision "shell", path: "Provision.ps1"
config.vm.define "db" do |db|
db.vm.box = "backend"
db.vm.network "private_network", ip: "192.168.0.10"
db.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
db.vm.communicator = "winrm"
db.vm.provision "shell", path: "ProvisionRemote.ps1"
end
end
When I type vagrant up, according to the Multi-Machine documentation it should first boot the front end box and run Provision.ps1 and then boot the backend box and run ProvisionRemote.ps1 on it (outside in).
However, instead what happens is that the backend box boots first, and then it attempts to run Provision.ps1 (which is for the front end box) on it.
Bringing machine 'db' up with 'virtualbox' provider...
==> db: Importing base box 'backend'...
==> db: Matching MAC address for NAT networking...
==> db: Checking if box 'backend' is up to date...
==> db: Setting the name of the VM: RemoteBox_db_1459513634410_78500
==> db: Clearing any previously set network interfaces...
==> db: Preparing network interfaces based on configuration...
db: Adapter 1: nat
db: Adapter 2: hostonly
db: Adapter 3: hostonly
==> db: Forwarding ports...
db: 5985 => 55985 (adapter 1)
db: 5986 => 55986 (adapter 1)
==> db: Running 'pre-boot' VM customizations...
==> db: Booting VM...
==> db: Waiting for machine to boot. This may take a few minutes...
db: WinRM address: 127.0.0.1:55985
db: WinRM username: vagrant
db: WinRM transport: plaintext
==> db: Machine booted and ready!
==> db: Checking for guest additions in VM...
db: The guest additions on this VM do not match the installed version of
db: VirtualBox! In most cases this is fine, but in rare cases it can
db: prevent things such as shared folders from working properly. If you see
db: shared folder errors, please make sure the guest additions within the
db: virtual machine match the version of VirtualBox you have installed on
db: your host and reload your VM.
db:
db: Guest Additions Version: 4.3.28
db: VirtualBox Version: 5.0
==> db: Configuring and enabling network interfaces...
==> db: Mounting shared folders...
db: /vagrant => E:/_workingSource/project/env/
==> db: Running provisioner: shell...
db: Running: Provision.ps1 as c:\tmp\vagrant-shell.ps1
Why is it doing this? What am I doing wrong?
you should highlight that you have 2 machines
here you just define one machine (config and you did override some parameters as defined in the backend block but this is really the same machine definition) so vagrant is booting the one machine you define and tries to run all provisioner
The following works and defines 2 machines
Vagrant.configure(2) do |config|
config.vm.communicator = "winrm"
config.vm.define "front" do |front|
front.vm.box = "frontend"
front.vm.network "private_network", ip: "192.168.0.5"
front.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
front.vm.provision "shell", path: "Provision.ps1"
end
config.vm.define "db" do |db|
db.vm.box = "backend"
db.vm.network "private_network", ip: "192.168.0.10"
db.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
db.vm.provision "shell", path: "ProvisionRemote.ps1"
end
end
the config* parameter applys for the 2 machines (like config.vm.communicator) so all parameter that are common should be applied against the config. variable (note: I did not try to put the virtual box provider under config but it should work as long as it is the same) , and if you need machine specific parameter you must define within the specific block (like the IP defined as front.vm.network "private_network", ip: "192.168.0.5")
this approach fires provisioners in correct order ...
config.vm.provision "docker" do |d|
# installs docker
end
config.vm.provision :shell do |sh|
sh.privileged = false
sh.inline = $provision
end
config.vm.provision :shell do |sh|
sh.privileged = false
sh.path = "generateWebserverInstallEnvironment.sh"
end

Vagrantfile packaged in box (via packer) is not used

I used packer to create a vagrant box for a workshop I am running, and packaged vagrantfile in the box via the vagrantfile_template directive in the Vagrant post-processor as shown:
...
"post-processors": [{
"type": "vagrant",
"vagrantfile_template": "vagrantfile_templates/workshop",
"compression_level": "{{user `compression_level`}}",
"output": "fedora-22-x86_64.box"
}],
...
The contents of the resulting .box are:
% tar -tf workshop.box
Vagrantfile
box.ovf
metadata.json
packer-fedora-22-x86_64-disk1.vmdk
The contents of Vagrantfile in the box seem OK, and include the contents of the vagrantfile_template specified in the packer configuration. Note that this Vagrantfile defines two VMs named client and server:
% tar -O -xf freeipa-workshop.box Vagrantfile
# The contents below were provided by the Packer Vagrant post-processor
Vagrant.configure("2") do |config|
config.vm.base_mac = "0800278AF3E8"
end
# The contents below (if any) are custom contents provided by the
# Packer template during image build.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "workshop"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.define "server" do |server|
server.vm.network "private_network", ip: "192.168.33.10"
server.vm.hostname = "server.ipademo.local"
end
config.vm.define "client" do |client|
client.vm.network "private_network", ip: "192.168.33.20"
client.vm.hostname = "client.ipademo.local"
end
end
I added the box to vagrant with the name workshop:
% vagrant box add --name workshop workshop.box
==> box: Adding box 'workshop' (v0) for provider:
box: Downloading: file:///.../workshop.box
==> box: Successfully added box 'workshop' (v0) for 'virtualbox'!
% vagrant box list
workshop (virtualbox, 0)
Problem description
When I execute vagrant init workshop and then vagrant up, the Vagrantfile included in the box is not applied:
% vagrant init workshop
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "workshop"
... and so on (the rest of the default Vagrantfile)
% vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
...
Whoa! Why did it bring up default? According to the Vagrantfile docs the Vagrantfile packaged with the box should be used, and other Vagrantfiles including from the current directory should be merged into it. But this does not seem to be the case.
Vagrant 1.7.2 is the version in use.
I would like workshop participants to be able to bring up the VMs defined in the Vagrantfile included in the box, without supplying that Vagrantfile out of band (in order to minimise dependencies). Have I missed something important?
As all of us know, Vagrant loads and merges multiple Vagrantfiles in a pre-determined order outlined here (in the same section they also point out that multiple Vagrant.configure blocks are also OK).
I was experiencing the same very same issue when Vagrant would not pick up the config.vm.communicator = "winrm" configuration that was bundled in the .box using vagrantfile_template.
However, by Using vagrant --debug I noticed that Vagrant appeared to have cached the bundled Vagrantfile from a previous build of the same box:
INFO loader: Set :"26224240_win7sp1_x64_virtualbox" = ["#<Pathname:/home/thomas/.vagrant.d/boxes/win7sp1_x64/0/virtualbox/Vagrantfile>"]
One would think that vagrant destroy would remove the associated files in vagrant.d but it does not, so I was able to resolve the issue by manually removing ~/.vagrant.d/boxes/win7sp1_x64.
I confirmed that it now was working as intended by seeing that WinRM was indeed being used:
==> default: Waiting for machine to boot. This may take a few minutes...
default: WinRM address: 127.0.0.1:55985
default: WinRM username: vagrant
default: WinRM execution_time_limit: PT2H
default: WinRM transport: negotiate
==> default: Machine booted and ready!
Even though the Vagrantfile in the initialized directory did not have that configuration:
Vagrant.configure("2") do |config|
config.vm.box = "win7sp1_x64"
config.vm.box_url = "/media/data/VagrantBaseBoxes/win7sp1_x64/win7sp1_x64-virtualbox.box"
end
TL;DR:
Make sure no "old" Vagrantfiles are present in vagrant.d that may overwrite what's configured in the 'packer-ed box (see "load order and merging" in the link above).

Failing to create SMB shared folder using Vagrant on Windows host with linux guest

I'm using Vagrant to create an Ubuntu 14.04 guest on my Windows 7 SP 1 PC. This has been working ok, but the performance of the guest is poor when accessing files that have been synchronized from the host. After doing some reading, I'm trying to make the synchronized folder an SMB share, however this is failing when I run 'vagrant up'
Note that I've upgraded to powershell 3.0, as documented in https://docs.vagrantup.com/v2/synced-folders/smb.html. I've also ensured that my guest has cifs-util installed as pointed out in https://github.com/mitchellh/vagrant/issues/4642. I'm using Vagrant 1.7.4 and VirtualBox 4.3.28
My Vagrantfile looks like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "npt"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", "90"]
v.customize ["modifyvm", :id, "--memory", "4096"]
v.customize ["modifyvm", :id, "--cpus", 2]
end
config.vm.synced_folder "\\", "/npt_root", type: "smb"
config.vm.provision :shell do |shell|
shell.inline = "puppet module install puppetlabs/vcsrepo --force"
end
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet"
puppet.manifest_file = "basic_build_reqs.pp"
end
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
end
And the output I am seeing is:
Z:\npt\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'npt'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1442502969737_66801
==> default: Preparing SMB shared folders...
default: You will be asked for the username and password to use for the SMB
default: folders shortly. Please use the proper username/password of your
default: Windows account.
default:
default: Username: tdj#DCL
default: Password (will be hidden):
Exporting an SMB share failed! Details about the failure are shown
below. Please inspect the error message and correct any problems.
Host path: Z:/
Stderr: System error 123 has occurred.
The filename, directory name, or volume label syntax is incorrect.
Error:
Stdout:
It looks like Vagrant has interpreted the relative path "\" I've given it and is coming up with "Z:/", with unix style slashes, which Windows is then failing to parse.
Note that I've tried replacing the relative path with the absolute path "Z:\", but I still see the same output on the "Host path" line
I suspect "\\" is the problem in the following line:
config.vm.synced_folder "\\", "/npt_root", type: "smb"
Could you try to put in a concrete foldername that you would like to share with your VM and test if it works?

Vagrant Ansible provisioning SSH error

I'm trying to do some Vagrant/Ansible stuff, but running into problems from the start. Here's 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 is simply
---
- name: Bring up server with MySQL, Nginx, and PHP-FPM
hosts: all
remote_user: root
roles:
- common
and common/tasks/main.yml is
---
- name: Update apt
apt: update_cache=yes
When doing vagrant up, the output is
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 there to be the same as set in the private_network? I've been staring at this for over an hour, did I do something wrong? I have a feeling the IP isn't being set properly or something. I can ping 192.168.6.66.
The problem here that your site.yml overrides the remote user ansible will use to root. But, you do not provide the private key for it, nor password.
So the way, I fixed it was to set ansible_ssh_user to "vagrant", because it is default known user, and ansible will behave the same as vagrant ssh if remote_user is not overriden. And set sudo true, because "vagrant" 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 "WHY DOES THE ANSIBLE PROVISIONER CONNECT AS THE WRONG USER?" section Ansible Provisioning of Vagrant Documentation
Vagrant will create it's own ansible inventory file (which you've seen) with the defaults of 127.0.0.1 and 2200.
You need to specify the ansible inventory file using ansible.inventory_path
A very simple inventory file for use with Vagrant might look like:
default ansible_ssh_host=192.168.111.222 Where 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
I had Ansible on Vagrant 1.7 trying to connect as root, probably because of some separate deployment repo group vars defaults. Possible fixes:
set ansible.force_remote_user = true or ansible_ssh_user extra/host/group vars appropriately
or move to Vagrant 1.8, which forces remote user by default, as per the changelog
I was having a similar problem, where it wouldn't ssh into the server for whatever reason for provisioning.
vagrant ssh worked fine, but vagrant provision would fail to ssh, due to a timeout.
I finally connected the dots and realized that this was actually because of the VPN client that my employer has us use. Cisco AnyConnect VPN client does some kind of buggery and makes it so that I have to restart my entire workstation to be able to run it.
Luckily, I don't have to be connected to a VPN for many things, so this only happens sporadically for me.

Resources