2

I have created my kitchen.yml in the following way:

---
driver:
  name: vagrant
  customize:
    memory: 2048

driver_config:
  require_chef_omnibus: true
  use_vagrant_berkshelf_plugin: true

provisioner:
  name: chef_zero
  chef_omnibus_url: http://box-url/install.sh

platforms:
  - name: prod.abc.com
    driver:
      box_url: http://abc.box
    run_list:
      - role[new_role]

suites:
  - name: default

In the above kitchen.yml, I get the hostname of the machine as default-prodabccom. However, I want the hostname to be prod.abc.com

What changes should i made in my kitchen.yml to get the correct name?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
meallhour
  • 13,921
  • 21
  • 60
  • 117
  • Do you want the name of the box (in virtualbox) or the hostname of the running OS to be changed? – StephenKing Jul 31 '16 at 09:22
  • when i run `kitchen converge` i get the message `Converging ...` I want it to be `Converging ...` I believe with this change the hostname will be changed to `prod.abc.com` – meallhour Jul 31 '16 at 09:26
  • It seems like even though i am including `dot` , still it is not considering it – meallhour Jul 31 '16 at 09:33
  • not sure why it was downvoted, this is exactly what I need to know, and sounds like a pretty general use case for kitchen-vagrant – Tom Feb 18 '18 at 23:03

2 Answers2

3

Hostname of the Guest System

In order to define the hostname of the operating system running inside the VM (cf. /etc/hostname), use the vm_hostname option of the kitchen-vagrant driver:

platforms:
  - name: prod.abc.com
    driver_config:
      vm_hostname: prod.abc.com

Name of the Test-Kitchen Suite/Platform

To rename the suite-platform combination shown in Converging <default-prodabccom>, you can only play with name of suite and platform, i.e., to get production-abccom. This name is computed here in test-kitchen and, e.g., all dots are stripped, which cannot simply be changed.

Nevertheless, if I understand it right that you want to change this name: it makes little sense to me. Don't change that.

Name of the VM in VirtualBox

The name of the VM (e.g. kitchen-default-prodabcom_..default_1234..) is derived here in kitchen-vagrant and cannot easily be changed.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
1

I found this question because I was in the scenario where I am testing a number of kitchen enabled repos, each containing a number of platforms. e.g.

  1. elasticsearch
    • centos-6
    • centos-7
  2. java
    • centos-6
    • centos-7

and you can give those machines their own ip by virtualbox when they are spun up like so;

driver:
  name: vagrant
  network: 
    - ["private_network", { type: "dhcp" }]

This facilitates testing, if something has failed and then you can get to the box directly. And you can use the vagrant HostManager plugin to keep your /etc/hosts updated with the current ip address.

So you can go http://default-centos-74.vagrantup.com in a local browser to check that instance. You can also name your suites in such a way that it leads to unique names for each each, across repos, for example prefixing each like so;

suites:
  - name: elasticsearch-default

and in other other .kitchen.yml

suites:
  - name: java-default

which still leads to useful naming;

http://elasticsearch-default-centos-74.vagrantup.com

However whats happended recently is that chrome and firefox have started to enforce HSTS which makes trying to get to non-HTTPS local sites, mapped using /etc/hosts a PITA.

The main thing is to get rid of the vagrantup.com suffix. However that is hard coded in, and the only option for over writing it is in .kitchen.yml which is unfortunate, because that doesn't know the suite and platform at the point it generates the Vagrantfile, so it's not much use.

You can use chef/ansible to rename the box, but that is not very nice. The solution I came up with is like this;

you can set a custom Vagrantfile.erb in .kitchen.yml ;

---
driver:
  name: vagrant
  network: 
    - ["private_network", { type: "dhcp" }]
  vagrantfile_erb: Vagrantfile.erb

Then copy that Vagrantfile.erb out of the gem on your local box into the root of your test-kitchen repo. Mine was at /home/user1/.gem/ruby/gems/kitchen-vagrant-1.3.0/templates/Vagrantfile.erb

And then you set arbitrary names to your boxes by changing it at line 36;

c.vm.hostname = "<%= @instance.name %>.<%= 
config[:kitchen_root].split('/')[-1]  %>.testbox"

or you can modify it like so, and allow over riding from the .kitchen.yml config

36c36
<   c.vm.hostname = "<%= config[:vm_hostname] %>"
---
>   c.vm.hostname = "<%= @instance.name %>.<%= config[:var_domain] ? config[:var_domain] : config[:kitchen_root].split('/')[-1]  %>.<%= config[:var_suffix] ? config[:var_suffix] : "vagrantup.com"  %>"
99d98
<

https://gist.github.com/tolland/fe01eb0f46d26850cc5c98e167578f7b

And then you set arbitrary names to your boxes by setting var_suffix and var_domain in .kitchen.yml

---
driver:
  name: vagrant
  network: 
    - ["private_network", { type: "dhcp" }]
  vagrantfile_erb: Vagrantfile.erb
  #var_domain: sometingsomething
  var_suffix: testbox
Tom
  • 3,324
  • 1
  • 31
  • 42