Hello Ansible Experts,--I have a PowerShell script that actually takes an argument and stops/starts a service based on the argument passed.[CmdletBinding()] param ( [string] $SITE ) $ServiceName = Get-Website | findstr 80 | findstr $SITE | %{ $_.Split(' ')[0]; } | findstr Production Write-Host -Object "The service to stop and start is ColdFusion 9 - $ServiceName" Stop-Service -Name "ColdFusion 9 - $ServiceName" Start-Service -Name "ColdFusion 9 - $ServiceName"When I run the above script locally on the windows machine, it stops/starts the service.When I attempt to run the same script via the Ansible playbook below bypassing the argument actually the stopping/starting service doesn't work.- hosts: CF-DEV-B gather_facts: yes tasks: - name: restart service win_shell: C:\Users\Administrator\Documents\service.ps1 cdu become: yes become_user: Administrator register: output - debug: var=outputPosting the debug section output here for your reference.TASK [debug] ********************************************************************************************************************************************************************************************************************************
ok: [10.0.0.96] => {
"output": {
"changed": true,
"cmd": "C:\\Users\\Administrator\\Documents\\restart_service.ps1 cdu",
"delta": "0:00:01.099647",
"end": "2020-07-29 01:46:22.326932",
"failed": false,
"rc": 0,
"start": "2020-07-29 01:46:21.227285",
"stderr": "Stop-Service : Cannot find any service with service name 'ColdFusion 9 - '.\r\nAt C:\\Users\\Administrator\\Documents\\restart_service.ps1:8 char:1\r\n+ Stop-Service -Name \"ColdFusion 9 - $ServiceName\"\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (ColdFusion 9 - :String) [Stop-S \r\n ervice], ServiceCommandException\r\n + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell. \r\n Commands.StopServiceCommand\r\n \r\nStart-Service : Cannot find any service with service name 'ColdFusion 9 - '.\r\nAt C:\\Users\\Administrator\\Documents\\restart_service.ps1:9 char:1\r\n+ Start-Service -Name \"ColdFusion 9 - $ServiceName\"\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (ColdFusion 9 - :String) [Start- \r\n Service], ServiceCommandException\r\n + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
When executed via ansible-playbook the PowerShell fails to find the service name.While I know we have win_servive module to stop and start a service but that module doesn't help me in solving the problem which we have. Actually, the arguments will be passed to ansible-playbook by using "-e" extra argument options and the arguments are dynamically identified and passed based on which site is downAny suggestions to fix this would be much appreciable. Thanks in advance for looking into it.Regards,Darshan
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/beeccf92-8322-4f34-bf22-b6c288c7873eo%40googlegroups.com.
Hello Avinash,
Thanks for your response. And sorry for this duplicate post. (I missed the response from other community members) The original post is here: https://groups.google.com/d/msg/ansible-project/LGtMnY3b32E/XN5bRkBwCQAJ
The script module never worked for me.
fatal: [10.0.0.96]: FAILED! => {"changed": false, "msg": "Could not find or access 'C:UsersAdministratorDocumentsservice.ps1'\nSearched in:\n\t/home/ec2-user/site-warmup/gs-int/files/C:UsersAdministratorDocumentsservice.ps1\n\t/home/ec2-user/site-warmup/gs-int/C:UsersAdministratorDocumentsservice.ps1\n\t/home/ec2-user/site-warmup/gs-int/files/C:UsersAdministratorDocumentsservice.ps1\n\t/home/ec2-user/site-warmup/gs-int/C:UsersAdministratorDocumentsservice.ps1 on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.