Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Vagrantfile has type issues #236

Closed
jsirex opened this issue Jul 21, 2016 · 9 comments
Closed

Generated Vagrantfile has type issues #236

jsirex opened this issue Jul 21, 2016 · 9 comments
Labels

Comments

@jsirex
Copy link

jsirex commented Jul 21, 2016

I'm using latest vagrant, test-kitchen, virtualbox. Nothing helps me to bring machine up:

---
driver:
  name: vagrant
  ssh:
    insert_key: false
  customize:
    cpus: 1
    memory: 1024

Produces:

Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.box = "bento/centos-6.7"
  c.vm.hostname = "default-centos-67"
  c.ssh.insert_key = "false"
  c.vm.synced_folder ".", "/vagrant", disabled: true
  c.vm.provider :virtualbox do |p|
    p.customize ["modifyvm", :id, "--cpus", "1"]
    p.customize ["modifyvm", :id, "--memory", "1024"]
  end
end

Here is false as string "false"

Relates to #130

@keithnoguchi
Copy link

keithnoguchi commented Jul 22, 2016

Same issue here, and I can't find the way to pass false in .kitchen.yml to the Vagrantfile as is, as @jsirex mentioned above.

Here is the kitchen version, as well as the vagrant version:

$ kitchen --version
Test Kitchen version 1.10.2
$ vagrant --version
Vagrant 1.8.5

And also, here is the snippet of the kitchen create, which ended up as Authentication failure due to the insecure key update, which is reported in #130:

$ kitchen destroy
-----> Starting Kitchen (v1.10.2)
-----> Destroying <default-centos65>...
       ==> default: Forcing shutdown of VM...
       ==> default: Destroying VM and associated drives...
       Vagrant instance <default-centos65> destroyed.
       Finished destroying <default-centos65> (0m2.72s).
-----> Destroying <default-ubuntu-1404>...
       Finished destroying <default-ubuntu-1404> (0m0.00s).
-----> Destroying <default-centos-72>...
       Finished destroying <default-centos-72> (0m0.00s).
-----> Kitchen is finished. (0m2.88s)
$ kitchen list
Instance             Driver   Provisioner  Verifier  Transport  Last Action
default-centos65     Vagrant  ChefSolo     Busser    Ssh        <Not Created>
default-ubuntu-1404  Vagrant  ChefSolo     Busser    Ssh        <Not Created>
default-centos-72    Vagrant  ChefSolo     Busser    Ssh        <Not Created>
$ kitchen create default-centos65
-----> Starting Kitchen (v1.10.2)
-----> Creating <default-centos65>...
       Bringing machine 'default' up with 'virtualbox' provider...
       ==> default: Importing base box 'learningchef/centos65'...
==> default: Matching MAC address for NAT networking...
       ==> default: Checking if box 'learningchef/centos65' is up to date...
       ==> default: Setting the name of the VM: kitchen-kitchen-default-centos65_default_1469162632088_25825
       ==> default: Clearing any previously set network interfaces...
       ==> default: Preparing network interfaces based on configuration...
           default: Adapter 1: nat
       ==> default: Forwarding ports...
           default: 22 (guest) => 2222 (host) (adapter 1)
       ==> default: Booting VM...
       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 127.0.0.1:2222
           default: SSH username: vagrant
           default: SSH auth method: private key
           default:
           default: Vagrant insecure key detected. Vagrant will automatically replace
           default: this with a newly generated keypair for better security.
           default:
           default: Inserting generated public key within guest...
           default: Removing insecure key from the guest if it's present...
           default: Key inserted! Disconnecting and reconnecting using new SSH key...
           default: Warning: Authentication failure. Retrying...
           default: Warning: Authentication failure. Retrying...
           default: Warning: Authentication failure. Retrying...
^C
$ cat .kitchen.yml
---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: centos65
    driver:
      box: learningchef/centos65
      box_url: learningchef/centos65
      ssh:
        insert_key: false
  - name: ubuntu-14.04
  - name: centos-7.2

suites:
  - name: default
    run_list:
    attributes:
$ cat .kitchen/kitchen-vagrant/kitchen-kitchen-default-centos65/Vagrantfile
Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.box = "learningchef/centos65"
  c.vm.box_url = "learningchef/centos65"
  c.vm.hostname = "default-centos65"
  c.ssh.insert_key = "false"
  c.vm.synced_folder ".", "/vagrant", disabled: true
  c.vm.provider :virtualbox do |p|
  end
end

Hope we can hear some insight how to pass false as is into Vagrantfile.

Cheers,

@keithnoguchi
Copy link

I just changed Vagrantfile manually and now vagrant up runs with insecure key, which demonstrates "false" inside the Vagrantfile is the reason why kitchen create doesn't honor the .kitchen.yml rule:

$ sed -i.orig 's/\"false\"/false/'  .kitchen/kitchen-vagrant/kitchen-kitchen-default-centos65/Vagrantfile

$ cat .kitchen/kitchen-vagrant/kitchen-kitchen-default-centos65/Vagrantfile
Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.box = "learningchef/centos65"
  c.vm.box_url = "learningchef/centos65"
  c.vm.hostname = "default-centos65"
  c.ssh.insert_key = false
  c.vm.synced_folder ".", "/vagrant", disabled: true
  c.vm.provider :virtualbox do |p|
  end
end
$ pushd .kitchen/kitchen-vagrant/kitchen-kitchen-default-centos65/
/usr/local/git/chef/kitchen/.kitchen/kitchen-vagrant/kitchen-kitchen-default-centos65 /usr/local/git/chef/kitchen
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'learningchef/centos65' is up to date...
$ vagrant ssh
[email protected]'s password:
$ vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'learningchef/centos65'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'learningchef/centos65' is up to date...
==> default: Setting the name of the VM: kitchen-kitchen-default-centos65_default_1469164061393_1818
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.20
    default: VirtualBox Version: 5.1
==> default: Setting hostname...
ocean$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/kei/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

$ vagrant ssh
Last login: Fri Dec  5 05:53:15 2014 from 10.0.2.2
Welcome to your Packer-built virtual machine.
[vagrant@default-centos65 ~]$ pwd
/home/vagrant
[vagrant@default-centos65 ~]$ exit
logout
Connection to 127.0.0.1 closed.

Hope it helps.

@jsirex
Copy link
Author

jsirex commented Jul 22, 2016

I've temporary patched gem in https://github.com/test-kitchen/kitchen-vagrant/blob/master/templates/Vagrantfile.erb#L57 file:

--  c.ssh.<%= key %> = <%= value.inspect %>
++  c.ssh.<%= key %> = <%= [true, false].include?(value) ? value : value.inspect %>

@keithnoguchi
Copy link

good to know, @jsirex! Thanks for sharing!

By the way, I've tried with ubuntu-1404 and surprisingly it didn't hit the issue...

I didn't expect this, as I had an issue with centos-72, just like the custom centos-65...

Here is the snippet with ubuntu-1404, for your reference:

$ kitchen create default-ubuntu-1404
-----> Starting Kitchen (v1.10.2)
-----> Creating <default-ubuntu-1404>...
       Bringing machine 'default' up with 'virtualbox' provider...
       ==> default: Checking if box 'bento/ubuntu-14.04' is up to date...
       ==> default: Machine not provisioned because `--no-provision` is specified.
       [SSH] Established
       Vagrant instance <default-ubuntu-1404> created.
       Finished creating <default-ubuntu-1404> (0m3.12s).
-----> Kitchen is finished. (0m3.30s)
$ kitchen login default-ubuntu-1404
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-86-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Fri Jul 22 14:22:49 2016 from 10.0.2.2
vagrant@default-ubuntu-1404:~$ uname -an
Linux default-ubuntu-1404 3.13.0-86-generic #131-Ubuntu SMP Thu May 12 23:33:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
vagrant@default-ubuntu-1404:~$

@keithnoguchi
Copy link

i mean there is no #130 issue on ubuntu-1404. Obviously, the false string manipulation issue should be platform independent issue, as I didn't have insert_key: false in ubuntu-1404 in .kitchen.yml as below:

$ cat .kitchen.yml
---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: centos65
    driver:
      box: learningchef/centos65
      box_url: learningchef/centos65
      ssh:
        insert_key: false
  - name: ubuntu-14.04
  - name: centos-7.2

suites:
  - name: default
    run_list:
    attributes:

I'll update #130 regarding platform dependency, instead.

@keithnoguchi
Copy link

by the way, @jsirex, do you have a PR for that hack? I know that's a hack but I felt we can get better attention with the PR, than the issue.

Thanks for the insight!

Kei @ Kitchen/Chef newbie 😃

@ghost
Copy link

ghost commented Jul 28, 2016

I had the same issue and how this post help me was to realize that the ssh value was being cast as a string and should not be. The sed command didn't work - the command worked but the Vagrant file was regenerated with "false" instead of false. Taking a queue from jsirex I took a look at my Vagrant.erb file and I changed /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/kitchen-vagrant-0.20.0/templates/Vagrantfile.erb

From:
c.ssh.<%= key %> = "<%= value %>"

to
c.ssh.<%= key %> = <%= value %>

Just removed the quotes . . . and kitchen create worked

Mac OSX 10.11.6
Vagrant 1.8.5
Test Kitchen version 1.10.2

@cheeseplus cheeseplus added the Bug label Jul 28, 2016
@shkrt
Copy link

shkrt commented Jul 28, 2016

Also spotted this bug when working on tutorials at learn.chef.io. I use additional custom Vagrantfile to make the setting insert_key = false work. You can provide path to another Vagrantfie in the kitchen.yml file, and it would be processed directly, without kitchen-vagrant, and therefore the setting will work.

https://gist.github.com/Shkrt/480a9c9a1b91e3bbd9b321c0dbba75c5

@cheeseplus
Copy link
Contributor

cheeseplus commented Jul 29, 2016

@jsirex any chance we can get that patch as a PR? otherwise I'll open one myself for this issue. (just want to give you the chance to take credit in code, we'll note your contribution in the commit still if I make it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants