0

I want to enable logging of an fstp server like this: https://serverfault.com/a/74234/90324

But salt does nothing. I reduced it to this:

enable_logging_of_sftp:
  file.replace:
    - name: /etc/ssh/sshd_config
    - pattern: Sxxxxubsystem
    - repl: Syyyubsystem
    - ignore_if_missing: False

Still, salt says:

      ID: enable_logging_of_sftp
Function: file.replace
    Name: /etc/ssh/sshd_config
  Result: True
 Comment: No changes needed to be made
 Started: 11:09:24.356010
Duration: 15.231 ms
 Changes:   

I don't understand this. Of course Sxxxxubsystem and Syyyubsystem are not in /etc/ssh/sshd_config.

Since ignore_if_missing is missing is False (which is the default any way), I think I should get an error message.

Why is there no error message if pattern and repl are not in the file?

Above question arose since I misread the docs. Here is the follow-up question which handles my use case: Salt: Raise Error if file.replace did not find anything to replace

guettli
  • 3,113
  • 14
  • 59
  • 110

1 Answers1

1

If your file is present, you will never get an error, even if the pattern is not present in the file.

Quoting this page https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.replace

ignore_if_missing : False

New in version 2016.3.4.

Controls what to do if the file is missing. If set to False, the state will display an error raised by the execution module. If set to True, the state will simply report no changes.

If what you want to do is detect when your pattern is not present, I don't know how you can do it. But you can look at append_if_not_found parameter to insert data even if the pattern is not present.

daks
  • 673
  • 6
  • 23
  • Thank you very much! I was reading too fast. I read "if the pattern is missing", but it is about "if the file is missing". I was blind. Sorry. – guettli Jan 17 '19 at 15:13
  • @guettli can you please validate my answer? – daks Jan 17 '19 at 15:21
  • Here is the follow-up question: https://serverfault.com/questions/950354/salt-raise-error-if-file-replace-did-not-find-anything-to-replace – guettli Jan 23 '19 at 11:28