3

Is it possible to do the same thing in Saltsack, but by embedded functionality (without powershell workaround)?

installation:
cmd.run:
- name: ./installation_script

wait for installation:
cmd.run:
 - name: powershell -command "Start-Sleep 10"
 - unless: powershell -command "Test-Path @('/path/to/file/to/appear')"
Anatoli
  • 889
  • 2
  • 15
  • 33
  • I'm not sure what exactly are you trying to do. Do you want to run a command only after the installation is complete? Or do you want to run command only if the file exists? – alexK May 03 '17 at 14:12
  • @alexK This installation creates a file - it is the marker that task is completed. So I want to go ahead only when file exists. – Anatoli May 03 '17 at 17:01
  • Then I'm afraid, there's no real way that will not involve running some kind of OS command. Maybe just to make a state more platform-agnostic you could use python states provider as shown [here](http://stackoverflow.com/a/21859316/1212203) – alexK May 04 '17 at 10:10
  • Thanks for the link! So many ways to do one thing :) – Anatoli May 04 '17 at 12:04

2 Answers2

7

Unfortunately there is not a better way to do this in the current version of salt. But there was retry logic added into states in the next release Nitrogen.

The way I would do this in that release is.

installation:
  cmd.run:
    - name: ./installation_script

wait for installation:
  cmd.run:
    - name: Test-Path @('/path/to/file/to/appear')
    - retry:
      - attempts: 15
      - interval: 10
      - until: True
    - shell: powershell

And this will continue to run the Test-Path until it exits with a 0 exit code (or whatever the equivalent is in powershell)

https://docs.saltstack.com/en/develop/ref/states/requisites.html#retrying-states

Daniel

Utah_Dave
  • 4,531
  • 24
  • 23
gtmanfred
  • 593
  • 6
  • 14
1

NB: While using retry, pay attention to the indent, it has to be 4 spaces from retry key to form a dictionary for salt. Otherwise it will default to 2 attempts with 30s interval. (2017.7.0.)

wait_for_file:
  file.exists:
    - name: /path/to/file
    - retry:
        attempts: 15
        interval: 30
karel
  • 11
  • 2