How to create a service on a windows 10 machine?

476 views
Skip to first unread message

Sharwari Phadnis

unread,
Apr 8, 2016, 10:05:15 AM4/8/16
to Ansible Project
I am trying to create a service of type kernel on a remote windows 10 machine from a linux ansible controller machine. To create a service I'm using sc create type=kernel binpath=c:\path  command.

Ansible playbook for creating a service:
- hosts: windows
  tasks:
     - name: Create temp service
       raw: sc create temp type=kernel binpath=c:\path\


And I'm getting the following error:

TASK [Create temp service on windows] ****************************************
fatal: [10.x.x.x]: FAILED! => {"changed": false, "failed": true, "rc": 1, "stderr": "#< CLIXML\r\n<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><Obj S=\"progress\" RefId=\"0\"><TN RefId=\"0\"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N=\"SourceId\">1</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S=\"Error\">Set-Content : A positional parameter cannot be found that accepts argument 'type=kernel'._x000D__x000A_</S><S S=\"Error\">At line:1 char:1_x000D__x000A_</S><S S=\"Error\">+ sc create temp type=kernel binpath=c:\\windows\\ ..._x000D__x000A_</S><S S=\"Error\">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S=\"Error\">    + CategoryInfo          : InvalidArgument: (:) [Set-Content], ParameterBindingException_x000D__x000A_</S><S S=\"Error\">    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand_x000D__x000A_</S><S S=\"Error\"> _x000D__x000A_</S></Objs>", "stdout": "", "stdout_lines": []}



What could be the exact reason? Or is there any other of creating a service on a windows machine?

J Hawkesworth

unread,
Apr 9, 2016, 3:46:25 PM4/9/16
to Ansible Project
sc is a powershell alias for 'set-content'

If you change your raw command to

   raw: sc.exe ....

it will probably work.

Better still install nssm (which is a service manager) and use win_nssm module.

There is also a win_service_configure module if you prefer for creating modules but it hasn't been merged into ansible yet.  Its here - https://github.com/ansible/ansible-modules-extras/pull/1115
 perhaps you could test it?

Hope this helps,

Jon
Reply all
Reply to author
Forward
0 new messages