Ask Your Question

Revision history [back]

First off, replace hiera() with new lookup() function as hiera() function has been deprecated.

I highly recommend reading how to set up hiera in modules

Your class should look more like

class foo (
) {

  if $enable_bar {
    $_state = running
    $_run_at_boot = true
  } else {
    $_state = stopped
    $_run_at_boot = false

  service { 'bar':
    ensure => $_state,
    enable => $_run_at_boot,



foo::enable_bar: true

In your test, you should no longer need the hiera stuff, but you will need to stub out the enable_bar param for the 'disabled' test

  context 'test case for bar in disabled state' do
    let(:facts) { :operatingsystemmajrelease => '7', :osfamily => 'RedHat' }
    let(:param) { enable_bar: false }

    it { contain_service('bar').with(
        ensure: 'stopped',
        enable: 'false',

Hope that all makes sense