file absent in config manifest fails

36 views
Skip to first unread message

Tim Dunphy

unread,
Oct 14, 2015, 10:14:30 PM10/14/15
to puppet...@googlegroups.com
Hey guys,

 On puppet server 3.8.2 here. And I have a file definition that I want to set as 'absent'. For example, this is what I have:

  file { '/etc/newrelic/newrelic.cfg':
    ensure  => absent,
    path    => '/etc/newrelic/newrelic.cfg',
    content => template('newrelic/newrelic.cfg.erb'),
    before  => Service[$newrelic_php_service],
    notify  => Service[$newrelic_php_service],
  }

And if I remove the file I want on the target host:

[root@ops3:~] #rm -fv /etc/newrelic/newrelic.cfg
removed ‘/etc/newrelic/newrelic.cfg’

And then run the puppet agent again:

[root@ops3:~] #puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Could not retrieve fact='nr_java_found', resolution='<anonymous>': undefined method `start_with?' for nil:NilClass
Info: Caching catalog for ops3.jokefire.com
Info: Applying configuration version '1444874991'
Notice: /Stage[main]/Newrelic::Agent::Php/File[/etc/newrelic/newrelic.cfg]/ensure: created
Info: /Stage[main]/Newrelic::Agent::Php/File[/etc/newrelic/newrelic.cfg]: Scheduling refresh of Service[newrelic-daemon]
Notice: /Stage[main]/Newrelic::Agent::Php/Service[newrelic-daemon]: Triggered 'refresh' from 1 events
Notice: /Stage[main]/Mcollective::Service/Service[mcollective]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Mcollective::Service/Service[mcollective]: Unscheduling refresh on Service[mcollective]
Notice: /Stage[main]/Apache::Service/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Apache::Service/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: /Stage[main]/Puppet::Service/Service[puppet]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Puppet::Service/Service[puppet]: Unscheduling refresh on Service[puppet]
Notice: Finished catalog run in 7.17 seconds

Notice the newrelic.cfg file that I want to be 'absent' is created nontheless. 

Is this some kind of flaw in the version of puppet I'm using? Or could I be doing something wrong?

Because this is not at all the way I understand the 'absent' value of the ensure setting is supposed to work!

I guess in the meantime I can comment out the file definition entirely. But I would like to understand why the 'absent' setting isn't working the way it's supposed to!

Thanks,
Tim

--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Peter Bukowinski

unread,
Oct 14, 2015, 10:24:27 PM10/14/15
to puppet...@googlegroups.com
Tim,

On Oct 14, 2015, at 10:14 PM, Tim Dunphy <bluet...@gmail.com> wrote:

Hey guys,

 On puppet server 3.8.2 here. And I have a file definition that I want to set as 'absent'. For example, this is what I have:

  file { '/etc/newrelic/newrelic.cfg':
    ensure  => absent,
    path    => '/etc/newrelic/newrelic.cfg',
    content => template('newrelic/newrelic.cfg.erb'),
    before  => Service[$newrelic_php_service],
    notify  => Service[$newrelic_php_service],
  }

If you specify 'ensure => absent' then you should not have a 'content' line. They are contradictory parameters. (Also, but unrelated, the path parameter is duplicative since specifying the path as the file resource name serves the same purpose.)

Tim Dunphy

unread,
Oct 14, 2015, 11:56:06 PM10/14/15
to puppet...@googlegroups.com
If you specify 'ensure => absent' then you should not have a 'content' line. They are contradictory parameters. (Also, but unrelated, the path parameter is duplicative since specifying the path as the file resource name serves the same purpose.)

Ok! Gothca. Actually not to deflect blame, but I didn't author this manifest. I downloaded it from puppet forge for the newrelic module. 

But the real problem I found out was that they duplicated the file definition in two separate manifests. It was listed in:

Class: newrelic::php
environments/production/modules/newrelic/manifests/php.pp

And 

Class: newrelic::agent::php
environments/production/modules/newrelic/manifests/agent/php.pp

Not sure how they did that and got away with it, since I thought you could only define a resource once in a module. 

But making the file absent by doing this in both files:

$newrelic_daemon_cfgfile_ensure                        = 'absent',

  file { '/etc/newrelic/newrelic.cfg':
    ensure  => $newrelic_daemon_cfgfile_ensure,
    path    => '/etc/newrelic/newrelic.cfg',
    content => template('newrelic/newrelic.cfg.erb'),
    before  => Service[$newrelic_php_service],
    notify  => Service[$newrelic_php_service],
  }

Is what worked. Also, I may go ahead and change the manifests per your advice, but that's more of a style issue than a functional one I think.

Thanks!!
Tim

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/266E9C53-C845-474F-B3AD-54CA5D3D86B1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

David Schmitt

unread,
Oct 16, 2015, 8:56:28 AM10/16/15
to puppet...@googlegroups.com


On 15/10/2015 04:55, Tim Dunphy wrote:
If you specify 'ensure => absent' then you should not have a 'content' line. They are contradictory parameters. (Also, but unrelated, the path parameter is duplicative since specifying the path as the file resource name serves the same purpose.)

Ok! Gothca. Actually not to deflect blame, but I didn't author this manifest. I downloaded it from puppet forge for the newrelic module.

(also, ensure will override content any time of the day)


But the real problem I found out was that they duplicated the file definition in two separate manifests. It was listed in:

Class: newrelic::php
environments/production/modules/newrelic/manifests/php.pp

And 

Class: newrelic::agent::php
environments/production/modules/newrelic/manifests/agent/php.pp

Not sure how they did that and got away with it, since I thought you could only define a resource once in a module. 

... in a catalog. The module is just source code on the master which can contain as many "conflicting" resource definitions as it wants. The important thing is that only unique resources are then sent to the agent. I don't know the newrelic module, but from the class names I'd assume, only one of them is included on your node.


Cheers, D.

Tim Dunphy

unread,
Oct 16, 2015, 9:34:21 AM10/16/15
to puppet...@googlegroups.com
... in a catalog. The module is just source code on the master which can contain as many "conflicting" resource definitions as it wants. The important thing is that only unique resources are then sent to the agent. I don't know the newrelic module, but from the class names I'd assume, only one of them is included on your node.

Hi David, 

Ah, ok! That sounds right. So as long as the resource that is sent to the agent is unique, you're good. Thanks for the clarification! 

Thanks
Tim

--
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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages