How to add a line to file only if directory exists, else do nothing

What would I use to check if a directory exists for true/false answer without generating an error. I can't use file, because ensure => present or absent with create or remove the directory.

Then use only a true answer to add line to a file with file_line like this:

if ( $answer == true ) { fileline { 'addparameter' : path => '/dir1/config_file', line => "line to append", } edit retag close merge delete Comments 1 is this a directory that you are creating somewhere with puppet, or do you expect it to be pre-existing? If so, create a custom fact. (The real answer is you should manage state with puppet and make it declarative, trying to do other things like that are made hard by the language for a reason) ( 2016-12-02 13:01:08 -0600 )edit you can then use the custom fact (for a specific directory) to either apply or not apply the resource. I strongly encourage you to manage it in a different way ( 2016-12-02 13:02:06 -0600 )edit 1 Answer Sort by » oldest newest most voted you write it as a (shell) script $_l = 'line to append'
$_f = '/dir1/config_file'$_c = @("EOT"/L$) /usr/bin/test -d /dir0/ && \ /bin/grep -q '^${_l}\$'${_f} || \
/bin/echo '${_l}' >>${_f}
|-EOT

exec { 'config_file':
command  => \$_c,
provider => 'shell',
}

more