Search code examples
puppet

Puppet existing directory to bool


is it possible to use a function, which checks if the given directory/file exists and assigns the boolean return value to a variable?

I want to execute a part of my manifest only if a file/directory doesn't exist.

Greetings


Solution

  • You will have to create a custom fact to get that piece of information from the agent to your master. The easiest way to do this is an external fact. On Linux, this scriptlet would suffice.

    #!/bin/sh
    
    [ -d /the/directory/in/question ] || exit 0
    
    echo 'my_directory=present'
    

    You can then use the $my_directory fact in your manifests. It's missing if the directory is not yet there, and otherwise has the value 'present'.