Re: [Puppet Users] Data Type: Hashes

2015-11-27 Thread Henrik Lindberg

On 2015-25-11 1:35, Matthew Ceroni wrote:

I am having an issue accessing elements of a hash.

First, it is defined in hiera as such:

lb::rules:
   VCC: rule1
   GR: rule2

I retrieve the value using

$lb_rules = hiera('lb::rules')

Then I simply try to print out one of the values
ex:

  notify { "$lb_rules[VCC]": }



To interpolate the [] expression you must write
"${lb_rules['VLC']}"

Otherwise the [] part becomes text. You must quote the uppercase bare 
word or it will be interpreted as the name of a type (like Integer, or 
File).


Since you ended up with the [] part in your title, and because puppet to 
bat crazy stuff with titles containing them (in some versions of 
puppet), you end up with the error you got.


Hope that helps.

- henrik


But get

Error 400 on SERVER: Evaluation Error: Missing title. The title
expression resulted in undef at
/etc/puppet/environments/sandbox/manifests/site.pp:14:11

If I don't specify a key and instead do

notify { "$lb_rules": }

I get

Error 400 on SERVER: Evaluation Error: Illegal title type at index 0.
Expected String, got Hash[String, String]

Confirming that lb_rules is a hash.




--
You received this message because you are subscribed to the Google
Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to puppet-users+unsubscr...@googlegroups.com
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/CA%2BNsY5jkQAEyamw7yauG2FWA6ktqeWGOVRZBCKaS_pW%2BYqS0OQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.



--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/n3a091%24ff4%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Still mud-wrestling with spec testing

2015-11-27 Thread Peter Berghold
So,

Now that my schedule has some slack in it I've turned my attention back to
doing spec testing of my Puppet modules.  Taking a really really simple
module that I wrote as an example I started in again.

Here is the one and only file making up the class.

-- init.pp --
class ntp {

  package { 'ntp':
ensure => latest
  }
  service { 'ntp':
ensure  => running,
enable  => true,
require => Package[ntp]
  }


}
-

That should be really easy to run tests against in my opinion.  I wrote a
Gemfle for the occasion.

-Gemfile---
source 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" :
['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'
gem 'facter', '>= 1.7.0'
gem 'rake','>= 0.0.0'
gem 'spec','>= 0.0.0'

and my spec file looks like this:

--- spec/classes/init_spec.rb ---
require 'spec_helper'
describe 'ntp', :type => 'class' do

  context 'On Debian' do
let :facts do {
 :osfamily => 'Debian'
}
end

  it {
should contain_package('ntp').with({ 'name' =>  'ntp' })
should contain_service('ntp').with({ 'name' => 'ntp' })
  }
end

end
---

and when I run "rake spec" I get this (severely trimmed) set of errors:
-errors--
 1) ntp On Debian should contain Package[ntp] with name => "ntp"
 Failure/Error: should contain_package('ntp').with({ 'name' =>  'ntp' })

 ArgumentError:
   wrong number of arguments (2 for 1)


Looks to me after reading "The Next Generation of Puppet Module Testing"
 at this page:
https://puppetlabs.com/blog/the-next-generation-of-puppet-module-testing
there should only be one argument to  "with" so.. if that's not an
authoritative page for that information, which one is?

Can somebody clarify for me what;s going on here?

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAArvnv0%3DEobRO49%3DhYNuf6D2e2feN4md2rFqmx%2BGySCNByhtCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.