{"id":16179232,"url":"https://github.com/jonashackt/vagrant-travisci-libvrt","last_synced_at":"2025-03-19T01:30:55.472Z","repository":{"id":55158768,"uuid":"242775838","full_name":"jonashackt/vagrant-travisci-libvrt","owner":"jonashackt","description":"Example project showing how to run Vagrant on TravisCI using libvrt \u0026 KVM","archived":false,"fork":false,"pushed_at":"2021-01-06T11:07:00.000Z","size":23,"stargazers_count":25,"open_issues_count":4,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T13:46:48.626Z","etag":null,"topics":["kvm","kvm-hypervisor","libvirt","travis","travis-ci","vagrant","vagrant-libvirt"],"latest_commit_sha":null,"homepage":"https://stackoverflow.com/a/60615201/4964553","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonashackt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-24T15:46:44.000Z","updated_at":"2023-01-10T03:21:13.000Z","dependencies_parsed_at":"2022-08-14T13:51:41.258Z","dependency_job_id":null,"html_url":"https://github.com/jonashackt/vagrant-travisci-libvrt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fvagrant-travisci-libvrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fvagrant-travisci-libvrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fvagrant-travisci-libvrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fvagrant-travisci-libvrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashackt","download_url":"https://codeload.github.com/jonashackt/vagrant-travisci-libvrt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243958078,"owners_count":20374790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kvm","kvm-hypervisor","libvirt","travis","travis-ci","vagrant","vagrant-libvirt"],"created_at":"2024-10-10T05:26:10.818Z","updated_at":"2025-03-19T01:30:55.214Z","avatar_url":"https://github.com/jonashackt.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# vagrant-travisci-libvrt\n\n[![Build Status](https://www.travis-ci.com/jonashackt/vagrant-travisci-libvrt.svg?branch=master)](https://www.travis-ci.com/jonashackt/vagrant-travisci-libvrt)\n\nExample project showing how to run Vagrant on TravisCI using libvrt \u0026 KVM\n\n\u003e If you're interested, here's also a setup using VirtualBox: https://github.com/jonashackt/vagrant-travisci __BUT__ I didn't get it to work. Maybe you have an idea?!\n\n\n## Why Vagrant on a CI system?\n\nI´d really want to test bigger Infrastructure-as-Code projects like https://github.com/jonashackt/kubernetes-the-ansible-way and therefore need Vagrant running on a CI system (I don´t want to setup or host the CI system myself).\n\nAnd no, Docker-in-Docker won´t suffice here!\n\nWell until today, I really thought that __there is no way to do it with TravisCI__ - just have a look into https://github.com/jonashackt/vagrant-ansible-on-appveyor ([and this so thread](https://stackoverflow.com/questions/31828555/using-vagrant-on-cloud-ci-services)).\n\nBut then I came upon these GitHub issues in my beloved Molecule project: https://github.com/ansible-community/molecule-vagrant/issues/2#issuecomment-585616279 \u0026 especially https://github.com/ansible-community/molecule-vagrant/issues/8#issuecomment-589902704, which confused me right away.\n\nDid you know [libvirt](https://libvirt.org/)??! I didn't, this thing is a crazy thing - [an API for all those virtualization providers out there](https://help.ubuntu.com/lts/serverguide/libvirt.html) (sounds like Vagrant, huh?!). And as the GitHub Issue comments state, it should be possible to use Vagrant with libvrt \u0026 KVM on TravisCI... Which would give us the following workflow for our tools:\n\n![cloud-uml](http://www.plantuml.com/plantuml/proxy?cache=no\u0026src=https://raw.githubusercontent.com/jonashackt/vagrant-travisci-libvrt/master/cloud.iuml)\n![local-uml](http://www.plantuml.com/plantuml/proxy?cache=no\u0026src=https://raw.githubusercontent.com/jonashackt/vagrant-travisci-libvrt/master/local.iuml)\n\nWe also need an Vagrant-extension for libvirt, which is luckily already available: [the Vagrant libvirt Plugin](https://github.com/vagrant-libvirt/vagrant-libvirt)\n\n__ONLY IF__ there are Vagrant Boxes that support both `libvrt` \u0026 `virtualbox` as a provider. And... there are! Just have a look at the `generic` boxes on the Vagrant Cloud: https://app.vagrantup.com/boxes/search?provider=libvirt\u0026q=ubuntu+bionic\u0026sort=downloads\u0026utf8=%E2%9C%93, which are backed by https://roboxes.org\n\nThis would fulfil our request: in both cases a simple `vagrant up` based on the same [Vagrantfile](Vagrantfile) would work.\n\n## Using vagrant-libvirt to run Vagrant with libvrt \u0026 KVM on TravisCI\n\nFirst we need to configure the usual Travis [.travis.yml](.travis.yml) for our project:\n\n```yaml\ndist: bionic\nlanguage: python\n\ninstall:\n# Install libvrt \u0026 KVM (see https://github.com/alvistack/ansible-role-virtualbox/blob/master/.travis.yml)\n- sudo apt-get update \u0026\u0026 sudo apt-get install -y bridge-utils dnsmasq-base ebtables libvirt-bin libvirt-dev qemu-kvm qemu-utils ruby-dev\n\n# Download Vagrant \u0026 Install Vagrant package\n- sudo wget -nv https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb\n- sudo dpkg -i vagrant_2.2.7_x86_64.deb\n\n# Vagrant correctly installed?\n- vagrant --version\n\n# Install vagrant-libvirt Vagrant plugin\n- sudo vagrant plugin install vagrant-libvirt\n```\n \nThen we also need to install [vagrant-libvirt](https://github.com/vagrant-libvirt/vagrant-libvirt) on TravisCI.\n\n## prevent errors like The home directory you specified is not accessible\n\nYou may experience some strange errors like `The home directory you specified is not accessible`:\n\n```\n$ vagrant up --provider=libvirt\n\nVagrant failed to initialize at a very early stage:\n\nThe home directory you specified is not accessible. The home\n\ndirectory that Vagrant uses must be both readable and writable.\n\nYou specified: /home/travis/.vagrant.d\n\nThe command \"vagrant up --provider=libvirt\" exited with 1.\n```\n\nor `Permission denied @ rb_sysopen - /home/travis/.vagrant.d/data/machine-index/index.lock (Errno::EACCES)`:\n\n```\n$ vagrant up --provider=libvirt\n\n/opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine_index.rb:321:in `initialize': Permission denied @ rb_sysopen - /home/travis/.vagrant.d/data/machine-index/index.lock (Errno::EACCES)\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine_index.rb:321:in `open'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine_index.rb:321:in `with_index_lock'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine_index.rb:52:in `initialize'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:723:in `new'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:723:in `machine_index'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:206:in `block in action_runner'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/runner.rb:34:in `run'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:525:in `hook'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:774:in `unload'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/bin/vagrant:185:in `ensure in \u003cmain\u003e'\n\n\tfrom /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/bin/vagrant:185:in `\u003cmain\u003e'\n\nThe command \"vagrant up --provider=libvirt\" exited with 1.\n```\n\nThe simplest solution here is to always use `sudo` prefixing our `vagrant` commands (although [this stackoverflow answer](https://stackoverflow.com/a/29438084/4964553) tells us not to do so).\n\n## Finally testdrive the Vagrant installation\n\nNow we should be able to add a `vagrant up` to the `script` section to our [.travis.yml](.travis.yml). __But be sure__ to add the ` --provider=libvirt` to the command! Otherwise Vagrant won't pick up `libvrt` as it's virtualization provider ([as stated in the docs](https://github.com/vagrant-libvirt/vagrant-libvirt#start-vm9)):\n\n```yaml\nscript:\n- sudo vagrant up --provider=libvirt\n- sudo vagrant ssh -c \"echo 'hello world!'\"\n```\n\n## polishing: cache vagrant boxes\n\nTo speed up our future builds, we should try to cache the big Vagrant boxes throughout our builds. [The Travis docs state](https://docs.travis-ci.com/user/caching/#arbitrary-directories), that we only need to add the following to our [.travis.yml](.travis.yml):\n\n```yaml\ncache:\n  directories:\n  - /home/travis/.vagrant.d/boxes\n```\n\nDon't simple use `.vagrant.d/boxes` here, since Vagrant will place it's boxes inside `/home/travis/.vagrant.d/boxes` - and not inside `$TRAVIS_BUILD_DIR/.vagrant.d/boxes` which expands to `/home/travis/build/jonashackt/vagrant-travisci/.vagrant.d/boxes`.\n\n\n## prevent Error while creating domain: Error saving the server: Call to virDomainDefineXML failed: invalid argument: could not find capabilities for domaintype=kvm\n\nIf we don't have a look into our [Vagrantfile](Vagrantfile) beforehand, we may run into the following error:\n\n```\n$ sudo vagrant up --provider=libvirt\n\nBringing machine 'ubuntu' up with 'libvirt' provider...\n==\u003e ubuntu: Box 'generic/ubuntu1804' could not be found. Attempting to find and install...\n    ubuntu: Box Provider: libvirt\n    ubuntu: Box Version: \u003e= 0\n==\u003e ubuntu: Loading metadata for box 'generic/ubuntu1804'\n    ubuntu: URL: https://vagrantcloud.com/generic/ubuntu1804\n==\u003e ubuntu: Adding box 'generic/ubuntu1804' (v2.0.6) for provider: libvirt\n    ubuntu: Downloading: https://vagrantcloud.com/generic/boxes/ubuntu1804/versions/2.0.6/providers/libvirt.box\n    ubuntu: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com\n==\u003e ubuntu: Successfully added box 'generic/ubuntu1804' (v2.0.6) for 'libvirt'!\n==\u003e ubuntu: Uploading base box image as volume into libvirt storage...\n==\u003e ubuntu: Creating image (snapshot of base box volume).\n==\u003e ubuntu: Creating domain with the following settings...\n==\u003e ubuntu:  -- Name:              molecule-ansible-docker-aws_ubuntu\n==\u003e ubuntu:  -- Domain type:       kvm\n==\u003e ubuntu:  -- Cpus:              2\n==\u003e ubuntu:  -- Feature:           acpi\n==\u003e ubuntu:  -- Feature:           apic\n==\u003e ubuntu:  -- Feature:           pae\n==\u003e ubuntu:  -- Memory:            2048M\n==\u003e ubuntu:  -- Management MAC:    \n==\u003e ubuntu:  -- Loader:            \n==\u003e ubuntu:  -- Nvram:             \n==\u003e ubuntu:  -- Base box:          generic/ubuntu1804\n==\u003e ubuntu:  -- Storage pool:      default\n==\u003e ubuntu:  -- Image:             /var/lib/libvirt/images/molecule-ansible-docker-aws_ubuntu.img (32G)\n==\u003e ubuntu:  -- Volume Cache:      default\n==\u003e ubuntu:  -- Kernel:            \n==\u003e ubuntu:  -- Initrd:            \n==\u003e ubuntu:  -- Graphics Type:     vnc\n==\u003e ubuntu:  -- Graphics Port:     -1\n==\u003e ubuntu:  -- Graphics IP:       127.0.0.1\n==\u003e ubuntu:  -- Graphics Password: Not defined\n==\u003e ubuntu:  -- Video Type:        cirrus\n==\u003e ubuntu:  -- Video VRAM:        256\n==\u003e ubuntu:  -- Sound Type:\t\n==\u003e ubuntu:  -- Keymap:            en-us\n==\u003e ubuntu:  -- TPM Path:          \n==\u003e ubuntu:  -- INPUT:             type=mouse, bus=ps2\nError while creating domain: Error saving the server: Call to virDomainDefineXML failed: invalid argument: could not find capabilities for domaintype=kvm \nThe command \"sudo vagrant up --provider=libvirt\" exited with 1.\n``` \n\nTo prevent this, we need to use at least Ubuntu `bionic` as our Travis build system. Therefore we should configure it inside our [.travis.yml](.travis.yml):\n\n```yaml\n---\ndist: bionic\n...\n```\n\n\n# Optional: Install libvirt locally\n\nYou may also want to use libvirt locally. Therefore [we need to install libvirt and QEMU/KVM according to the docs](https://github.com/vagrant-libvirt/vagrant-libvirt#installation).\n\nOn Mac OS we can [simply use `homebrew` like this post describes](https://lunar.computer/posts/vagrant-libvirt-macos/):\n\n```shell script\nbrew install libiconv gcc libvirt\n```\n\nThen run the libvirt service with\n\n```\nbrew services start libvirt\n```\n\nNow we should be able to install the [vagrant-libvirt plugin](https://github.com/vagrant-libvirt/vagrant-libvirt#installation), but with some additions (cause otherwise we'll run into errors like `extconf.rb:73:in '\u003cmain\u003e': libvirt library not found in default locations (RuntimeError)`):\n\nFirst, check the ruby version Vagrant uses with:\n\n```\n$ /opt/vagrant/embedded/bin/ruby --version\nruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin13]\n```\n\nFor me this is `2.4.4`, so insert the version and run:\n\n```\n$ CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' \\\nGEM_HOME=~/.vagrant.d/gems/2.4.4 \\\nGEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \\\nPATH=/opt/vagrant/embedded/bin:$PATH \\\nvagrant plugin install vagrant-libvirt\n```\n\nThis should install `libvirt` successfully:\n\n```\nInstalling the 'vagrant-libvirt' plugin. This can take a few minutes...\nBuilding native extensions.  This could take a while...\nFetching: fog-libvirt-0.7.0.gem (100%)\nFetching: vagrant-libvirt-0.0.45.gem (100%)\nInstalled the plugin 'vagrant-libvirt (0.0.45)'!\n```\n\nNow we should be able to fire up our Molecule Vagrant test based on `libvirt`:\n\n```\npipenv run molecule --debug create --scenario-name vagrant-libvirt-ubuntu \n```\n\nFinal problem: https://discourse.brew.sh/t/failed-to-connect-socket-to-var-run-libvirt-libvirt-sock-no-such-file-or-directory/1297\n\nAs simple `vagrant up` with libirt doesn't work right now:\n\n```\nvagrant up --provider=libvirt\nBringing machine 'ubuntu' up with 'libvirt' provider...\nError while connecting to libvirt: Error making a connection to libvirt URI qemu:///system?no_verify=1\u0026keyfile=/Users/jonashecht/.ssh/id_rsa\u0026socket=/var/run/libvirt/libvirt-sock:\nCall to virConnectOpen failed: Socket-Erstellung zu '/var/run/libvirt/libvirt-sock' fehlgeschlagen: No such file or directory\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fvagrant-travisci-libvrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashackt%2Fvagrant-travisci-libvrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fvagrant-travisci-libvrt/lists"}