puppetlabs / bolt

Bolt is an open source orchestration tool that automates the manual work it takes to maintain your infrastructure on an as-needed basis or as part of a greater orchestration workflow. It can be installed on your local workstation and connects directly to remote nodes with SSH or WinRM, so you are not required to install any agent software.
https://puppet.com/docs/bolt/latest/bolt.html
Apache License 2.0
497 stars 224 forks source link

A function to delete a file on a target (`delete_file()`) #3200

Open jay7x opened 1 year ago

jay7x commented 1 year ago

Use Case

It'd be nice to be able to delete a file from a target. We have upload/download/write functions but there is nothing to delete..

Describe the Solution You Would Like

I'd be happy to have the delete_file() function which deletes the file specified on the targets specified

delete_file($filename, $targets, $options) => ResultSet

Describe Alternatives You've Considered

It's possible to work this around with run_command though it doesn't look great:

run_command("rm -f -- '${filename}'", $targets)

Additional Context

The ability to delete a file was required to cleanup a temporary file which is passed to another program to consume it. The file can be deleted after. So actually maybe we need a mktemp() function too. Or, as proposed in Slack:

with_tempfile() |$file| {
 # ...
}

Here is the discussion related: https://puppetcommunity.slack.com/archives/C7GP57T50/p1675006959793689

pdthomson commented 1 year ago

@jay7x If no ones doing this already could I be assigned to this issue?

jay7x commented 1 year ago

@jay7x If no ones doing this already could I be assigned to this issue?

Hi @pdthomson! I don't think anyone is working on this at the moment.. Please feel free to do a PR! Thank you!

pdthomson commented 1 year ago

Hey @jay7x I have went through the set up documentation on the github repo and was running the tests and getting a lot of failures, I have mocked out some code and wanted to write a delete_file_spec.rb in the bolt-modules/boltlib/spec/functions but I cant get any of those tests to even pass currently and it seems I must be missing something with the initial setup as this is my first contribution.

NameError:
  uninitialized constant PuppetlabsSpec
# ./bolt-modules/boltlib/spec/functions/vars_spec.rb:8:in `block in <top (required)>'
# ./bolt-modules/boltlib/spec/functions/vars_spec.rb:7:in `<top (required)>'

An error occurred while loading ./bolt-modules/boltlib/spec/functions/wait_spec.rb.
Failure/Error: include PuppetlabsSpec::Fixtures

Ive done a bunch of reading on bolt/puppet and scrolled through the slack to find any similar issues, as I am sure I am missing something easy or running a command incorrectly

jay7x commented 1 year ago

Hi @pdthomson! Somehow it was fine for me last time few month ago.. 🤔 let me try to setup the environment again. I'll update you here..

jay7x commented 1 year ago

Well.. here is what I did:

bundle install --path=.bundle --with test
bundle exec r10k puppetfile install .
cd bolt-modules/boltlib/
bundle exec rake spec

This way those tests are fine for me on ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [arm64-darwin21].

Though I guess you'll need to change transport-related classes too.. so it seems you need to spin up the docker-compose infra (docker-compose -f spec/docker-compose.yml up -d --build). Though it works for x86_64 arch only.. those containers don't have arm64 versions. So I cannot run it at the moment.

This repo has CI/CD configured which can be used to run the tests for now..

jay7x commented 1 year ago

I asked someone from the Bolt team to have a look here just in case. So you can get the support from them. Feel free to jump in to the #bolt channel on the Puppet Community Slack! And maybe register here for the Puppet Hackathon as you're heading to do things anyway: https://dev.to/puppet/may-the-source-be-with-you-45bi :)

smortex commented 1 year ago

I experience some breakage now that puppetlabs/puppet has a 8.0.0 tag. Adding gem 'puppet', '< 8.0.0' to the Gemfile somehow helps, but in any case, the whole tests suite does not pass on my machine (some tests have some requirements)!

pdthomson commented 1 year ago

Oh perfect! I went ahead and registered for the Hackathon! I will spin up the docker container again and add gem 'puppet', '< 8.0.0' into the gem file and give it a go. Oh perfect having the CI/CD I can test against that so I should be good to go then.

jay7x commented 5 months ago

Aaaand.. I hit this again! :(

@pdthomson By any chance, have you anything done wrt this? Some work-in-progress branch maybe?

davidsandilands commented 2 months ago

@pdthomson just to check in on this and see if you had any work in progress branch or such like?