gpt4 book ai didi

ubuntu - Ansible 无法提供 Vagrant 盒子

转载 作者:行者123 更新时间:2023-12-04 18:40:47 29 4
gpt4 key购买 nike

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

最佳答案

您没有在 config.vm.define 中定义机器( Vagrantfile ) ,因此 Vagrant(和 Ansible)将知道虚拟机为 default .

您需要修改剧本:

---
- hosts: default
tasks:
...

或添加 config.vm.defineVagrantfile :
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

关于ubuntu - Ansible 无法提供 Vagrant 盒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42469715/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com