Ask Your Question
0

File Content NOT Overwriting if File Exists [closed]

asked 2018-11-07 18:41:18 -0600

thawkins gravatar image

updated 2018-11-08 16:36:14 -0600

Using Open-Source Puppet 5.5.6 on CentOS 7

I am specifically trying to manage the outputs.conf for splunk universal forwarder in /opt/splunkforwarder/etc/system/local/outputs.conf

If the file does not exist then my puppet defined content gets pushed on agent run.

However, if the file does exist, it will not replace the content.

This is my manifest:
class splunkforwarder {
    file { '/opt/splunkforwarder/etc/system/local/outputs.conf':
      ensure  => file,
      owner   => 'root',
      group   => 'root',
      mode    => '0600',
      source  => 'puppet:///modules/splunkforwarder/outputs.conf',
      audit   => 'all',
      replace => true
    }
}

The permissions and ownership are able to be changed by puppet and I have tested by varying the values in my manifest, but the content will not change.

----Edit----
To Further Clarify, with this configuration, if I manually edit the outputs.conf file and add anything to it, puppet will not overwrite whatever trash I added to outputs.conf.

My understanding is that by default puppet is supposed to overwrite any manually added changes to a managed file. Is this a bug?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by thawkins
close date 2018-11-09 12:07:26.903465

1 Answer

Sort by » oldest newest most voted
1

answered 2018-11-08 16:06:05 -0600

DarylW gravatar image

updated 2018-11-09 08:44:38 -0600

I believe you are using the replace parameter backwards - it should be 'false'.

https://puppet.com/docs/puppet/5.5/ty...

replace

Whether to replace a file or symlink that already exists on the local system but whose content doesn’t match what the source or content attribute specifies. Setting this to false allows file resources to initialize files without overwriting future changes. Note that this only affects content; Puppet will still manage ownership and permissions. Defaults to true.

Main point of emphasis - Setting this to false allows file resources to initialize files without overwriting future changes

-------- EDIT -------------

The problem is that you are using Audit - I can't find the regular puppet documentation, but from this article ( https://puppet.com/blog/all-about-aud... )

Now instead of changing each value (though you can change it too if you wish) Puppet will instead generate auditing log messages, which are available in your standard Puppet reports:

audit mode makes it 'audit' changes instead of enforcing changes - In theory, if you have audit mode off, you will still 'log' every change, because puppet will be 'putting it back', with audit mode, it means 'leave it, but tell me about its differences'

edit flag offensive delete link more

Comments

Why would I want that to be set to false? I WANT puppet to replace the file content, but it doesn't. I only added 'replace => true' to ensure that the value was in fact set to true.

thawkins gravatar imagethawkins ( 2018-11-08 16:11:51 -0600 )edit

Oh, I thought you were trying to do the opposite - initially manage it but not manage it after manual / application based changes happened to the file

DarylW gravatar imageDarylW ( 2018-11-09 08:32:04 -0600 )edit

See edit above...

DarylW gravatar imageDarylW ( 2018-11-09 08:44:29 -0600 )edit

That actually makes total sense, I'll update this after testing to confirm that works. Thanks DarylW.

thawkins gravatar imagethawkins ( 2018-11-09 11:08:01 -0600 )edit

Removing the audit line totally worked, thanks again DarylW.

thawkins gravatar imagethawkins ( 2018-11-09 12:06:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-07 18:41:18 -0600

Seen: 30 times

Last updated: Nov 09