Vagrant

作者: abrocod | 来源:发表于2016-09-27 10:46 被阅读27次

TO DO

Cheat Sheet

https://gist.github.com/wpscholar/a49594e2e2b918f4d0c4


Official getting start tutorial

Project setup

The first step in configuring any Vagrant project is to create aVagrantfile. The purpose of the Vagrantfile is twofold:
Mark the root directory of your project. Many of the configuration options in Vagrant are relative to this root directory.

Describe the kind of machine and resources you need to run your project, as well as what software to install and how you want to access it.

vagrant init
vagrant init hashicorp/precise64

Box

Boxes are added to Vagrant with vagrant box add. This stores the box under a specific name so that multiple Vagrant environments can re-use it. If you have not added a box yet, you can do so now:

$ vagrant box add hashicorp/precise64

Inside vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.box_version = "1.1.0"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end

Up and ssh

vagrant up
vagrant ssh

Synced folder

By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.

Provisioning

If you've never used a configuration management system before, it is recommended you start with basic shell scripts for provisioning.
You can find the full list of built-in provisioners and usage of these provisioners in the navigational area to the left.

Provision time

Provisioning happens at certain points during the lifetime of your Vagrant environment:

  • On the first vagrant up that creates the environment, provisioning is run. If the environment was already created and the up is just resuming a machine or booting it up, they will not run unless the --provision flag is explicitly provided.
  • When vagrant provision is used on a running environment.
  • When vagrant reload --provision is called. The --provision flag must be present to force provisioning.

You can also bring up your environment and explicitly not run provisioners by specifying --no-provision.

Use shell
  • Inline script
Vagrant.configure("2") do |config|
  config.vm.provision "shell",
    inline: "echo Hello, World"
end
  • External script
    Setup vagrantfile as
Vagrant.configure("2") do |config|
  config.vm.provision "shell", path: "script.sh"
end
Use Ansible

The Vagrant Ansible provisioner allows you to provision the guest usingAnsible playbooks by executing ansible-playbook from the Vagrant host.

Setup vagrantfile as

Vagrant.configure("2") do |config|

  #
  # Run Ansible from the Vagrant Host
  #
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end

end

Vagrantfile

The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines.

Configuration version
Vagrant.configure("1") do |config|
  # v1 configs...
end

Vagrant.configure("2") do |config|
  # v2 configs...
end

Networking

Port forwarding

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, guest: 80, host: 4567
end

Run a vagrant reload or vagrant up (depending on if the machine is already running) so that these changes can take effect.

Share

Teardown

Rebuild

相关文章

  • Vagrant命令

    vagrant help vagrant help vagrant [command] -h vagrant bo...

  • 用git在homestead下建私仓

    vagrant 进入 homestead 账号:vagrant 密码:vagrant 1.在vagrant账号下退...

  • vagrant

    Vagrant常用命令 Vagrant Cmd: vagrant box add 添加box的操作 vagrant...

  • homestead root账号密码和公钥链接

    vagrant账号密码: vagrant / vagrant root账号登录 vagrant登陆后,切换到roo...

  • 使用vagrant搭建hadoop环境

    环境准备 下载vagrant和virtualbox,并安装 vagrant:https://www.vagrant...

  • 2-安装

    安装 Vagrant 安装Vagrant 非常简单。前往 Vagrant downloads page 获取你的平...

  • vagrant 常用命令

    $ vagrant init # 初始化$ vagrant up # 启动虚拟机$ vagrant hal...

  • vagrant入门

    [Vagrant入门一(转)]阅读目录VirtualBox安装Vagrant安装Vagrant配置links 原文...

  • vagrant常用命令

    vagrant init# 初始化vagrant up启动虚拟机vagrant reload --provisio...

  • vagrant多台虚拟机

    使用vagrant创建多台虚拟机 安装virtualbox 安装vagrant2.2.3 vagrant init...

网友评论

    本文标题:Vagrant

    本文链接:https://www.haomeiwen.com/subject/vcucyttx.html