*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"}

I tried to copy the script using the win_copy module and set the remote_src 
to true.  It kept failing with the weird message. I didn't spend much time 
on it as I thought of using win_shell instead. 

Can we discuss this on the original post please?

Regards,
Darshan


On Wednesday, July 29, 2020 at 11:59:16 PM UTC+9:30, Avinash Jadhav wrote:
>
> Hello Darshan,
>
> Could you please try to below 
>
> --- 
> - 
>   become: true
>   become_user: ansible
>   gather_facts: true
>   hosts: CF-DEV-B
>   ignore_errors: true
>   tasks: 
>     - 
>       name: restart service
>       script: C:\Users\Administrator\Documents\service.ps1 cdu
>       register: out
>     - 
>       debug: var=out.stdout_lines
>   
>
> Please let know if it is working or not 
>
> Regards 
> Avinash Jadhav
>
>
> On Wed, 29 Jul 2020 at 19:23, Darshan Yamakanamardi <dars...@gmail.com 
> <javascript:>> wrote:
>
>> 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 ProductionWrite-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.
>>
>> [image: Screen Shot 2020-07-29 at 11.00.47 PM.png]
>>
>>
>>
>>
>>
>> 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=output
>>
>>
>>
>>
>> Posting 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 down
>>
>> Any 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...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/beeccf92-8322-4f34-bf22-b6c288c7873eo%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/beeccf92-8322-4f34-bf22-b6c288c7873eo%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/33791434-bce5-402e-8751-956469dc1ba6o%40googlegroups.com.

Reply via email to