Rspec giving no implicit conversion of Hash into String for an array

1,690 views
Skip to first unread message

James Perry

unread,
Aug 16, 2017, 12:51:30 PM8/16/17
to Puppet Developers
I am getting an odd error when running rake spec on my module.  The functions work fine when setup in Puppet, but when I try to test it rspec is kicking out an error about my $myarr arrays.  When I comment it out, the tests pass. 

What they heck does this error mean and why does it complain when Puppet uses it just fine? 

The error I am getting is: 
  2) ssh::sshd_config should contain Service[myservice]
     Failure/Error: is_expected.to contain_service('myservice')

     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Hash into String at line 1:1 on node <mynode>
     # :1:in `block in call_function'
     # :in `stack'
     # ./spec/classes/init_spec.rb:18:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # TypeError:
     #   no implicit conversion of Hash into String
     #   :1:in `block in call_function'


I have an array defined as 
$myarr = [ 'one', 'two', 'three' ] 
in myparams.pp

In init.pp I have a pretty basic setup
class mymodule {
   include mymodule::myparams

   file { "/tmp/myfile": 
    ensure => present,
    owner   => "root",
    group   => "root",
    mode    => "0600",
    before => Service["myservice"]
    }

   service { "myservice": 
      ensure => running,
      subscribe => File["/tmp/myfile"],
      }
}

My spec file has: 
require 'spec_helper'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-utils'
require 'hiera-puppet-helper'
require 'facter'

describe 'ssh::sshd_config' do
  it do 
   is_expected.to contain_file('/tmp/myfile')
  end
  it do 
    is_expected.to contain_service('myservice')
  end
end


John Bollinger

unread,
Aug 16, 2017, 2:13:50 PM8/16/17
to Puppet Developers


On Wednesday, August 16, 2017 at 11:51:30 AM UTC-5, James Perry wrote:
I am getting an odd error when running rake spec on my module.  The functions work fine when setup in Puppet, but when I try to test it rspec is kicking out an error about my $myarr arrays.  When I comment it out, the tests pass. 

What they heck does this error mean and why does it complain when Puppet uses it just fine? 


I'm inclined to suspect that the "it" that Puppet uses just fine is something altogether different from the code you presented for our consideration.  File names, contents, and line numbers do not appear to be consistent among your error message, spec file, and manifest.  If you want help, then please present the smallest complete example you can come up with that demonstrates the problem, along with the details of the environment you're testing in and the full, original error message(s) corresponding to the example. Who knows -- you might even discover the issue in the process of preparing that.

FWIW, the code you presented for class mymodule looks ok to me, modulo the contents of the unprovided mymodule::myparams class.


John

James Perry

unread,
Aug 18, 2017, 9:48:54 AM8/18/17
to Puppet Developers
So let me try this again. Here is the full init.pp and spec file being used.  The setup is very simple.  Likewise it does't matter if the $sshd_hostkey_rhel_cent_7 is setup as a smart parameter or set inside the module itself, the error "Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Hash into String at line 2:1 on node" persists relative to where the array is defined. 

Note: I attached the templates/sshd_config.erb for brevity.

I find this quite perplexing as the array is defined properly and when I run t on a CentOS 7 / RHEL 7 box, via puppet apply, I have no errors. This happens on my dev Foreman/Puppet 4 server and on a stand-along VM spun up just to verify this behavior persists on a clean install of the puppet agent and gems to do spec testing. (Output of puppet apply the end of the post)

manifests/init.pp (ssh)
# Class: ssh
#
# This module manages ssh
#
# Parameters: none
#
# Actions:
#
# Requires: see Modulefile
#
# Sample Usage:
#
class ssh () {
}

