file_from_local_source_with_check

Ensure that a file or directory is copied from a local source if a check command succeeds.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
sourceSource file (absolute path on the target node).

This parameter is required.
pathDestination file (absolute path on the target node).

This parameter is required.
check_commandCommand to run, it will get the source path as argument.

This parameter is required.
rc_okReturn codes to be considered as valid, separated by a comma (default is 0).

This parameter is optional.

Outcome conditions

You need to replace ${path} with its actual canonified value.

  • ✅ Ok: file_from_local_source_with_check_${path}_ok
    • ☑️ Already compliant: file_from_local_source_with_check_${path}_kept
    • 🟨 Repaired: file_from_local_source_with_check_${path}_repaired
  • ❌ Error: file_from_local_source_with_check_${path}_error

Example

method: file_from_local_source_with_check
params:
  source: VALUE
  rc_ok: OPTIONAL_VALUE
  check_command: VALUE
  path: VALUE

Documentation

This method is a conditional file copy.

It allows comparing the source and destination, and if they are different, call a command with the source file path as argument, and only update the destination if the commands succeeds (i.e. returns a code included in rc_ok).

Examples

# To copy a configuration file only if it passes a config test:
file_from_local_source_with_check("/tmp/program.conf", "/etc/program.conf", "program --config-test", "0");

This will:

  • Compare /tmp/program.conf and /etc/program.conf, and return kept if files are the same
  • If not, it will execute program --config-test "/tmp/program.conf" and check the return code
  • If it is one of the rc_ok codes, it will copy /tmp/program.conf into /etc/program.conf and return a repaired
  • If not, it will return an error