Saltstack - installing script with manual interactions

Viewed 33

I am creating a state which is running a shell script, but to be installed need manual interactions.

like:
press yes to continue 
add home folder for the user x 
accept license agreement yes or no 
default answer is: n
is the following path correct press yes to continue
etc.



Start_shell_Script:
  cmd.run:
    - name: script.sh
    - stateful: True
    - shell: /bin/bash
    - runas: user-x 

I would like to automate the process and do not cut in half the installation of the application and run some scripts manually.

Thank you in advance.

1 Answers

As of now there is no built-in way to pass interactive inputs to scripts from Saltstack cmd module. However take a look at Linux expect. This is one of the ways you can automate your interactive scripts.

To be specific, autoexpect is a handy tool to quickly automate an interactive script. For your use case, you can run it as:

autoexpect /path/to/script.sh

Provide interactive inputs as required. This will create a script.exp (expect script) with a record of your inputs. This can then be run at any time with expect /path/to/script.exp non-interactively.

You can transfer this file to the minion and use it in a Salt state as well:

Start_shell_Script:
  cmd.run:
    - name: /usr/bin/expect /path/to/script.exp
Related