class ssh::sshd_config (
  # Hostkey setting for CentOS / RHEL 7
  $sshd_hostkey_rhel_cent_7 = [
    '# HostKey for protocol version 1',
    '#HostKey /etc/ssh/ssh_host_key',
    '# HostKeys for protocol version 2',
    'HostKey /etc/ssh/ssh_host_rsa_key',
    '#HostKey /etc/ssh/ssh_host_dsa_key',
    'HostKey /etc/ssh/ssh_host_ecdsa_key',
    'HostKey /etc/ssh/ssh_host_ed25519_key',
    ]
    ) {
 # Setup sshd_config file for SUSE, RedHat, CentOS
  include ssh


  # Get OS Major version as it differs from facter versions
  # and lsbdist pacakges not installed on RedHat by default

  $osver = split($::operatingsystemrelease, '[.]')
  $osmajver = $osver[0]

  case $::facts['operatingsystem'] {
    'RHEL', 'CentOS', 'RedHat' : {
      $sshd_sftp_subsystem = "/usr/libexec/openssh/sftp-server"
      $sshd_syslogfacility = "SyslogFacility AUTHPRIV"

      if $::facts['$operatingsystemrelease'] >= "7" {
        # CentOS / RedHat 7 +
        $sshd_hostkey = $sshd_hostkey_rhel_cent_7
      } else {
        $sshd_hostkey = "# Hostkey not set in RH/CentOS under version 7"
      }
    }
    # RHEL, CENTOS
    'SLES'                     : {
      $sshd_hostkey = "# HostKey not set in SUSE"
      $sshd_sftp_subsystem = "/usr/lib64/ssh/sftp-server"
      $sshd_syslogfacility = "# SyslogFacility not set in SUSE"
    }
    default                    : {
      $sshd_sftp_subsystem = "/usr/libexec/openssh/sftp-server"
      $sshd_syslogfacility = "SyslogFacility AUTHPRIV"
      $sshd_hostkey = "# Hostkey not set in Default section of case statement"
    }
  }

  file { "sshdconfig":
    ensure  => present,
    path    => "/etc/ssh/sshd_config",
    owner   => "root",
    group   => "root",
    mode    => "0600",
    content => template("ssh/sshd_config.erb"),
    before  => Service['sshd'],
  }

  service { "sshd":
    ensure    => running,
    name      => "sshd",
    enable    => true,
    subscribe => File["sshdconfig"],
  }

}


spec/classes/init_spec.rb
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-utils'
require 'hiera-puppet-helper'
require 'spec_helper'
require 'facter'

describe 'ssh::sshd_config' do
  let :facts do {
    :operatingsystemrelease => "7.3.1611s"
  }
  end
    it { is_expected.to contain_file('sshdconfig') }
    it { is_expected.to contain_service('sshd') }
end

spec/spec_helper:
require 'puppetlabs_spec_helper/module_spec_helper'

----------------------------------------------
So if in manifests/init.pp I comment out lines 18-26 and 44:

