Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File delete action if condition exists

Tags:

chef-recipe

New to chef recipe and google is not showing me an example of what I need to do.

I have a file that I want deleted when chef finds it exists.

I am not finding any google examples of something like

file /path/foo do
action delete
end if /path/foo exists

and the chef file documentation is not showing anything like file /path/foo do condition exists action delete end

Is the only way to use a script like bash?

bash 'delete_foo' do
    if [ -f /path/foo ] then
       /bin/rm /path/foo
    fi
end
like image 365
peter cooke Avatar asked Dec 09 '22 00:12

peter cooke


1 Answers

file '/path/foo' do
  action :delete
  only_if { File.exist? '/path/foo' }
end
like image 69
display name Avatar answered Mar 12 '23 00:03

display name