ansible shell module unable to 'vagrant up' on remote host via playbook

68 views
Skip to first unread message

Oremo Ojwang

unread,
Oct 16, 2022, 3:57:24 PM10/16/22
to Ansible Project


I intend to launch a number of of vms on multiple host machines. So I have a playbook that installs vagrant and virtualbox on the host machine. Following the installations, the playbook then copies specific Vagrantfile from the ansible controller to the remote host where vms are to be lauched via 'vagrant up'.
NB:

    I am able to run the 'vagrant up' on the target machine but an error is thrown when I use the ansible playbook
    Before running the ansible, I already have set up a sudoer user called devops.
    Target host machines are ubuntu 22 desktop
    ansible version 2.10.8
    vagrant version 2.3.1
    virtualbox version 6.1

Below is the playbook content:

---
- hosts: vagranthosts
  remote_user: devops
  become: yes

  roles:
  - robertdebock.virtualbox
  - darkwizard242.vagrant

  tasks:
  - name: Show host's ip
    debug:
      msg: "{{ ansible_ssh_host }}"


  - name: Remove vagrant previous file
    file:
      path: /home/devops/vagrant-deploy/Vagrantfile
      state: absent

 
  - name: install prerequisites
    apt:
      name: libfuse2
      state: present

  - name: move to vagrant-deploy and launch vms for this host
    shell:
      cmd: vagrant up
      chdir: /home/devops/vagrant-deploy/
    become: yes


Blow is the line use to run the playbook:

ansible-playbook -i hosts.ini install-vagrant.yaml -kK -vvv

Below the specific Vagrant file that is failing:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # General Vagrant VM configuration.
  config.vm.box = "bento/ubuntu-22.04"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 1024
    v.linked_clone = true
  end

  # vagrant server 01.
  config.vm.define "app" do |app|
    app.vm.hostname = "orc-app1.test"
    app.vm.network :private_network, ip: "192.168.60.201"
  end

  # vagrant server 02
  config.vm.define "app" do |app|
    app.vm.hostname = "orc-app2.test"
    app.vm.network :private_network, ip: "192.168.60.202"
  end

 
end


Below is error:

fatal: [192.168.1.138]: FAILED! => {
    "changed": true,
    "cmd": "vagrant up",
    "delta": "0:00:17.237544",
    "end": "2022-10-15 12:09:06.419253",
    "invocation": {
        "module_args": {
            "_raw_params": "vagrant up",
            "_uses_shell": true,
            "argv": null,
            "chdir": "/home/devops/vagrant-deploy/",
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2022-10-15 12:08:49.181709",
    "stderr": "There was an error while executing `VBoxManage`, a CLI used by Vagrant\nfor controlling VirtualBox. The command and stderr is shown below.\n\nCommand: [\"showvminfo\", \"9420c5e1-629e-4148-8ce1-92658357a477\"]\n\nStderr: /usr/lib/virtualbox/VBoxManage: /tmp/.mount_vagranMxQRIa/usr/lib/libcurl.so.4: no version information available (required by /usr/lib/virtualbox/VBoxRT.so)\nVBoxManage: error: Failed to create the VirtualBox object!\nVBoxManage: error: Code NS_ERROR_ABORT (0x80004004) - Operation aborted (extended info not available)\nVBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start.",
    "stderr_lines": [
        "There was an error while executing `VBoxManage`, a CLI used by Vagrant",
        "for controlling VirtualBox. The command and stderr is shown below.",
        "",
        "Command: [\"showvminfo\", \"9420c5e1-629e-4148-8ce1-92658357a477\"]",
        "",
        "Stderr: /usr/lib/virtualbox/VBoxManage: /tmp/.mount_vagranMxQRIa/usr/lib/libcurl.so.4: no version information available (required by /usr/lib/virtualbox/VBoxRT.so)",
        "VBoxManage: error: Failed to create the VirtualBox object!",
        "VBoxManage: error: Code NS_ERROR_ABORT (0x80004004) - Operation aborted (extended info not available)",
        "VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start."
    ],
    "stdout": "",
    "stdout_lines": []
}



Oremo Ojwang

unread,
Oct 17, 2022, 2:45:56 AM10/17/22
to Ansible Project
NB: The ansible controller is a multipass running ubuntu 22.04

Dick Visser

unread,
Oct 17, 2022, 3:07:05 AM10/17/22
to ansible...@googlegroups.com
Hii

Some comments inline below

On Sun, 16 Oct 2022 at 21:57, Oremo Ojwang <george...@gmail.com> wrote:

> - name: install prerequisites
> apt:
> name: libfuse2
> state: present

I'm surprised that this doesn't need "become: true"?

> - name: move to vagrant-deploy and launch vms for this host
> shell:
> cmd: vagrant up
> chdir: /home/devops/vagrant-deploy/
> become: yes

And I'm surprised that running vagrant needs 'become: yes'.
AFAIK vagrant does not need this.

"start": "2022-10-15 12:08:49.181709",
> "stderr": "There was an error while executing `VBoxManage`, a CLI used by Vagrant\nfor controlling VirtualBox. The command and stderr is shown below.\n\nCommand: [\"showvminfo\", \"9420c5e1-629e-4148-8ce1-92658357a477\"]\n\nStderr: /usr/lib/virtualbox/VBoxManage: /tmp/.mount_vagranMxQRIa/usr/lib/libcurl.so.4: no version information available (required by /usr/lib/virtualbox/VBoxRT.so)\nVBoxManage: error: Failed to create the VirtualBox object!\nVBoxManage: error: Code NS_ERROR_ABORT (0x80004004) - Operation aborted (extended info not available)\nVBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start.",

This sounds like your Ubuntu host is missing libcurl.
Try adding that (libcurl4 to be precise) to the list of packages that
you install in the "install prerequisites" task.

Oremo Ojwang

unread,
Oct 21, 2022, 3:58:01 AM10/21/22
to ansible...@googlegroups.com
Thanks, I was able to remove the become: yes  to become_user:devops and that sorted the issue.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/2RbR8tfOFYQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLZafkR2Nhm-L87eL8QwwwJaWb7F_O7GBmrwqTPAsh9y5w%40mail.gmail.com.


--
George Oremo
Reply all
Reply to author
Forward
0 new messages