2

I am doing some operations with Kafka via salt, and using scripts to perform them.

My current SLS file looks roughly like:

/tmp/script.sh:
  file.managed:
    - source: salt://blah/blah

Run script:
  cmd.run:
    - name: /tmp/script.sh

delete /tmp/script.sh:
  file.absent
    - name: /tmp/script.sh

script.sh is idempotent itself. But I always get a changed=2 status report at the end of applying the state, because of it putting the script down and then deleting it.

Is there a more idiomatic way in Salt to have temporary scripts that don't live on the target box? Or do people usually just leave them in /tmp so that they don't see a reported change when applying a state.

0

You might want to consider adding an unless or onlyif requisite in the first directive - especially if script.sh is particularly complicated or expensive. With unless or onlyif, you will use the reults of several BASH commands to determine if you need to push down and execute your script. If your system is out of plumb only then is the state enforced. If everything checks out OK, then the script will never be pushed and executed preventing changed=2 in the final status report. You will want to use a require requisite for the second and third directives to prevent them from running if the script is not pushed by file.managed otherwise you will get to errors instead of two changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.