# WIP: Vagrant ProfitBricks Cloud Provider This is a [Vagrant](http://www.vagrantup.com) 1.5+ plugin that adds a [ProfitBricks](https://devops.profitbricks.com) provider to Vagrant, allowing Vagrant to control and provision machines within the ProfitBricks cloud. **Note:** This plugin requires Vagrant 1.5+. ## Features * Boot ProfitBricks instances. * SSH into the instances. * COMING SOON: Provision the instances with any built-in Vagrant provisioner. * Sync folders with any built-in Vagrant synchronized folder plugin (e.g. `rsync`) * Create ProfitBricks images from a running Vagrant box ## Installation Install using the standard Vagrant plugin installation methods. ``` $ vagrant plugin install vagrant-profitbricks ``` ## Usage Once the plugin is installed, you use it with `vagrant up` by specifying the `profitbricks` provider: ``` $ vagrant up --provider=profitbricks ``` You'll need a Vagrantfile in order to properly create/configure remote servers. You can generate a sample Vagrantfile with `vagrant init`. Here's an example with ProfitBricks configuration: ```ruby Vagrant.configure("2") do |config| # The box is optional in newer versions of Vagrant # config.vm.box = "dummy" config.vm.provider :profitbricks do |rs| rs.username = "YOUR PB USERNAME" rs.password = "YOUR PB PASSWORD" rs.flavor = /Small/ rs.image = /Ubuntu/ rs.datacenter_id = /DC_Ge/ rs.profitbricks_volume_size = 20 end end ``` You may be required to use a box, depending on your version of Vagrant. If necessary you can add the "dummy" box with the command: ``` $ vagrant box add dummy https://github.com/profitbricks/vagrant-profitbricks/raw/master/dummy.box ``` Then uncomment the line containing `config.vm.box = "dummy"`. Once the server is created a confirmation email is received with your credentials. Also, the password can be set inside the config section with the option admin_password. In both cases it is required that you change the password upon first logon. After server creation the user can login with: ``` $ vagrant ssh ``` Once the password is changed it is posible to provision synced_folders with ``` $ vagrant provision ``` ### CentOS / RHEL / Fedora The default configuration of the RHEL family of Linux distributions requires a tty in order to run sudo. Vagrant does not connect with a tty by default, so you may experience the error: > sudo: sorry, you must have a tty to run sudo You can tell Vagrant it should use a pseudo-terminal (pty) to get around this issue with the option: ```ruby config.ssh.pty = true ``` However, Vagrant does not always work well with the pty. In particular, rsync may not work. So we recommend using this configuration for a workaround which will reconfigure the server so a tty is not required to run sudo: The following settings show an example of how you can workaround the issue: ```ruby Vagrant.configure("2") do |config| config.vm.box = "dummy" config.ssh.pty = true config.vm.provider :profitbricks do |rs| rs.username = "YOUR USERNAME" rs.password = "YOUR PASSWORD" rs.profitbricks_ram = 1024 rs.profitbricks_cores = 1 rs.image = /^CentOS-7/ rs.datacenter_id = /DC_US/ end end ``` ### Windows Windows servers can be created with this provider; however, Profitbricks images do not have the WinRM service started or an SSH server pre-installed. To take full advantage of Vagrant, you need to enable WinRM to use the `vagrant rdp` command to launch Remote Desktop. You can consult the vagrant documentation on how to enable WinRM on created server [WINRM CONFIGURATION](http://docs.vagrantup.com/v2/boxes/base.html) The following settings show how to setup box to enable RDP: ```ruby Vagrant.configure("2") do |config| config.vm.box = "dummy" config.vm.communicator = "winrm" config.vm.provider :profitbricks do |rs| rs.username = "YOUR USERNAME" rs.password = "YOUR PASSWORD" rs.flavor = /Meduim/ rs.image = /^windows-2012-r2/ rs.profitbricks_volume_size = 30 rs.datacenter_id = /DC_US/ end end ``` ### Parallel, multi-machine setup You can define multiple machines in a single Vagrant file, for example: ```ruby Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "dummy" config.vm.define :ubuntu do |ubuntu| ubuntu.vm.provider :profitbricks do |rs| rs.username = ENV['PB_USERNAME'] rs.admin_password = ENV['VAGRANT_ADMIN_PASSWORD'] rs.password = ENV['PB_PASSWORD'] rs.flavor = /Micro/ rs.image = /Ubuntu/ rs.datacenter_id = /DC_US/ end end config.vm.define :centos do |centos| centos.ssh.pty = true centos.vm.provider :profitbricks do |rs| rs.username = ENV['PB_USERNAME'] rs.admin_password = ENV['VAGRANT_ADMIN_PASSWORD'] rs.password = ENV['PB_PASSWORD'] rs.flavor = /Micro/ rs.image = /^CentOS/ # Don't match OnMetal - CentOS rs.datacenter_id = /DC_US/ end end end ``` You than can then launch them all with `vagrant up --provider profitbricks`, or a specific server with `vagrant up --provider profitbricks `. Vagrant will create all machines simultaneously when you have a multi-machine setup. If you want to create them one at a time or have any trouble, you can use the `--no-parallel` option. ## Custom Commands The plugin includes several ProfitBricks-specific vagrant commands. You can get the list of available commands with `vagrant profitbricks -h`. ### Flavors / Images You can list all available images with the command: ``` $ vagrant profitbricks images ``` ``` $ vagrant profitbricks flavors ``` If you have a multi-machine setup than this will show the images/flavors for each machine. This seems a bit repetitive, but since machines can be configured for different locations or even accounts they may have a different set of available images or flavors. You can also get the list for a specific machine by specifying its name as an argument: ``` $ vagrant profitbricks images $ vagrant profitbricks flavors ``` These commands will connect to ProfitBricks using the settings associated with the machine and query the location to get the list of available flavors, images, networks and servers. ## Configuration This provider exposes quite a few provider-specific configuration options: | NAME| DESCRIPTION | |---|---| | datacenter_id | Datacenter Id or name or regular expression that matches the datacenter name. | | username | The username with which to access ProfitBricks. | | password | The API password for accessing ProfitBricks. | | admin_password | Root user password that will be used for first login. | | flavor | The server flavor to boot. This can be a string matching the exact ID or name of the server, or this can be a regular expression to partially match some server flavor. Flavors are listed [here](#flavors). As an alternative to using flavor names, one can specify the amount of ram in MB and number of cores with `profitbricks_ram` and `profitbricks_cores`. | | profitbricks_volume_size | The size of the volume in GB. | | volume_type | Disk volume type (SSD or HDD). Will default to SSD if not specified | | volume_licence_type | The licence type of the volume. Options: LINUX, WINDOWS, UNKNOWN, OTHER. You will need to provide either the `image` or the `volume_licence_type` parameters. `volume_licence_type` is required, but if `image` is supplied, it is already set and cannot be changed. | | volume_availability_zone | The storage availability zone assigned to the volume. Valid values: AUTO, ZONE_1, ZONE_2, or ZONE_3. This only applies to HDD volumes. Leave blank or set to AUTO when provisioning SSD volumes. Will default to AUTO if not specified. | | image | The server image to boot. This can be a string matching the exact ID or name of the image or this can be a regular expression to partially match some image. | | image_password | One-time password is set on the Image for the appropriate account. This field may only be set in creation requests. When reading, it always returns null. Password has to contain 8-50 characters. Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789] | | volume_ssh_keys | SSH keys to allow access to the volume via SSH | | profitbricks_url | The compute_url to hit. This is good for custom endpoints. | | server_name | The name of the server within ProfitBricks Cloud. This defaults to the name of the Vagrant machine (via `config.vm.define`), but can be overridden with this. | | location | Specify location for datacenter if one needs to be created, default value is 'us/las' | | cpu_family | Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON". | | lan_id | The LAN ID the network interface (NIC) will sit on. If the LAN ID does not exist it will be created. | | nat | Indicates the private IP address has outbound access to the public internet. Defaults to 'false'. | These can be set like typical provider-specific configurations: ```ruby Vagrant.configure("2") do |config| # ... other stuff config.vm.provider :profitbricks do |rs| rs.username = "profitbricks_user" rs.api_key = "profitbricks_password" end end ``` You can find a more complete list the documentation for the [Config class](http://www.rubydoc.info/gems/vagrant-profitbricks/VagrantPlugins/ProfitBricks/Config). ### Networks Networking features in the form of `config.vm.network` are not supported with `vagrant-profitbricks`, currently. If any of these are specified, Vagrant will emit a warning, but will otherwise boot the ProfitBricks server. ## Development To work on the `vagrant-profitbricks` plugin, clone this repository out, and use [Bundler](http://gembundler.com) to get the dependencies: ``` $ bundle ``` Once you have the dependencies, verify the unit tests pass with `rake`: ``` $ bundle exec rake ``` If those pass, you're ready to start developing the plugin. You can test the plugin without installing it into your Vagrant environment by just creating a `Vagrantfile` in the top level of this directory (it is gitignored) that uses it and use bundler to execute Vagrant: ``` $ bundle exec vagrant up --provider=profitbricks ```