RexOps / RexOps/Rex

Execute command before moving file into its final location

Open
#1,478 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Perl
Stars
737
Forks
214
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining Rex's existing global file hooks and the file deployment path described in the issue. Determine whether per-file hooks or a dedicated validate option best fits the existing hook model, then verify that the temporary file is copied to its final location only after validation succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.