vagrant w/ KVM Ansible Playbook Setup


Userlevel 4
My co-worker Ben Thomasson wrote a small script that I want to see if people can use to setup their linux box (e.g. Ubuntu Xenial) to run vagrant w/ KVM to use our vagrant box images of Cumulus VX. Here is the playbook->

  1. Install Ansible
  2. Use this playbook (just cut and paste this code snippet)
    #  Sets up vagrant-libvirt on a new machine for a user.  # Run using: ansible-playbook -i "localhost," -c local user.yml  ---  - hosts: all    tasks:      - name: Checkout Vagrant-Libvirt plugin        git: repo=https://github.com/pradels/vagrant-libvirt dest={{playbook_dir}}/vagrant-libvirt update=no      - name: Build/Install Vagrant-Libvirt plugin        shell: 'git checkout 0.0.31; gem build vagrant-libvirt.gemspec; vagrant plugin install vagrant-libvirt*.gem'        args:           chdir: "{{playbook_dir}}/vagrant-libvirt"      - name: Install Vagrant Mutate Plugin        shell: vagrant plugin install vagrant-mutate      - name: Install Vagrant Cumulus Plugin        shell: vagrant plugin install vagrant-cumulus      - name: Add user groups        shell: sudo usermod -aG kvm,libvirt {{ansible_ssh_user}}  
    Run the playbook
    ansible-playbook -i "localhost," -c local user.yml


If you have a Vagrantfile that is KVM compatible it should work on your host machine. You can generate Vagrantfiles using our topology converter script (by Eric Pulvino) here: https://github.com/cumulusnetworks/topology_converter. Basically you would create a topology.dot file than convert it:
python topology-converter.py topology.dot --provider libvirt
Than just vagrant up!
vagrant up --provider libvirt
. Please post any questions here so we can make some nicer directions.

4 replies

I executed the playbook and it generates the following error output and exits with a failed result:
TASK [Build/Install Vagrant-Libvirt plugin] ************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "git checkout 0.0.31; gem build vagrant-libvirt.gemspec; vagrant plugin install vagrant-libvirt*.gem", "delta": "0:00:00.913529", "end": "2016-06-20 13:48:10.779508", "failed": true, "rc": 1, "start": "2016-06-20 13:48:09.865979", "stderr": "Note: checking out '0.0.31'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b

HEAD is now at 8489077... Merge pull request #468 from Paulche/table_of_content
WARNING: description and summary are identical
WARNING: pessimistic dependency on rspec-core (~> 2.12.2, development) may be overly strict
if rspec-core is semantically versioned, use:
add_development_dependency 'rspec-core', '~> 2.12', '>= 2.12.2'
WARNING: pessimistic dependency on rspec-expectations (~> 2.12.1, development) may be overly strict
if rspec-expectations is semantically versioned, use:
add_development_dependency 'rspec-expectations', '~> 2.12', '>= 2.12.1'
WARNING: pessimistic dependency on rspec-mocks (~> 2.12.1, development) may be overly strict
if rspec-mocks is semantically versioned, use:
add_development_dependency 'rspec-mocks', '~> 2.12', '>= 2.12.1'
WARNING: pessimistic dependency on nokogiri (~> 1.6.0) may be overly strict
if nokogiri is semantically versioned, use:
add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.0'
WARNING: open-ended dependency on rake (>= 0, development) is not recommended
if rake is semantically versioned, use:
add_development_dependency 'rake', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
/usr/lib/ruby/2.3.0/rubygems/specification.rb:946:in 'all=': undefined method 'group_by' for nil:NilClass (NoMethodError)
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:275:in 'with_isolated_gem'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:131:in 'install_local'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:47:in 'install_plugin'
\tfrom /usr/share/vagrant/plugins/commands/plugin/action/install_gem.rb:37:in 'call'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/action/warden.rb:34:in 'call'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/action/builder.rb:116:in 'call'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in 'block in run'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/util/busy.rb:19:in 'busy'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in 'run'
\tfrom /usr/share/vagrant/plugins/commands/plugin/command/base.rb:14:in 'action'
\tfrom /usr/share/vagrant/plugins/commands/plugin/command/install.rb:32:in 'block in execute'
\tfrom /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in 'each'
\tfrom /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in 'execute'
\tfrom /usr/share/vagrant/plugins/commands/plugin/command/root.rb:56:in 'execute'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/cli.rb:42:in 'execute'
\tfrom /usr/lib/ruby/vendor_ruby/vagrant/environment.rb:268:in 'cli'
\tfrom /usr/bin/vagrant:173:in '
'", "stdout": " Successfully built RubyGem
Name: vagrant-libvirt
Version: 0.0.30
File: vagrant-libvirt-0.0.30.gem
Installing the 'vagrant-libvirt-0.0.30.gem' plugin. This can take a few minutes...", "stdout_lines": [" Successfully built RubyGem", " Name: vagrant-libvirt", " Version: 0.0.30", " File: vagrant-libvirt-0.0.30.gem", "Installing the 'vagrant-libvirt-0.0.30.gem' plugin. This can take a few minutes..."], "warnings": ["Consider using git module rather than running git"]}


I need a bit more information to recreate this problem. Which OS and OS version does this happen on and which version of Ansible are you using?
[kbingham-laptop:~] 0 $ ansible --version
ansible 2.1.0.0
config file = /home/kbingham/.ansible.cfg
configured module search path = ['/home/kbingham/Sites/sysops/hosts/ansible/modules']

[kbingham-laptop:~] 0 $ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
Userlevel 4
I modified it as follows..
 - hosts: all  tasks:     - name: Download Vagrant (/w Checksum Verification)       get_url: url=https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4_x86_64.deb  dest=/home/{{ansible_ssh_user}}/vagrant_v1.8.4.deb checksum=sha256:fd38d8e00e494a617201facb42fc2cac627e5021db15e91c2a041eac6a2d8208     - name: Install Vagrant       apt: deb="/home/{{ ansible_ssh_user}}/vagrant_v1.8.4.deb"       become: yes     - name: Install libvirt and QEMU       apt: name={{item}} update_cache=yes       with_items:         - libvirt-bin         - libvirt-dev         - qemu-utils         - qemu       become: yes     - name: Install Vagrant Plugins (Mutate,Cumulus,Libvirt)       shell: vagrant plugin install vagrant-cumulus vagrant-mutate vagrant-libvirt       become: yes     - name: Add Cumulus Vagrant Box       shell: vagrant box add CumulusCommunity/VX-3.0     - name: Mutate the Cumulus Box to be used with libvirt       shell: vagrant mutate CumulusCommunity/VX-3.0 libvirt   

Reply