Ask Your Question
1

How to unset a fact in an inherited class?

asked 2014-05-19 12:40:01 -0500

Joseph Carlos gravatar image

I have a class that sets a few facts:

class my_service {
  fact {
    'sysadmin0': value => 'alice';
    'sysadmin1': value => 'bob';
    'sysadmin2': value => 'charles';
  }
  ...
}

I would like to have an inherited class that only sets the first of those facts:

class my_service::test inherits my_service {
  # Be sure that sysadmin1 and sysadmin2 are NOT defined:
  Fact['sysadmin0'] {value => 'diane' }
  Fact['sysadmin1'] {value => undef }
  Fact['sysadmin2'] {value => undef }
  ...
}

However, this generates the error Error 400 on SERVER: No value provided for sysadmin1 fact. How can I get those other two facts undefined on the inherited class?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-05-19 16:43:48 -0500

spuder gravatar image

Rather than hard coding the users inside the class, I would suggest using parameterized classes. The apache module is a great example of how to do this (see ghosts)

define my_service::test( $user => undef ) {

}

Then call the subclass for each user

my_service::test { 'alice':
  user => 'alice'
}
my_service::test { 'bob':
  user => 'bob',
}

You don't even really need to use the user, since the name can be the variable.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-05-19 12:40:01 -0500

Seen: 54 times

Last updated: May 19 '14