Search code examples
salt-project

How do I restart salt-minion without causing the state to fail?


We use a salt state to update the saltenv and pillarenv in /etc/salt/minion we call this initial state with the state.apply app.changesaltenv saltenv=newenv pillarenv=newenv

I haven't figured out a way to have the salt state restart the minion without it causing the salt state to fail because it loses connectivity with the salt minion.

If I try to add service.restart to the state, the state fails because the minion stops communicating with the master.

I noticed this question but the examples does so by causing a failure.


Solution

  • After asking around I got this suggestion and it works so far.

    It does make an assumption about where salt-call is and I can't find a salt variable that easily exposes where salt-call.bat is. I can write some jinja that checks grains['saltpath'] to determine if salt was installed to C:\salt or C:\Program Files\Salt Project\Salt or possibly someplace else.

    Restart Salt Minion:
      cmd.run:
    {%- if grains['kernel'] == 'Windows' %}
        - name: 'C:\salt\salt-call.bat service.restart salt-minion'
    {%- else %}
        - name: 'salt-call service.restart salt-minion'
    {%- endif %}
        - bg: True
        - order: last
    

    Answer originally by Greg Long.