Search code examples
salt-project

Call one salt-stack script from another


What is the best way to have one salt sls file call another? Does salt provide a way to do this or do I need a workaround?

The context is that I have one salt script installing Apache Tomcat, and I would like to make another script copy out the webapps into a temporary directory, run the installation script, then afterwards copy the webapps back in. I know I could put this in one .sls file, but I would like to keep them separate.


Solution

  • You can include other sls files. Example:

    tomcat/install.sls
    apps.sls
    

    In apps.sls, you just put:

    #save_webapps
    [...]
    
    include:
    - tomcat.install
    
    [...]
    #restore_webapps
    

    It should work as is, but you can use requisites (require and require_in) to make sure your states executes in the order you want.