问题Vagrantfile
:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "kurseve"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.ssh.insert_key = false
config.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "tasks/main.yml"
end
end
我试图打电话给tasks/main.yml
ansible-playbook,如下所示:
---
- hosts: kurseve
tasks:
- name: update apt cache
apt: update_cache=True
- name: Installing developer tools
apt: pkg={{ item }} state=latest
with_items:
- build-essential
- cmake
- git
- pkg-config # used to configure our build
- wget
- name: Installing Image I/O packages required by Open-CV
apt: pkg={{ item }} state=latest
with_items:
- libjpeg8-dev
- libtiff5-dev
但当我做$ vagrant up
时,我得到以下追溯
$ vagrant up --provision
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: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> default: have version '20170213.0.0'. The latest is version '20170222.0.0'. Run
==> default: `vagrant box update` to update.
==> default: Setting the name of the VM: kurseve-playbook_default_1488118172711_3988
==> 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: Forwarding ports...
default: 22 (guest) => 2200 (host) (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: Machine booted and ready!
==> 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: 4.3.36
default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Mounting shared folders...
default: /vagrant => /Users/user/development/projects/kurseve-playbook
==> 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 ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit="default" --inventory-file=/Users/user/development/projects/kurseve-playbook/.vagrant/provisioners/ansible/inventory -v tasks/main.yml
No config file found; using defaults
PLAY RECAP *********************************************************************
目录结构:
$ tree
.
├── Vagrantfile
└── tasks
└── main.yml
答案 0 :(得分:2)
您没有在config.vm.define
中定义计算机(Vagrantfile
),因此Vagrant(和Ansible)将虚拟机称为default
。
您需要修改剧本:
---
- hosts: default
tasks:
...
或者将config.vm.define
添加到Vagrantfile
:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "kurseve"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.define "kurseve"
config.ssh.insert_key = false
config.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "tasks/main.yml"
end
end
或使用多机语法:
Vagrant.configure("2") do |config|
config.vm.define "kurseve" do |server|
server.vm.box = "ubuntu/trusty64"
server.vm.hostname = "kurseve"
server.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
server.ssh.insert_key = false
server.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "tasks/main.yml"
end
end
end