0

Lets say in below salt call. I want the salt not to execute anymore further if a file exist.

In below example. It should execute run-aerospike-mem_disk-check but once if it detects file exist in check_bad_conf. It shouldn't execute run-aerospike-config and get some RED color in salt as failed. How to achieve it.

Lets say in below salt call. I want the salt not to execute anymore further if a file exist.

In below example. It should execute run-aerospike-mem_disk-check but once if it detects file exist in check_bad_conf. It shouldn't execute run-aerospike-config and get some RED color in salt execution as failed. How to achieve it.

run-aerospike-mem_disk-check:
  cmd.wait:
   - name: /var/local/aero_dmcheck.sh
   - watch:
     - file: /var/local/aero_config

check_bad_conf:
   file.exist : /tmp/badconf
     - failhard : yes

run-aerospike-config:
  cmd.wait:
    - name: /var/local/aero_config.pl
    - watch:
      - file: /var/local/aero_config.yml
mannoj
  • 443
  • 2
  • 5
  • 18

2 Answers2

0

Make it more clear please.
Why you are so badly after "RED"?
You have disk-check to be run only if the bad file exists?
If so it must not run aerospike-config? Run once no matter if the file still exists?

cmd.wait accepts onlyif argument in which you can run command to assert file absence/presence/anything (it is exit code-driven).
However you need to know that if onlyif is not satisfied the state turns GREEN not RED There is also creates argument that is designed exactly for running the command if the given file exists. Refer to cmd manual

As you probably want aerospike-config to be run only if the disk-check was not run maybe it is sufficient to use file.missing like so:

check:
  file.missing:
    - name: /tmp/badconf
run-aerospike-config:
  cmd.wait:
    - name: /var/local/aero_config.pl
    - watch:
      - file: /var/local/aero_config.yml
    - require:
      - file: check

Read more about Salt requisites here If you want your run-aerospike-mem_disk-check script to be run exactly once, why don't you use cmd.script and add stateful argument to prohibit further executions?

lakier
  • 550
  • 4
  • 16
-1

I actually never really used it but you can use some kind of "if-statement". Check this out:

Check file exists and create a symlink

I think in your case file.present or file.absent would fit.

Hope that helps.

Bruh
  • 16
  • 2