p0deje / vagrant-vultr

Vultr provider for Vagrant
MIT License
46 stars 16 forks source link

Provisioning existing instances on Vultr? #2

Closed attilagyorffy closed 8 years ago

attilagyorffy commented 8 years ago

I've tried setting the config.vm.hostname variable as follows but I am unable to get Vagrant to provision my machine. Here's the config:

config.vm.hostname = 'my,vultr.instance.hostname'

  config.vm.provider :vultr do |vultr, override|
    override.vm.box = 'vultr'
    override.vm.hostname = 'my,vultr.instance.hostname'
    override.ssh.private_key_path = '~/.ssh/id_rsa'
    override.ssh.username = 'root'

    vultr.token = 'wontsharethis'

    vultr.region = 'Frankfurt'
    vultr.os = 'FreeBSD 10.2 x64'
  end

I have used DigitalOcean in the past and the vagrant-digitalocean provider and i expect this Vultr provider to work just fine when I set he box hostname. What am I missing? Is there a different way to do this?

Thanks in advance.

p0deje commented 8 years ago

I'm not sure what problem do you have. Provisioning is fully delegated to vagrant itself, there is no such code in vagrant-vultr. I have a very basic test ensuring provisioning works, so I think this has nothing to do with vagrant-vultr.

If you're trying to provision the existing instance (i.e. then one that has not been created by vagrant-vultr), then I don't think that's going to work. The fact that vagrant-digitalocean allows doing it is probably a side-effect and it is not designed to be used this way.

Please, re-open issue if you think that's still a bug and you can provide me with solid steps to reproduce the problem.

simplytech commented 6 years ago

I think setting the hostname through the Vultr API (and hence through the vagrant-vultr plugin) is different from setting it using a provisioner such as "shell" or "ansible".

Please refer to issue #11 and my corresponding pull request which makes it possible to set the hostname through the vagrant-vultr plugin. Here is a test that works (you don't need the shell or the ansible provisioner, but I had them in there so I left them as examples):

The relevant line is: vultr.hostname = 'buildbot' which I think is what @attilagyorffy was looking for.

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.provider :vultr do |vultr, override|
      override.ssh.private_key_path = '~/.ssh/id_rsa'
      override.vm.box = 'vultr'
      override.vm.box_url = 'https://github.com/p0deje/vagrant-vultr/raw/master/box/vultr.box'

      vultr.region = 'New Jersey'
      vultr.plan = '1024 MB RAM,25 GB SSD,1.00 TB BW'
      vultr.os = 'Ubuntu 16.04 x64'
      vultr.label    = 'BuildBot'
      vultr.tag      = 'Build Servers'
      vultr.hostname = 'buildbot'
  end

  config.vm.define :buildbotvm do |machine|
  end

  # Shell provisioner.
  config.vm.provision "shell", inline: "hostnamectl set-hostname buildbot" # On newer systems running systemd

  # Ansible provisioner.
  config.vm.provision "ansible" do |ansible|
    # ansible.verbose = "vvv"
    ansible.playbook = "provisioning/playbook.yml"
    ansible.inventory_path = "provisioning/inventory"
    ansible.compatibility_mode = "2.0"
    # ansible.sudo = true
  end
end