{"id":19813886,"url":"https://github.com/strzibny/vagrant-presentation","last_synced_at":"2025-05-01T10:31:03.710Z","repository":{"id":25667821,"uuid":"29103629","full_name":"strzibny/vagrant-presentation","owner":"strzibny","description":"My Vagrant presentations and corresponding notes. Originally created for DevConf.cz","archived":false,"fork":false,"pushed_at":"2015-03-23T11:24:46.000Z","size":6253,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-06T12:06:28.494Z","etag":null,"topics":["fedora","libvirt","vagrant"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/strzibny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-11T19:48:16.000Z","updated_at":"2020-12-24T19:04:49.000Z","dependencies_parsed_at":"2022-08-24T06:40:43.221Z","dependency_job_id":null,"html_url":"https://github.com/strzibny/vagrant-presentation","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/strzibny%2Fvagrant-presentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strzibny%2Fvagrant-presentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strzibny%2Fvagrant-presentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strzibny%2Fvagrant-presentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strzibny","download_url":"https://codeload.github.com/strzibny/vagrant-presentation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251859789,"owners_count":21655620,"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":["fedora","libvirt","vagrant"],"created_at":"2024-11-12T09:37:34.332Z","updated_at":"2025-05-01T10:31:03.154Z","avatar_url":"https://github.com/strzibny.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vagrant Presentation\n\nThis is the accompanying text to the Vagrant presentation available\nin this repository with comprehensive and structured information\nfeatured on the slides.\n\nVagrant *(http://vagrantup.com)* is a program for setting up reproducible\nand portable development environments easily with a large community.\n\n*Note: This presentation and text talks primarily about using\nVagrant with libvirt provider provided by vagrant-libvirt\nplugin on Fedora and derivates. A lot of the information is general\nthough.*\n\n## Presenters\n\n- Josef Stříbný\n  - GitHub: [@strzibny](https://www.github.com/strzibny)\n  - Twitter: [@strzibnyj](https://www.twitter.com/strzibnyj)\n  - Blog: [Notes to self](https://nts.strzibny.name)\n\nJosef does mostly Ruby and RubyGems packaging for Fedora and RHEL,\nand started to maintain Vagrant in Fedora.\n\n## Agenda\n\n- The Goal \u0026and; Vagrant\n- Vagrant components ecosystem\n- Using Vagrant as a developer\n- Creating your own box\n- Finding Vagrant boxes\n- Vagrant in Fedora\n- Demo\n\n## The Goal\n\nThe goal is to have isolated, distributable and portable development environments.\n\n- Isolated so your project's setup does not mess up with your workstation or other projects\n- Distributable so new member of your team can just clone your project with Vagrantfile and\nget the project running easily by reusing the configuration\n- Portable so you can run your project's development environment on Linux, Windows or Mac OS\n\n## Vagrant World\n\nVagrant is built around hosts, guests, providers and provisioners. Images are distributed in a provider-specific *.box* files\nand project's configuration is saved within *Vagrantfile*.\n\n### Definitions\n\n#### Host\n\n- Host operating system (Windows, RHEL), its detection and capabilities (NFS)\n\nMany included by defaults, others by plugins.\n\n#### Guest\n\n- Guest operating system (Ubuntu, OpenBSD, Fedora), its detection and capabilities (halt, insert public key), **virtualized environment**\n\nMany included by defaults, others by plugins.\n\n#### Provider\n\n- Provider of virtual machines or containers used (**VirtualBox**, libvirt, **docker**)\n\nVirtualBox is upstream default and docker support is also included by default.\n*libvirt* and others are available via plugins.\n\n#### Provisioner\n\n- Configuration management system to set up (provision) your machine (**Shell, Chef, Puppet**, Ansible)\n\nShell, Chef and Puppet are included in Vagrant by default.\n\n#### Vagrant box\n\n- Package format including **provider-specific** image plus metadata\n\n#### Vagrantfile\n\n- Definition of configuration and provisioning for a project **on top of a given box**\n\n## Using Vagrant as a Developer\n\nThe simplicity behind Vagrant is that developer can checked out a project repository\nand -- provided it includes Vagrantfile -- just run `vagrant up` to provision the\nmachine and to have a shared folder(s) of the project's source code and ports available\nso the development would feel pretty much like a local one.\n\nWith `vagrant rsync-auto` one can keep auto-syncing the shared folders *(if synced via rsync)*\nand with `vagrant ssh` one can access the machine via SSH. Once the work is finished,\none can halt the machine with `vagrant halt` or destroy it with `vagrant destroy`.\n\n```shell\n$ ls ~/project\n... ... ... Vagrantfile\n$ vagrant up # start and provision VMs defined in Vagrantfile\n$ vagrant rsync-auto\n$ vagrant ssh\n```\n\n```shell\n$ vagrant halt\n$ vagrant destroy\n```\n\n## Creating a Vagrant Box\n\n### From Scratch\n\n#### Preparing the Image\n\nTo create a desired image for your Vagrant box you need to ensure that\n**vagrant** user with sudo rights and without password protection exists.\n\nVagrant will use this *vagrant* user to access your virtual machine via\nSSH which means that SSH has to be present in the virtual machine and\nproperly set up.\n\nTo do so on CentOS 6, one has to install *openssh-server* package, start\nand enable the service first:\n\n```shell\n# yum install openssh-server\n# service sshd start\n# chkconfig sshd on\n# netstat -tulpn | grep :22\n```\n\nFor Fedora 21 Server is this already done *by default* so this step can\nbe skipped.\n\nVagrant uses SSH keys to access the virtual machine so the public\nkeys needs to be present on the VM for *vagrant* user.\n\nYou can set them easily with the following commands for *vagrant* user:\n\n```shell\n$ mkdir .ssh\n$ curl -k https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub\n\u003e .ssh/authorized_keys\n$ chmod 0700 .ssh\n$ chmod 0600 .ssh/authorized_keys\n```\n\nSince Vagrant would do system provisioning and administration,\nit needs to have sudo access on the machine. Using `visudo` command on Fedora\nyou can edit *sudoers* file and ensure that vagrant won't need a password\nand have sudo rights with `%vagrant ALL=(ALL) NOPASSWD: ALL`.\n\nWhen editing the *sudoers* file make sure that `requiretty` option is\nnot present (or it is commented out). That is the default on Fedora.\nIf you would require a real TTY then Vagrant commands sent to the VM\nwould fail.\n\nLast option to set up when in *sudoers* file is to allow SSH agent\nforwarding. You can set that up if you want to use the SSH key from\nour local machine inside the Vagrant box.\n\n```\n# No password\n%vagrant ALL=(ALL) NOPASSWD: ALL\n...\n# No requiretty, Fedora default\n# Defaults    requiretty\n...\n# SSH agent forwarding\nDefaults env_keep += \"SSH_AUTH_SOCK\"\n```\n\nA good practice is also setting up **root** user with password \"vagrant\",\nalthough it is not necessary for Vagrant to work. Finally you can add\nanything you like to the VM. If you would like to do provision with\nChef or Puppet for example, you would need to install them at this time.\nBut if you would like to have installed Ruby, you can decide whether to\ninclude Ruby in the VM itself or include the installation later in the\nVagrantfile.\n\n#### Packaging VM as Box\n\nVagrant boxes are simply said just tarred images. What is important to\nnote is that *.box* files are provider specific. Below is an *libvirt*\nexample for which you need only the KVM image named as *box.img* and\n*metadata.json* file which specifies the provider.\n\n*Example:* vagrant-libvirt provider and Fedora 21 server:\n\n- *qcow2* image file named **box.img**\n- optional **Vagrantfile** with defaults\n- **metadata.json**\n\nThe contents of the metadata file:\n\n```shell\n$ cat metadata.json\n{\n  \"provider\" : \"libvirt\",\n  \"format\" : \"qcow2\",\n  \"virtual_size\" : 40\n}\n```\n\nVirtual size has to be set for allocating space in storage pool (in GB).\n\nOnce you have that prepared, you can just pack it all together using **tar**:\n\n```shell\n$ tar cvzf vagrant-fedora-21-server.box ./metadata.json vagrant-fedora-21-server.qcow2\n```\n\n### In an Automatic Fashion\n\nYou can use a popular Ruby gem **veewee** to build your Vagrant boxes.\nIt provides a lot of templates for various *providers* and *guests*.\n\nHere is how to find and build a CentOS box with *libvirt* provider:\n\n```shell\n$ gem install veewee\n$ veewee kvm templates # list available templates for KVM\n$ veewee kvm define centos7-x86_64 'CentOS-7.0-1406-x86_64-netinstall' -f\n$ veewee kvm build 'centos7-x86_64' --workdir=/home/strzibny\n```\n\nThat box already comes with \u003cstrong\u003ePuppet\u003c/strong\u003e and \u003cstrong\u003eChef\u003c/strong\u003e\npreinstalled as you can see for yourself by examing the template:\n\n\n```shell\n$ ls veewee/templates/CentOS-7.0-1406-x86_64-netinstall/\nbase.sh\nchef.sh\ncleanup.sh\ndefinition.rb\nks.cfg\npuppet.sh\nvagrant.sh\nvirtualbox.sh\nvmfusion.sh\nzerodisk.sh\n```\n\nTemplate is just a collection of shell scripts that are run on the base VM\nto set it up for use as Vagrant box. `definition.rb` is an internal veewee\ndefinition for the box to be set up.\n\n## Finding Vagrant Boxes\n\nOriginally there was an official Vagrant Cloud *(vagrantcloud.com)* service that is being merged\ninto a new service called Atlas *(atlas.hashicorp.com)*.\n\nWith Atlas it's enough to:\n\n```shell\nvagrant up chef/centos-6.5 --provider virtualbox\n```\nand the corresponding box will be downloaded from HashiCorp servers.\n\nA good unofficial alternative is *http://www.vagrantbox.es/*. You can\nadd boxes from a given URL:\n\n```shell\n$ vagrant box add {title} {url}\n$ vagrant init {title}\n$ vagrant up\n```\nor add them with `vagrant box add` command.\n\n\n## Getting started using vagrant-libvirt\n\nLet's get a box first and add it:\n\n```\nwget http://file.rdu.redhat.com/~jshubin/vagrant/fedora-21/fedora-21.box\nvagrant box add fedora21 fedora-21.box\n```\n\nor:\n\n```\nvagrant box add fedora21 http://file.rdu.redhat.com/~jshubin/vagrant/fedora-21/fedora-21.box\n```\n\nEither action will add boxes in `.vagrant.d/boxes`:\n\n```\n$ ls .vagrant.d/boxes\nfedora21/\n```\n\nTo check:\n\n```\n$ vagrant box list\nfedora21 (libvirt, 0)\nrhel6    (libvirt, 0)\n```\n\nAnd to create Vagrantfile:\n```\n$ vagrant init fedora21\n```\n\nfedora21 either exists in `.vagrant.d/boxes` or `box_url` option is stated in Vagrant file:\n\n```\nconfig.vm.box = \"fedora21\"\nconfig.vm.box_url = \"http://file.rdu.redhat.com/~jshubin/vagrant/fedora-21/fedora-21.box\"\n```\n\n### $ vagrant up\n\n```\n$ vagrant up\n\n==\u003e default: Uploading base box image as volume into libvirt storage...\n==\u003e default: Creating image (snapshot of base box volume).\n\n$ sudo ls /var/lib/libvirt/images\nfedora21_vagrant_box_image.img\n\n\n==\u003e default: Creating domain with the following settings...\n..\n==\u003e default:  -- Image:             /var/lib/libvirt/images/user_default.img\n```\n\n`user` is the current directory (/home/user) and `default` is the name of the VM,\n`.img` file is renamed image from the `.box` file.\n\n```\n==\u003e default: Starting domain.\n==\u003e default: Waiting for domain to get an IP address...\n\n```\n\nlibvirt uses dnsmasq program (DNS and DHCP server) which is automatically configured and started by libvirt for each virtual network switch.\n\nOther actions follows including replacing insecure key-pairs and executing plugin hooks.\n\nTo see all our running VMs and containers:\n```\n$ vagrant global-status\n```\n\n## Vagrant in Fedora\n\n### Vagrant in Fedora 22, 21\n\nVagrant has been submitted as a Fedora 22 feature together with *vagrant-libvirt* plugin.\nAs Vagrant is already built for Fedora 22 in the official repositories it is enough to run:\n\n```shell\n# dnf install vagrant-libvirt\n```\n\nto install Vagrant with libvirt support. libvirt is the new default provider in Fedora builds.\n\nI would like to introduce a new **@vagrant** group in Fedora as well.\n\n### Older Fedoras and RHEL\n\nFollowing Copr repositories were created to install Vagrant on Fedora 20, 21 and as a software\ncollection on RHEL.\n\n- [jstribny/vagrant-f20](http://copr.fedoraproject.org/coprs/jstribny/vagrant-f20)\n- [jstribny/vagrant-f21](http://copr.fedoraproject.org/coprs/jstribny/vagrant-f21)\n- [jstribny/vagrant1 software collection](http://copr.fedoraproject.org/coprs/jstribny/vagrant1)\n\n## Official RPM\n\nIt is also possible to run the official RPM from *https://www.vagrantup.com/downloads.html* which\ncomes with VirtualBox provider as a default. You will still need to download and install\nVirtualBox yourself.\n\nIf you would like to use *libvirt* provider with the upstream package, you need to install\n*vagrant-libvirt* plugin with:\n\n```shell\n$ vagrant plugin install vagrant-libvirt\n```\n\n## Demo\n\nNew demos for this tech talk:\n\n- [github.com/strzibny/vagrant-demo-rails-postgresql-passenger](https://github.com/strzibny/vagrant-demo-rails-postgresql-passenger)\n- [github.com/strzibny/vagrant-docker-examples](https://github.com/strzibny/vagrant-docker-examples)\n\nPlease see demo/ folder for some more examples.\n\n## Attributions\n\n- This presentation @ Josef Stříbný\n- Vagrant logos and artwork @ HashiCorp, Inc.\n- Fedora, libvirt logos @ Red Hat, Inc.\n- Puppet logo @ Puppet Labs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrzibny%2Fvagrant-presentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrzibny%2Fvagrant-presentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrzibny%2Fvagrant-presentation/lists"}