Ask Your Question

Overwrite file if it exists or create file if it does not

asked 2013-07-15 06:25:29 -0600

michael1wright gravatar image

updated 2013-07-15 08:54:39 -0600

Ancillas gravatar image


I am trying to rewrite a file using puppet with the following function.

If the file exists I still want the file to be rewrite from the source. Will this be achieved with the following method?

define setup_sysctl_conf( $dependence=File[$dummy_dependence_file] )
    file { $name:
     path    => '/etc/sysctl.conf',
     ensure  => present,
     mode    => 0777,
     source  => '/vagrant/files/sysctl.conf',
     require => $dependence, 

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-07-15 09:23:55 -0600

Ancillas gravatar image

updated 2013-07-17 09:48:56 -0600

I want to make sure I understand you correctly. If /etc/sysctl.conf does not exist, you want to create it. If /etc/sysctl.conf does exist, you want to rewrite the content to match your source. Is that correct?

If so, then you can re-write your requirements to be, "make /etc/sysctl.conf match my source."

file { '/etc/sysctl.conf':
  ensure  => present,
  owner   => 'root',
  group   => 'root',
  mode    => '0777',
  source  => 'puppet:///vagrant/files/sysctl.conf',

You need to make sure your file source is configured in fileserver.conf as a mount point, or located in a module.

See the http ... (more)

edit flag offensive delete link more


what is the difference apart from the source 'puppet//'. Does the 'puppet//' not mean the file has to be on a puppet node?

michael1wright gravatar imagemichael1wright ( 2013-07-16 04:22:07 -0600 )edit

The puppet master can only source files that exist on the puppet master itself. Further, the files that are being sources either have to be in a module, or in ...(more)

Ancillas gravatar imageAncillas ( 2013-07-16 12:42:14 -0600 )edit

I re-added a link above, but Askbot isn't parsing the text correctly. It looked fine in the preview :/.

Ancillas gravatar imageAncillas ( 2013-07-17 09:49:44 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2013-07-15 06:25:29 -0600

Seen: 13,507 times

Last updated: Jul 17 '13