How do I manage stranded resources in Chef

0 votes

Is there a clean way to manage stranded resources through cookbook modifications? For instance, let's say I have a recipe resource that writes a file from a template like so:

template 'C:\dir\somefile.txt' do
    source 'somefile.erb'
end

And then I update the cookbook to write that file to a different place like so:

template 'C:\some_different_dir\new_file_location.txt' do
    source 'sample.erb'
end

The file from the original recipe doesn't get cleaned up automatically does it? So at that point C:\dir\somefile.txt is just stranded out there not being used.

The reason I care is because our app demands a lot of resources and I don't want a lot of disk drive space taken up over time with cookbook updates. I also don't like stranded files placed about the server because I don't want something to accidentally get picked up by one of our applications and get executed. The app I'm working on has a bunch of different services running all over the place and plus we have contracts with partners and other organizations concerning left over files and source code.

Also we can't easily move into a direction where we spin up fresh new servers when our app updates using something like Vagrant or Terraform. Once our servers are spun up, they are there for a long time. Some of them aren't even VMs.

Can anyone solve this query?

Thanks.

Jul 24, 2018 in Other DevOps Questions by Damon Salvatore
• 5,980 points
880 views

1 answer to this question.

0 votes

Try the follow the follow this procedure. You would have to add a new resource to clean up the old file:

file 'C:\\dir\\somefile.txt' do
  action :delete
end

Once every server has cleaned up the file, you can remove that from the recipe, or just leave it. You can also check out the zap cookbook, which attempts to do automated cleanups but this is really hard to do in a stable way, so it comes with some "gotchas", mostly related to nested execution contexts and custom resources.

I hope the above information would be helpful for you.

answered Jul 24, 2018 by Atul
• 10,240 points

Related Questions In Other DevOps Questions

0 votes
1 answer

How do I share Build Definitions across Projects in Visual Studio Online?

VSTS does not support sharing build definitions ...READ MORE

answered Jul 5, 2018 in Other DevOps Questions by DareDev
• 6,890 points
556 views
0 votes
1 answer

how do i make apache2 site point outside the folder in ubuntu?

in apche2 configuration file u have to ...READ MORE

answered Jul 6, 2018 in Other DevOps Questions by Kalgi
• 52,350 points
817 views
0 votes
0 answers

How do I add the azure-devops commands to the Azure CLI in an offline on-premise server?

I wanted to add the azure-DevOps extension to the Azure ...READ MORE

Apr 19, 2022 in Other DevOps Questions by Kichu
• 19,040 points
589 views
+1 vote
2 answers

When do we use Chef or Azure SDK to create VM and deploy in automation

The solution to the automated deployment in ...READ MORE

answered Aug 21, 2018 in Other DevOps Questions by Priyaj
• 58,020 points
1,166 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,053 views
+2 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,201 views
0 votes
1 answer

How do I preserve local ivy repository in Bluemix BUILD & DEPLOY?

You're right--the pipeline spins up a new ...READ MORE

answered Jul 17, 2018 in Other DevOps Questions by Atul
• 10,240 points
619 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP