0

Maybe I am blind, but I could not find a way to let the salt-ssh call fail, if file.replace did not replace a single line.

If the pattern I provide did not match, then I want to get noticed.

Example:

enable_foo:
  file.replace:
    - name: /etc/foo/foo.config
    - pattern: DisallowBar
    - repl: AllowBarUntilMidnight
  • Case1: DisallowBar found and replaced, gets replaced: OK
  • Case2: AllowBarUntilMidnight is already in the file: OK
  • Case3: DisallowBar and AllowBarUntilMidnight are not in the file: I want salt to fail.
guettli
  • 3,811

1 Answers1

0

Saltstack is a configuration management tool so when using states you define what you want, you normally don't bother to be warn when something is done or not.

So in your example I would say "you want replace pattern X by string Y" and that's it. Saltstack does the job to replace the pattern if it exists and do nothing if not.

Moreover, in configuration management, you generally want states to be 'idempotent'. It means successive executions must produce the same result. Wether you execute your state one time or 1000 times should be the same. I'm not sure that what you want to do is really provided by saltstack.

update: of course you can do what you want with saltstack, but you may have to separate in two states: one to check current state and eventually fail (check failhard https://docs.saltstack.com/en/latest/ref/states/failhard.html), and another to replace

daks
  • 673