Hi,
how can I create a condition based on the presence of a specific puppet 
class on the host?

I'm using Foreman, some hosts have myclass_a applied, while others have 
myclass_a AND myclass_b.
Resources in myclass_b are applied after resources in myclass_a.

Both classes change a parameter inside a configuration file, using augeas. 
But this causes two changes in the file on each puppet run (from state b to 
a, and then from state a to b again).

So I'm trying to do something like this, to prevent myclass_a from applying 
the modification if also myclass_b is present:

class myname::myclass_a {

  if defined("myname::myclass_b") {
    $confchanges = [
                     'set anotherpath_b anothervalue_b', # if class B is 
present, I only apply my specific edits
                    ]
  }
  else {
    $confchanges = [
                     'set anotherpath_b anothervalue_b',
                     'set mypath myvalue_a', # if class B is absent, I also 
apply the conflicting edit
                    ]
  }

  augeas { 'myconffile_a':
    lens    => 'Puppet.lns',
    incl    => '/etc/myconf.conf',
    changes => $confchanges,
  }

}

class myname::myclass_b {

  augeas { 'myconffile_b':
    lens    => 'Puppet.lns',
    incl    => '/etc/myconf.conf',
    changes => 'set mypath myvalue_b',
  }

}

...but this does not work, it never gets to the "else" section. Probably 
because the "defined" function is evaluated on the puppet master, where the 
class always exists.

I cannot use a condition on the existence of the "myconffile_b" resource, 
because this is parse order dependent and would always return false when 
evaluated inside myclass_a.

Any suggestions?
I'm looking into alternatives like virtual resources or defined types, but 
I cannot see anything better suited at the moment.

Thanks.
Marco

-- 
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/6d3c91d0-f70a-45dc-8dfe-d9309570425c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to