I’ve been banging my head against the proverbial brick wall here for a bit
and I think it’s time to ask for some help.
The Code
I present: https://github.com/vancluever/ssh_keygen_halite
Basically a library-based “HWRP” designed to make it easy to generate SSH keys.
A couple of things I am aware of:
- I might remove the dependency on
sshkey
as this stuff should be easy
enough to do withopenssl
andnet/ssh
(are these both standard library?
I can seeopenssl
but didn’t seenet/ssh
on ruby-doc). I am aware of
some issues with usingchef_gem
in library resources as well which gives
me another reason to de-couple it. - The code needs some cleanup (I have butchered it a bit trying to fix this)
- I might not be doing ChefSpec right in a way that’s unrelated to
Poise/Halite. - My greater knowledge of Ruby project management is quite novice. In fact,
this cookbook is an effort to try and teach myself how to use these tools.
My intentions here:
- Write a resource using the Poise pattern.
- Build it with the Halite pattern.
- Use the Halite helpers to simply my tests (ie: inline recipes)
- Do all of this using as few dependencies as possible (I’m deliberately
not usingpoise-boiler
right now as it seems unrelated to the pattern itself
and more related to thepoise-*
cookbooks).
Ultimately, I’d like to get this to a point where I can re-use the skeleton of
the code for other Poise-based resources, and maybe tool its generation (ie:
a la berks cookbook
).
The Problem
The generated resources seem to be empty or completely missing!
$bundle exec rspec test/spec/
...
1) SSHKeygen::Resource
Failure/Error: it { is_expected.to create_file('/root/.ssh/id_rsa') }
NoMethodError:
ssh_keygen[/root/.ssh/id_rsa] (/.../ssh_keygen_halite/test/spec/resources/ssh_keygen_spec.rb line 7) had an error: NoMethodError: undefined method `owner' for nil:NilClass
# ./lib/ssh_keygen/provider.rb:45:in `block (2 levels) in save_private_key'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/resource_builder.rb:77:in `instance_eval'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/resource_builder.rb:77:in `build'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/dsl/recipe.rb:108:in `build_resource'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/dsl/recipe.rb:69:in `declare_resource'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/dsl/resources.rb:15:in `file'
# ./lib/ssh_keygen/provider.rb:43:in `block in save_private_key'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/mixin/why_run.rb:52:in `call'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/mixin/why_run.rb:52:in `add_action'
# ./vendor/ruby/2.2.0/gems/chef-12.5.1/lib/chef/provider.rb:175:in `converge_by'
# ./lib/ssh_keygen/provider.rb:42:in `save_private_key'
# ./lib/ssh_keygen.rb:50:in `block in action_create'
[truncated]
I’ve pored over examples (namely some in poise-service
) but still can’t seem
to figure out what I’m missing, without just copy-pasting. If I had to gander a
guess I’d say I’m doing ChefSpec wrong more than anything.
Any help would be appreciated!
PS: Noah, thanks for all you work on this. I’ve used a couple of the Poise
cookbooks now with success (especially poise-service
to sensibly manage)
Upstart jobs.