chef-recipe

File delete action if condition exists


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

Solution

  • file '/path/foo' do
      action :delete
      only_if { File.exist? '/path/foo' }
    end