Search code examples
salt-project

Create a windows service in a salt state


I know how to create a windows service by doing,

salt service.create "servicename" "c:\executable.exe" display="serviceIcreated"

How can I incorportate this into a state?

c:\temp\somedir:
  file.recurse:
    -source: salt:/d/ser

Solution

  • As the service.create is not available in Salt States you will need to run the execution module from within your own state or sls file.

    You could do it this way:

    create_executable:
      module.run:
        - name: service.create
        - m_name: servicename
        - bin_path: c:\executable.exe
        - display: serviceIcreated
    

    About the piece of code in your question I did not understand how it adds value to your question.

    c:\temp\somedir:   
       file.recurse:
        -source: salt:/d/ser
    

    If it is relevant, please make an edit in order to make it easier to understand.