Override cronjob command

324 views
Skip to first unread message

Rufus McDufus

unread,
Jun 1, 2012, 6:34:21 AM6/1/12
to puppet...@googlegroups.com
Hi folks - I'm trying what should be a simple task but I'm having a case of brain fade!  In puppet enterprise in the pe_compliance module, a cronjob gets added by class pe_compliance::agent:

% cat /opt/puppet/share/puppet/modules/pe_compliance/manifests/agent.pp
class pe_compliance::agent {
  cron { 'report_baseline':
    command     => 'PATH=/opt/puppet/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin /opt/puppet/bin/puppet inspect',
    hour        => '20',
    minute      => '0',
  }
}

I want to modify this cronjob to redirect stdout to /dev/null but I don't want to edit this file directly as I don't want to modify core modules. Everything I try to try and override results in a duplicate definition of Pe_compliance::agent or 'Only subclasses can override parameters'.  For instance if I try:

  class pe_compliance::agent::cronmodify inherits ::pe_compliance::agent {
    Cron['report_baseline'] {
      command => 'PATH=/opt/puppet/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin /opt/puppet/bin/puppet inspect >/dev/null'
    }
  }
  include pe_compliance::agent::cronmodify

I get:
 Error 400 on SERVER: Duplicate declaration: Class[Pe_compliance::Agent] is already declared; cannot redeclare at /opt/puppet/share/puppet/modules/pe_compliance/manifests/init.pp:15


Is there an easy way of overriding this parameter?

Thanks,

jcbollinger

unread,
Jun 1, 2012, 10:09:15 AM6/1/12
to Puppet Users
What you wrote above looks like it ought to work. Perhaps Puppet is
handling the "::pe_compliance::agent" inconsistently. Does it work if
instead you write

class pe_compliance::agent::cronmodify inherits pe_compliance::agent {
[...]

?

If it does, then I'm sure Puppetlabs would appreciate an official bug
report. Given that Puppet accepts "inherits ::pe_compliance::agent"
in the first place, it should recognize that it refers to the same
class as "pe_compliance::agent", and therefore engage its machinery
that allows super- and subclasses to both be declared on the same
node.


John

Rufus McDufus

unread,
Jun 1, 2012, 10:43:56 AM6/1/12
to puppet...@googlegroups.com
OK, I'm officially going crazy! I cut and paste the code I put in my first post - everything works perfectly now...

I have done some pretty major code re-organisation so it's likely I may have fixed something along the way which caused spurious problems. I can't reproduce it any more :(

Thanks for your help though!

Rufus McDufus

unread,
Jun 1, 2012, 11:12:06 AM6/1/12
to puppet...@googlegroups.com
Urr, I spoke too soon. It's working on some servers, not others. For instance on another I get:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Class[Pe_compliance::Agent] is already declared; cannot redeclare at /opt/puppet/share/puppet/modules/pe_compliance/manifests/init.pp:15 on node blah

I've re-built the server to try and eliminate any catalog caching issues (not that I've ever seen any), no luck.

jcbollinger

unread,
Jun 1, 2012, 12:43:18 PM6/1/12
to Puppet Users


On Jun 1, 10:12 am, Rufus McDufus <r...@bamalam.com> wrote:
> Urr, I spoke too soon. It's working on some servers, not others. For
> instance on another I get:
>
> err: Could not retrieve catalog from remote server: Error 400 on SERVER:
> Duplicate declaration: Class[Pe_compliance::Agent] is already declared;
> cannot redeclare at
> /opt/puppet/share/puppet/modules/pe_compliance/manifests/init.pp:15 on node
> blah


When you say it's working "on some servers" do you mean "on some
puppetmasters" (as in, you have multiple masters) or do you mean "for
some (Puppet) clients"?

Either way, it appears to be an issue with the master, not with the
agents. Did you try the modification I suggested?


> I've re-built the server to try and eliminate any catalog caching issues
> (not that I've ever seen any), no luck.


Puppet does not cache failed catalogs, so caching could not explain
the failures. Perhaps it could explain the successes, though.


John

Rufus McDufus

unread,
Jun 1, 2012, 1:45:36 PM6/1/12
to puppet...@googlegroups.com
Hi John - apolologies, I meant it works on some clients and not others. I did try your suggestion.
I've recently converted my site module to one with a lot more class inheritance so find I need to default to objects with fully-qualified namespace, but yes it still fails if the namespace isn't fully qualified.

Nan Liu

unread,
Jun 1, 2012, 2:27:19 PM6/1/12
to puppet...@googlegroups.com
You can't override this using inheritance because the class already
been declared in init.pp:

class { "pe_compliance::agent":
require => Anchor['pe_compliance::begin'],
before => Anchor['pe_compliance::end'],
}

I don't know the reason why parametrized class was used because
there's really no variables in the agent. One of things you can try is
to replace the module with your own since it's really just one
resource since I don't see any other pe-* module depending on it at
the moment. If there is dependency I missed, you can try copying the
existing module from /opt/puppet/share/puppet/modules/pe_compliance to
/etc/puppetlabs/puppet/modules/pe_compliance and customize the copy in
/etc/puppetlabs/modules.

Thanks,

Nan

Matthaus Litteken

unread,
Jun 1, 2012, 3:11:25 PM6/1/12
to puppet...@googlegroups.com
Rufus,

I've opened a ticket for your issue at
https://projects.puppetlabs.com/issues/14781, where you can track its
progress. Cron jobs generally shouldn't be producing output after a
successful run, so thanks for bringing this up so it can get
addressed.

-matthaus
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/QwmBqirdujsJ.
>
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.



--
Matthaus Litteken
Release Manager, Puppet Labs

Rufus McDufus

unread,
Jun 1, 2012, 3:31:32 PM6/1/12
to puppet...@googlegroups.com
Thanks Matthaus - that's a great solution for me!

Nan - I quite agree, but the strange thing is it's working perfectly on some nodes, not others and I can't figure any difference between them.  I guess there must be - but where I don't know!


Rob.


On Friday, 1 June 2012 20:11:25 UTC+1, Matthaus Litteken wrote:
Rufus,

I've opened a ticket for your issue at
https://projects.puppetlabs.com/issues/14781, where you can track its
progress. Cron jobs generally shouldn't be producing output after a
successful run, so thanks for bringing this up so it can get
addressed.

-matthaus


> puppet-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages