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 23, 2018 in Other DevOps Questions by Damon Salvatore
• 5,510 points
39 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 23, 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,810 points
31 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
• 40,460 points
33 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
• 56,520 points
138 views
0 votes
1 answer

SaltStack: how do I repeat other states with context?

In your case it’ll look something like ...READ MORE

answered Jul 10, 2018 in Other DevOps Questions by Kalgi
• 2,620 points
58 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
152 views
0 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
80 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
36 views