I need to delete all droplets with the name xyz. However when I run:
doctl compute droplet delete xyz -f
However this only works if there is exactly one droplet with the name xyz.
If there are >1 droplets I get:
Error: There are 2 Droplets with the name "xyz"; please provide a specific Droplet ID. [1111111, 9999999]
If there are 0 droplets I get:
Error: Droplet with the name "xyz" could not be found.
The problem is that I don’t know how many droplets have the name xyz when my script is run.
I tried:
doctl compute droplet delete xyz -f --all
But the --all flag does not exist. What would you recommend if I want to delete all droplets (I want this to work if there are 0, 1, 2, … n droplets, not just if there is exactly one droplet)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hello Albert,
Indeed, as the
--all
flag doesn’t exist for thedoctl compute droplet delete
command, you can achieve your goal by combining a few commands. You can list all Droplets, filter those with the name ‘xyz’, extract their IDs, and then delete each one. Here’s how you can do it in a shell script or command line:This command sequence does the following:
doctl compute droplet delete
to delete the Droplets without confirmation prompts.Note that this is a destructive action so make sure to test this script with caution, especially when using
-f
to force deletion without confirmation. You can for example only run the first part to view the IDs that will be passed to the delete command:Regarding your suggestion to have a more straightforward way to handle this, I recommend submitting a feature request to the
doctl
GitHub repository. You can propose the addition of an--all
flag or a similar feature that allows users to delete multiple droplets by name more seamlessly. Here’s the link to create a new issue: Submit a Feature Request to doctl.If you have any more questions or need further assistance, feel free to ask!
Best,
Bobby