neillturner / kitchen-verifier-serverspec

A Test Kitchen Serverspec Verifer without having to transit the Busser layer
Other
39 stars 19 forks source link

Must env_vars be hardcoded into .kitchen.yml? #8

Closed j4m3s closed 8 years ago

j4m3s commented 8 years ago

I'm using option 3: 'Locally on your workstation running serverspec in ssh mode'

At the start of a 'kitchen verify' run, test-kitchen knows the details of the instance it is testing, and outputs them to the terminal, e.g.

[Serverspec] Verify on instance=#<Kitchen::Instance:0x0000000280a2f8> with state={:hostname=>"127.0.0.1", :port=>"2222", :username=>"vagrant", :ssh_key=>

Can those connection details not be automatically be picked-up and used for the test suite, rather than having to hard-code them into the .kitchen.yml file as described in the README?:

      env_vars:
        TARGET_HOST: 127.0.0.1
        TARGET_PORT: 2222
        LOGIN_USER: vagrant
        SSH_KEY: 'c:/repository/puppet_repo/private_key.pem'
j4m3s commented 8 years ago

I'm not a ruby man so have resorted to hacking the serverspec.rb file in my .gem directory. I've inserted the following before line 376:

          ENV['KITCHEN_' + key.to_s.upcase] = value.to_s
          info("Environment variable #{'KITCHEN_' + key.to_s.upcase} value #{value}")

Now, back in my kitchen folder I can set my spec/spec_helper.rb to contain:

  set :host, ENV['KITCHEN_HOSTNAME']
  # ssh options at http://net-ssh.github.io/ssh/v1/chapter-2.html
  # ssh via ssh key
  set :ssh_options, :user => ENV['KITCHEN_USERNAME'], :port => ENV['KITCHEN_PORT'], :paranoid => false, :verbose => :error, :host_key => 'ssh-rsa', :keys => [ ENV['KITCHEN_SSH_KEY'] ]

and everything works dynamically :)

I'm sure there's a neater way but it works!

(NB: I think the README needs updating to show the :port being set in spec/spec_helper.rb?)

neillturner commented 8 years ago

that's a good idea i will add it and update the readme.

neillturner commented 8 years ago

fixed in 0.5.0