class ssh::sshd_config (
  # Hostkey setting for CentOS / RHEL 7
#  $sshd_hostkey_rhel_cent_7 = [
#    '# HostKey for protocol version 1',
#    '#HostKey /etc/ssh/ssh_host_key',
#    '# HostKeys for protocol version 2',
#    'HostKey /etc/ssh/ssh_host_rsa_key',
#    '#HostKey /etc/ssh/ssh_host_dsa_key',
#    'HostKey /etc/ssh/ssh_host_ecdsa_key',
#    'HostKey /etc/ssh/ssh_host_ed25519_key',
#    ]
   ) {
  # Setup sshd_config file for SUSE, RedHat, CentOS
  include ssh

...
        # CentOS / RedHat 7 +
 #       $sshd_hostkey = $sshd_hostkey_rhel_cent_7
...

Then run rake spec I get: 
/usr/bin/ruby -I/usr/local/share/gems/gems/rspec-core-3.6.0/lib:/usr/local/share/gems/gems/rspec-support-3.6.0/lib /usr/local/share/gems/gems/rspec-core-3.6.0/exe/rspec --pattern spec/\{aliases,classes,defines,unit,functions,hosts,integration,type_aliases,types\}/\*\*/\*_spec.rb --color

ssh::sshd_config
  should contain File[sshdconfig]
  should contain Service[sshd]

Finished in 0.78541 seconds (files took 1.7 seconds to load)
2 examples, 0 failures

-----------------------------
If I run the original init.pp above, i get the following when I run rake spec

# rake spec
I, [2017-08-18T09:22:52.855739 #30964]  INFO -- : Creating symlink from spec/fixtures/modules/ssh to /etc/puppetlabs/code/environments/aspera/modules/ssh

Notice: Preparing to install into /etc/puppetlabs/code/environments/aspera/modules/ssh/spec/fixtures/modules ...
Notice: Downloading from https://forgeapi.puppet.com ...
Notice: Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/aspera/modules/ssh/spec/fixtures/modules
└── puppetlabs-stdlib (v4.17.1)
/usr/bin/ruby -I/usr/local/share/gems/gems/rspec-core-3.6.0/lib:/usr/local/share/gems/gems/rspec-support-3.6.0/lib /usr/local/share/gems/gems/rspec-core-3.6.0/exe/rspec --pattern spec/\{aliases,classes,defines,unit,functions,hosts,integration,type_aliases,types\}/\*\*/\*_spec.rb --color

ssh::sshd_config
  should contain File[sshdconfig] (FAILED - 1)
  should contain Service[sshd] (FAILED - 2)

Failures:

  1) ssh::sshd_config should contain File[sshdconfig]
     Failure/Error: it { is_expected.to contain_file('sshdconfig') }

     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Hash into String at line 2:1 on node mynode.example.com
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `initialize'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `new'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `global_hiera_config_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:224:in `global_hiera_config_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/global_data_provider.rb:71:in `configuration_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/configured_data_provider.rb:16:in `config'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/global_data_provider.rb:13:in `unchecked_key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/data_provider.rb:41:in `block in key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:90:in `check'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/data_provider.rb:41:in `key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:76:in `lookup_global'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `block in global_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `global_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:325:in `env_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:291:in `block (2 levels) in retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:129:in `with'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:287:in `block in retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:75:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:286:in `retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:181:in `lookup_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:166:in `lookup_merge_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:58:in `block in lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:75:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:50:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup.rb:76:in `search_and_merge'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:401:in `block (2 levels) in inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:400:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:400:in `block in inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:396:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:396:in `inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:363:in `set_resource_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:171:in `evaluate_code'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:81:in `block in evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:73:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:395:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:395:in `evaluate_classes'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/loader/../../../puppet/functions/include.rb:16:in `include'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatch.rb:60:in `invoke'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:43:in `block in dispatch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:42:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:42:in `dispatch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:46:in `block in call'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:45:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:45:in `call'
     # :2:in `block in call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:313:in `eval'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:313:in `block in call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:311:in `call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:941:in `call_function_with_block'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:910:in `eval_CallNamedFunctionExpression'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:48:in `block in visit_this'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:42:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:42:in `visit_this'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:71:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # :in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `eval'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:715:in `eval_Program'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:48:in `block in visit_this'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:42:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:42:in `visit_this'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:71:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/parser/evaluating_parser.rb:63:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast/pops_bridge.rb:132:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast.rb:31:in `safeevaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:184:in `evaluate_code'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:81:in `block in evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:73:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:635:in `evaluate_main'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block (2 levels) in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/context.rb:65:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet.rb:306:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:162:in `compile'
     # /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera-puppet-helper/puppet.rb:16:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:33:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:268:in `block (2 levels) in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:266:in `block in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util.rb:224:in `block in benchmark'
     # /usr/share/ruby/benchmark.rb:296:in `realtime'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util.rb:223:in `benchmark'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:264:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:55:in `find'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/indirection.rb:194:in `find'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/adapters.rb:83:in `catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/adapters.rb:161:in `catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:354:in `build_catalog_without_cache'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:375:in `block in build_catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/cache.rb:17:in `call'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/cache.rb:17:in `get'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:374:in `build_catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:75:in `block in load_catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:319:in `with_vardir'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:69:in `load_catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:10:in `block in subject'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/matchers/create_generic.rb:84:in `call'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/matchers/create_generic.rb:84:in `matches?'
     # ./spec/classes/init_spec.rb:12:in `block (2 levels) in <top (required)>'

  2) ssh::sshd_config should contain Service[sshd]
     Failure/Error: it { is_expected.to contain_service('sshd') }

     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Hash into String at line 2:1 on node mynode.example.com
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `initialize'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `new'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:213:in `global_hiera_config_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:224:in `global_hiera_config_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/global_data_provider.rb:71:in `configuration_path'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/configured_data_provider.rb:16:in `config'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/global_data_provider.rb:13:in `unchecked_key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/data_provider.rb:41:in `block in key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:90:in `check'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/data_provider.rb:41:in `key_lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:76:in `lookup_global'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `block in global_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:316:in `global_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:325:in `env_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:291:in `block (2 levels) in retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:129:in `with'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:287:in `block in retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:75:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:286:in `retrieve_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:181:in `lookup_lookup_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:166:in `lookup_merge_options'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:58:in `block in lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/invocation.rb:75:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup/lookup_adapter.rb:50:in `lookup'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/lookup.rb:76:in `search_and_merge'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:401:in `block (2 levels) in inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:400:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:400:in `block in inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:396:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:396:in `inject_external_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:363:in `set_resource_parameters'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:171:in `evaluate_code'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:81:in `block in evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:73:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:395:in `each'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:395:in `evaluate_classes'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/loader/../../../puppet/functions/include.rb:16:in `include'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatch.rb:60:in `invoke'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:43:in `block in dispatch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:42:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/dispatcher.rb:42:in `dispatch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:46:in `block in call'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:45:in `catch'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/functions/function.rb:45:in `call'
     # :2:in `block in call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:313:in `eval'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:313:in `block in call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:311:in `call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:941:in `call_function_with_block'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:910:in `eval_CallNamedFunctionExpression'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:69:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # :in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `eval'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:715:in `eval_Program'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:69:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/parser/evaluating_parser.rb:63:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast/pops_bridge.rb:132:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast.rb:31:in `safeevaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:184:in `evaluate_code'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:81:in `block in evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:73:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:635:in `evaluate_main'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block (2 levels) in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/context.rb:65:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet.rb:306:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:162:in `compile'
     # /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera-puppet-helper/puppet.rb:16:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:33:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:268:in `block (2 levels) in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:266:in `block in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util.rb:224:in `block in benchmark'
     # /usr/share/ruby/benchmark.rb:296:in `realtime'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util.rb:223:in `benchmark'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:264:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/catalog/compiler.rb:55:in `find'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/indirector/indirection.rb:194:in `find'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/adapters.rb:83:in `catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/adapters.rb:161:in `catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:354:in `build_catalog_without_cache'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:375:in `block in build_catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/cache.rb:17:in `call'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/cache.rb:17:in `get'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:374:in `build_catalog'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:75:in `block in load_catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:319:in `with_vardir'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:69:in `load_catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/support.rb:10:in `block in subject'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/matchers/create_generic.rb:84:in `call'
     # /usr/local/share/gems/gems/rspec-puppet-2.6.7/lib/rspec-puppet/matchers/create_generic.rb:84:in `matches?'
     # ./spec/classes/init_spec.rb:13:in `block (2 levels) in <top (required)>'

Finished in 0.38469 seconds (files took 1.91 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/classes/init_spec.rb:12 # ssh::sshd_config should contain File[sshdconfig]
rspec ./spec/classes/init_spec.rb:13 # ssh::sshd_config should contain Service[sshd]

/usr/bin/ruby -I/usr/local/share/gems/gems/rspec-core-3.6.0/lib:/usr/local/share/gems/gems/rspec-support-3.6.0/lib /usr/local/share/gems/gems/rspec-core-3.6.0/exe/rspec --pattern spec/\{aliases,classes,defines,unit,functions,hosts,integration,type_aliases,types\}/\*\*/\*_spec.rb --color failed


----------------------------------------------
For puppet apply: I added 3 blank lines to end of /etc/ssh/sshd_config to force an update. 
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

# /opt/puppetlabs/bin/puppet apply --environment sshtesting -tv --noop manifests/init.pp -e "include ssh::sshd_config"
Info: Loading facts
Info: Loading facts
Info: Loading facts
Info: Loading facts
Info: Loading facts
Info: Loading facts

Notice: Compiled catalog for dlistmrfpup02.cbs.ad.cbs.net in environment aspera in 0.16 seconds
Info: Applying configuration version '1503063783'
Notice: /Stage[main]/Ssh::Sshd_config/File[sshdconfig]/content:
--- /etc/ssh/sshd_config        2017-08-18 09:39:43.684192737 -0400
+++ /tmp/puppet-file20170818-1934-9a0w0g        2017-08-18 09:43:03.902131458 -0400
@@ -160,6 +160,3 @@
 #      AllowTcpForwarding no
 #      PermitTTY no
 #      ForceCommand cvs server
-
-
-

Notice: /Stage[main]/Ssh::Sshd_config/File[sshdconfig]/content: current_value {md5}0744515e169813a221830e894399bfb0, should be {md5}568f923999a863de160ae981aa8db81a (noop)
Info: /Stage[main]/Ssh::Sshd_config/File[sshdconfig]: Scheduling refresh of Service[sshd]
Notice: /Stage[main]/Ssh::Sshd_config/Service[sshd]: Would have triggered 'refresh' from 1 events
Notice: Class[Ssh::Sshd_config]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Applied catalog in 0.27 seconds

sshd_config.erb

James Perry

unread,
Aug 18, 2017, 9:49:06 AM8/18/17
to Puppet Developers
    owner   => "root",
    group   => "root",
    mode    => "0600",
    content => template("ssh/sshd_config.erb"),
    before  => Service['sshd'],
  }

  service { "sshd":
    ensure    => running,
    name      => "sshd",
    enable    => true,
    subscribe => File["sshdconfig"],
  }

}


spec/classes/init_spec.rb
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-utils'
require 'hiera-puppet-helper'
require 'spec_helper'
require 'facter'

describe 'ssh::sshd_config' do
     Failure/Error: it { is_expected.to contain_file('sshdconfig') }

     Puppet::PreformattedError:
     Failure/Error: it { is_expected.to contain_service('sshd') }

     Puppet::PreformattedError:
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:313:in `block in call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/runtime3_support.rb:311:in `call_function'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:941:in `call_function_with_block'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:910:in `eval_CallNamedFunctionExpression'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:69:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # :in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `eval'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/puppet_stack.rb:30:in `stack'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:715:in `eval_Program'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/visitor.rb:69:in `visit_this_1'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/pops/parser/evaluating_parser.rb:63:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast/pops_bridge.rb:132:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/ast.rb:31:in `safeevaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/resource/type.rb:184:in `evaluate_code'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:81:in `block in evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/resource.rb:73:in `evaluate'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:635:in `evaluate_main'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block (2 levels) in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/util/profiler.rb:51:in `profile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:174:in `block in compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/context.rb:65:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet.rb:306:in `override'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:162:in `compile'
     # /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera-puppet-helper/puppet.rb:16:in `compile'
     # /usr/local/share/gems/gems/puppet-4.10.4/lib/puppet/parser/compiler.rb:33:in `compile'

----------------------------------------------
sshd_config.erb
Message has been deleted
Message has been deleted

James Perry

unread,
Aug 25, 2017, 9:33:20 AM8/25/17
to Puppet Developers
As an update to this odd issue, I did a puppet module generate to create a fresh directory setup and then copied in the the Puppet code, templates and spec files from the old one. Oddly it had no problems without any code modification that I can find anywhere. The same applies to using the PDK to create the module. 

It is perplexing, but appears beyond my skills to dig into to find the issue. 

Regardless the problem is resolved for that particular module. 
Reply all
Reply to author
Forward
0 new messages