In puppet, you can chown/chmod a single file by doing:
file {
'/var/log/mylog/test.log':
ensure => 'present',
mode => '0644',
owner => 'me';
}
Two questions on this:
-
ensure=>’present’ is gonna make sure ‘/var/log/mylog/test.log’ exists, if it doesn’t it creates it. Is there any way I can make it do actions if file exists, if file doesn’t exist, don’t bother to create/delete it, just ignore it and carry on.
-
Let’s say I have 3 files under /var/log/mylog/, I want to chown/chmod against them all in a batch instead of having 3 file resource sections in my puppet code. Can I do something like below(of coz, the code below doesn’t exist, it’s in my dream now ^_^ ):
files { '/var/log/mylog/*.log': ensure => 'present', mode => '0644', owner => 'me'; }
If you want to specify to take a given action if file exists, if file doesn’t exist etc. you have no choice (to my knownledge) currently than to use the
execresource withcreates+onlyiforunlessdirectives.You could use for instance (see reference doc)
No. Again, you’ll have to use an
execresource.