How to check if folder has any content in puppet

ycr

What I want to do is check whether a folder has any content before copying the content in the folder, since puppet is throwing an error if you are trying to copy content of a empty folder. This is what I have tried but it doesn't work :(

exec { "Copying_patches_$setupnode-$number":

      path    => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', 
      command => "cp -r ${params::script_base_dir}/libs/patches/* ${params::deployment_target}/$setup/repository/patches/",
      onlyif => "test -f ${params::script_base_dir}/libs/patches/*",
      notify          => Notify['${params::script_base_dir}/libs/patches/*  found'],
      require => File["${params::deployment_target}/$setupnode"],

    }

params::script_base_dir will give the path up to the script location.

Felix Frank

Try this approach:

package { 'rsync': ensure => 'installed' }

$from = "${params::script_base_dir}/libs/patches/"
$to   = "${params::deployment_target}/$setup/repository/patches/"

file { "$from/.sync_marker": ensure => file }

exec { "Copying_patches_$setupnode-$number":
  path    => '/usr/bin:/bin', 
  command => "rsync -r $from $to",
  require => [
    File["${params::deployment_target}/$setupnode"],
    Package['rsync'],
    File["$from/.sync_marker"],
  ],
  creates => "$to/.sync_marker",
}

Some remarks:

  1. I shortened your path - no need for java or things in /sbin
  2. Notifying a notify resource is usually no sensible - those always produce their message
  3. The trailing slash on the target does not matter to rsync, but the one on the sources does!
  4. The file in the source directory is created, just to make it possible to build a simple creates clause

The creates parameter makes sure that the command is run only once, and not during every run.

If you need Puppet to wait until the source directory is populated, you do have to use onlyif. Try this condition:

onlyif => "find $from | wc -l | grep -v '^2\$'",

The two lines of output would represent the directory itself and the marker file. The $ sign is escaped so that Puppet includes it in the command string literally.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery: How to check if the content has any URLs

From Dev

How to check if the page has content?

From Dev

How to check content of zip folder before uploading?

From Dev

How do I check if a folder has contents?

From Dev

Check if a git repository has any content that is not present in a remote

From Dev

How to check if json array has any value?

From Dev

How to check if any attribute has changed on a model

From Dev

How to check if any attribute has changed on a model

From Dev

How to check if a batch file has ANY parameters?

From Dev

How to check if json array has any value?

From Dev

How to check if XElement has any child nodes?

From Dev

How to check to see if wordpress shortcode has $content

From Dev

How to check if a directory exists in puppet

From Dev

Check if DataInputStream has content

From Dev

How to check if a folder is empty or not and use its content in an if-then-else-statement?

From Dev

How to check if a folder has more than 20 files in it in batch?

From Dev

OS X Applescript check how long file has been in folder

From Dev

Check if there are any empty files in a folder

From Dev

XSLT how to check if the current node has any attribute or not

From Dev

How to check if a table has any duplicated rows column in js?

From Dev

How to check if any span element in inside div has empty value

From Dev

How to check if a woocommerce product has any category assigned to it?

From Dev

How to check if a file has an extension (any extension) with regular expression in Bash?

From Dev

How to check if a channel has any messages? Discord.py

From Dev

How to check if C++ source has any system/shell calls in it?

From Dev

How to check if any span element in inside div has empty value

From Dev

How to check from command line if audio file has any sound

From Dev

How to check if wpa_supplicant.conf has any syntax errors?

From Dev

How to check if TarArchiveEntry has any of the 3 execute bits set?

Related Related

  1. 1

    jQuery: How to check if the content has any URLs

  2. 2

    How to check if the page has content?

  3. 3

    How to check content of zip folder before uploading?

  4. 4

    How do I check if a folder has contents?

  5. 5

    Check if a git repository has any content that is not present in a remote

  6. 6

    How to check if json array has any value?

  7. 7

    How to check if any attribute has changed on a model

  8. 8

    How to check if any attribute has changed on a model

  9. 9

    How to check if a batch file has ANY parameters?

  10. 10

    How to check if json array has any value?

  11. 11

    How to check if XElement has any child nodes?

  12. 12

    How to check to see if wordpress shortcode has $content

  13. 13

    How to check if a directory exists in puppet

  14. 14

    Check if DataInputStream has content

  15. 15

    How to check if a folder is empty or not and use its content in an if-then-else-statement?

  16. 16

    How to check if a folder has more than 20 files in it in batch?

  17. 17

    OS X Applescript check how long file has been in folder

  18. 18

    Check if there are any empty files in a folder

  19. 19

    XSLT how to check if the current node has any attribute or not

  20. 20

    How to check if a table has any duplicated rows column in js?

  21. 21

    How to check if any span element in inside div has empty value

  22. 22

    How to check if a woocommerce product has any category assigned to it?

  23. 23

    How to check if a file has an extension (any extension) with regular expression in Bash?

  24. 24

    How to check if a channel has any messages? Discord.py

  25. 25

    How to check if C++ source has any system/shell calls in it?

  26. 26

    How to check if any span element in inside div has empty value

  27. 27

    How to check from command line if audio file has any sound

  28. 28

    How to check if wpa_supplicant.conf has any syntax errors?

  29. 29

    How to check if TarArchiveEntry has any of the 3 execute bits set?

HotTag

Archive