简体   繁体   English

Ansible无法设置游民箱

[英]Ansible not able to provision Vagrant box

The Vagrantfile in question: 有问题的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

I am trying to call tasks/main.yml ansible-playbook which looks like this: 我正在尝试将tasks/main.yml -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

But when I do a $ vagrant up I get the following traceback 但是当我做$ 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 *********************************************************************

The directory structure: 目录结构:

$ tree
.
├── Vagrantfile
└── tasks
    └── main.yml

You are not defining the machine ( config.vm.define ) in your Vagrantfile , so the virtual machine will be known to Vagrant (and Ansible) as default . 您没有在Vagrantfile定义计算机( config.vm.define ),因此default Vagrant(和Ansible)将知道虚拟机。

You need either to amend the playbook: 您需要修改剧本:

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

Or add config.vm.define to the Vagrantfile : 或者将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

Or use a multi-machine syntax: 或使用多机器语法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM