Search code examples
windowssalt-project

How do I prevent module.run in saltstack if my file hasn't changed?


In the 2010.7 version of SaltStack, the onchanges element is available for states. However, that version isn't available for Windows yet, so that's right out.

And unfortunately salt doesn't use the zipfile module to extract zipfiles. So I'm trying to do this:

/path/to/nginx-1.7.4.zip:
    file.managed:
        - source: http://nginx.org/download/nginx-1.7.4.zip                        
        - source_hash: sha1=747987a475454d7a31d0da852fb9e4a2e80abe1d     

extract_nginx:
    module.run:
        - name: extract.zipfile
        - archive: /path/to/nginx-1.7.4.zip
        - path: /path/to/extract
        - require:
            - file: /path/to/nginx-1.7.4.zip

But this tries to extract the files every time. I don't want it to do that, I only want it to extract the file if the .zip file changes, because once it's been extracted then it'll be running (I've got something setup to take care of that). And once it's running, I can't overwrite nginix.exe because Windows is awesome like that.

So how can I extract the file only if it's a newer version of nginx?


Solution

  • I would probably use jinja to test for the existence of a file that you know would only exist if the zip file has been extracted.

    {% if salt['file.exists']('/path/to/extract/known_file.txt') %}
    extract_nginx:
        module.run:
            - name: extract.zipfile
            - archive: /path/to/nginx-1.7.4.zip
            - path: /path/to/extract
            - require:
                - file: /path/to/nginx-1.7.4.zip
    {% endif %}
    

    This will cause the extract_nginx state to not appear in the final rendered sls file if the zip file has been extracted.