Re: [Puppet Users] Creation of modifiable files via puppet

119 views
Skip to first unread message

Peter Brown

unread,
Oct 9, 2012, 1:26:58 AM10/9/12
to puppet...@googlegroups.com
Hi,

The best way to do that is to modify the system skeleton files and
make sure useradd is using them.
They get put in user homedirs when the account gets created.

On 9 October 2012 15:19, pdurkin <pdur...@gmail.com> wrote:
> I've been looking around but can't seem to find an answer to this.
>
> I would like to create a file whose initial contents come from the default
> in the puppet server but is subsequently modifiable and puppet won't
> overwrite any changes.
>
> The reason for this is that if I deploy a user account via puppet and upload
> a default .bashrc/.profile, the user should be able to modify these without
> having puppet change them back to the originals every time it runs.
>
> Thanks
>
> Paul
>
> --
> 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/-/MNccQWibusoJ.
> 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.

pdurkin

unread,
Oct 9, 2012, 1:54:04 AM10/9/12
to puppet...@googlegroups.com
Thanks, that solves the problem I posted however there were several situations where I would like to be able to upload a file and after that not care about it.

Another example I was wrestling with was uploading a tar.gz then allowing it to be removed afterwards.  I want it uploaded so that I can deploy the contents but once it's there I would like puppet (or some admin) to clean it up later.

Is it possible then I should be running an exec to copy the file from the server and use the unless (file exists already)?

thanks

Paul

Peter Brown

unread,
Oct 9, 2012, 2:16:23 AM10/9/12
to puppet...@googlegroups.com
On 9 October 2012 15:54, pdurkin <pdur...@gmail.com> wrote:
> Thanks, that solves the problem I posted however there were several
> situations where I would like to be able to upload a file and after that not
> care about it.
>
> Another example I was wrestling with was uploading a tar.gz then allowing it
> to be removed afterwards. I want it uploaded so that I can deploy the
> contents but once it's there I would like puppet (or some admin) to clean it
> up later.

If there are system config file in those archives it would be better
to manage them with puppet.
If you are deploying applications I find it's better to use git or svn
to manage the code for the application because you get versioning and
rollback options.

> Is it possible then I should be running an exec to copy the file from the
> server and use the unless (file exists already)?

Why can't you just manage the file with the file resource?
I am pretty sure there is an option that won't overwrite a file if it exists.
Please read the docs for the file resource to confirm.
> https://groups.google.com/d/msg/puppet-users/-/R-X_u_Jk4zgJ.

Paul Tötterman

unread,
Oct 9, 2012, 2:26:44 AM10/9/12
to puppet...@googlegroups.com
> Is it possible then I should be running an exec to copy the file from the server and use the unless (file exists already)?

exec { 'foobar':
  command => '/usr/bin/wget https://... -O /file/location',
  creates => '/file/location',
}

Cheers,
Paul

Peter Brown

unread,
Oct 9, 2012, 2:33:34 AM10/9/12
to puppet...@googlegroups.com
This is not really the best way to manage a file in puppet.

>
> Cheers,
> Paul
>
> --
> 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/-/8eoG3rgnbIcJ.

David Schmitt

unread,
Oct 9, 2012, 3:30:00 AM10/9/12
to puppet...@googlegroups.com
Use file's replace => false parameter.

See http://docs.puppetlabs.com/references/latest/type.html#file


Fun, D.

On 09.10.2012 07:19, pdurkin wrote:
> I've been looking around but can't seem to find an answer to this.
>
> I would like to create a file whose initial contents come from the
> default in the puppet server but is subsequently modifiable and puppet
> won't overwrite any changes.
>
> The reason for this is that if I deploy a user account via puppet and
> upload a default .bashrc/.profile, the user should be able to modify
> these without having puppet change them back to the originals every time
> it runs.
>
> Thanks
>
> Paul
>
> --
> 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/-/MNccQWibusoJ.

Mason Turner

unread,
Oct 9, 2012, 6:53:11 AM10/9/12
to puppet...@googlegroups.com, puppet...@googlegroups.com
That is the intent of "ensure => present". If the file isn't there, puppet will create it with the source/content parameter. If it is there (exists), puppet will leave it alone.

jcbollinger

unread,
Oct 9, 2012, 9:10:24 AM10/9/12
to puppet...@googlegroups.com


On Tuesday, October 9, 2012 12:19:20 AM UTC-5, pdurkin wrote:
I've been looking around but can't seem to find an answer to this.

I would like to create a file whose initial contents come from the default in the puppet server but is subsequently modifiable and puppet won't overwrite any changes.


This is exactly what the File resource type's 'replace' parameter is for.

file { '/etc/foo.conf'':
  ensure => 'file',
  source => 'puppet:///mymodule/foo.conf',
  replace => false
}

That will install the file (as a copy from the specified source, in the above example) if it does not already exist, but it will not modify an existing file.


John

pdurkin

unread,
Oct 10, 2012, 2:32:17 AM10/10/12
to puppet...@googlegroups.com
Thanks for all the help, the two solutions + using them both together will solve all the situations I'm considering.

Paul


On Tuesday, October 9, 2012 9:19:20 AM UTC+4, pdurkin wrote:
I've been looking around but can't seem to find an answer to this.

I would like to create a file whose initial contents come from the default in the puppet server but is subsequently modifiable and puppet won't overwrite any changes.

Reply all
Reply to author
Forward
0 new messages