Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute command before moving file into its final location #1478

Open
ferki opened this issue Mar 5, 2021 · 0 comments
Open

Execute command before moving file into its final location #1478

ferki opened this issue Mar 5, 2021 · 0 comments
Labels
feature request A suggested idea for the project

Comments

@ferki
Copy link
Member

ferki commented Mar 5, 2021

User story

As a rex user,
I would like to execute some commands before a file is moved to its final location,
so I can to validate file content, or show diff before the changes are applied.

Describe the solution you'd like

Currently we can use file hooks for similar purposes, but those hook apply for all file commands globally. We could either allow general file hooks on a case-by-case basis:

file '/etc/ssh/sshd_config',
  source        => 'files/etc/ssh/sshd_config',
  before_change => sub { run 'sshd -t <%= $filename %>'}; # template format

or introduce a new, purpose-made validate option:

file '/etc/ssh/sshd_config',
  source   => 'files/etc/ssh/sshd_config',
  validate => sub { run 'sshd -t %s'}; # string placeholder format

It would only copy the temporary file to its final location if this hook returns success.

Describe alternatives you've considered

Filename matching is possible inside the global hooks too, but it feels like the configuration for that would be far away from its context.

Additional context

Ansible has a similar validate logic too, but I think I would prefer a more generic solution, especially given we already have various file hooks in place, it's just hard to configure those on a per-file basis.

@ferki ferki added the feature request A suggested idea for the project label Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A suggested idea for the project
Projects
None yet
Development

No branches or pull requests

1 participant