File delete action if condition exists
Asked Answered
F

2

6

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
Fizzle answered 25/1, 2016 at 20:31 Comment(0)
R
15
file '/path/foo' do
  action :delete
  only_if { File.exist? '/path/foo' }
end
Remy answered 25/1, 2016 at 20:35 Comment(0)
S
0

It will delete file only if it exists and do nothing otherwise

file '/path/foo' do
  action :delete
end
Stellular answered 1/3, 2023 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.