Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:27:06+00:00 2026-06-05T18:27:06+00:00

In puppet, you can chown/chmod a single file by doing: file { ‘/var/log/mylog/test.log’: ensure

  • 0

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:

  1. 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.

  2. 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';
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:27:09+00:00Added an answer on June 5, 2026 at 6:27 pm
    1. 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 exec resource with creates + onlyif or unless directives.
      You could use for instance (see reference doc)

       exec { "touch /var/log/mylog/test.log":
          path    => "/usr/bin:/usr/sbin:/bin",
          user    => "${yourmodule::params::user}",
          group   => "${yourmodule::params::group}",
          creates => "/var/log/mylog/test.log", 
          unless  => "test -f /var/log/mylog/test.log"
       }
      
       file { '/var/log/mylog/test.log':
          ensure  => 'present',
          mode    => "${${yourmodule::params::mode}",
          owner   => "${yourmodule::params::user}",
          group   => "${yourmodule::params::group}",
          require => Exec["touch /var/log/mylog/test.log"]    
       }
      
    2. No. Again, you’ll have to use an execresource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple .pp / puppet file, and I'm getting Parameter provider failed:
Basically I deleted these files while doing some clean up in my puppet directory.
I am using Puppet for automating configuration management across hosts. It can use erb
How can we write a puppet manifest code that identifies whether a service(httpd) is
I'm using puppet and want to test it with noop, but some configuration depends
I have following manifest: define foo($var) { file { $var: } $barclass::store += $var
I'm doing my first steps in Puppet and ran into a problem. I've installed
I'm running Puppet 2.7.14 on RHEL 6.2 (both master and nodes have this configuration).
Is it possible to do a string substitution/transformation in Puppet using a regular expression?
I'm in the process of setting up mongodb, and we use puppet to control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.