Tasdik Rahman
Tasdik Rahman

Reputation: 2340

Ansible not able to provision Vagrant box

The Vagrantfile in question:

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

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

Upvotes: 1

Views: 464

Answers (1)

techraf
techraf

Reputation: 68609

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.

You need either to amend the playbook:

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

Or add config.vm.define to the 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

Upvotes: 2

Related Questions