"pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')" #43150

Hi Jborean,

I have tried with "win_scheduled_task"option like below…This time its not giving any error …and its not stopping the services as well. And the windows server i am trying is on 2008R2.
Please tell how exactly i have to use this module to run the python script.

cat winStop.yml

See the examples here: https://docs.ansible.com/ansible/2.4/win_scheduled_task_module.html#examples - this might clarify things a bit.

path needs to be a location for storing the task definition within scheduled tasks. If you run the scheduled tasks program on windows you can browse through the tree structure to find an appropriate location - its not a file system path

Also you probably need to set executable: to the full path to wherever python is installed on your windows machine and use arguments to tell python where the script is i.e. D:\smtn17\scripts\pystop.py

You might also need to set the user that scheduled tasks runs your python script as.

Hope this helps,

Jon

If you wanted to go the scheduled task route I would use https://docs.ansible.com/ansible/latest/modules/win_scheduled_task_module.html#examples instead of the 2.4 link. win_scheduled_task went through a big overhaul in 2.5 deprecating some of the options like path. Anyway there’s a reason why I had that as the last option, you are going to have much more luck doing it with become like this

`

  • name: run script with become
    win_command: python.exe D:\smtn17\scripts\pystop.py
    become: yes
    become_method: yes
    vars: # the values can be anything, I’m just using the standard connection user/var but you can choose any other
    ansible_become_user: ‘{{ ansible_user }}’
    ansible_become_pass: ‘{{ ansible_password }}’

`

https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows

Scheduled tasks are cumbersome and hard to get right while become is a lot easier to use.

Thanks

Jordan

Hi JBorean,

I have tried the below options:

  1. Method:
    become: yes

YAML:

  • name: Stopping Hyperion Services
    win_command: python.exe D:\smtn17\scripts\pystop.py
    become: yes
    become_method: yes
    vars:
    ansible_become_user: ‘{{ ansible_user }}’
    ansible_become_pass: ‘{{ ansible_password }}’

ERROR:
fatal: : FAILED! => {“msg”: “Internal Error: this connection module does not support running commands via True”}

  1. Method:
    win_psexec:

YAML:

  • name: Stopping Hyperion Services
    win_psexec:
    command: python.exe D:\smtn17\scripts\pystop.py
    executable: C:\Temp\PSTools\PsExec.exe
    register: stop_mt

ERROR:
{“changed”: true, “delta”: “0:00:01.297000”, “end”: “2018-07-26 09:53:00.248778”, “psexec_command”: “C:\Temp\PSTools\PsExec.exe -accepteula "python.exe D:\smtn17\scripts\pystop.py"”, “rc”: 2, “start”: “2018-07-26 09:52:58.951778”, “stderr”: “The system cannot find the file specified.\r\n\rPsExec could not start python.exe D:\smtn17\scripts\pystop.py:\r\n”, “stderr_lines”: [“The system cannot find the file specified.”, “”, “PsExec could not start python.exe D:\smtn17\scripts\pystop.py:”], “stdout”: “\r\nPsExec v2.2 - Execute processes remotely\r\nCopyright (C) 2001-2016 Mark Russinovich\r\nSysinternals - www.sysinternals.com\r\n\r\n”, “stdout_lines”: [“”, “PsExec v2.2 - Execute processes remotely”, “Copyright (C) 2001-2016 Mark Russinovich”, “Sysinternals - www.sysinternals.com”, “”]}

  1. Method:
    win_scheduled_task

YAML:

  • name: Stopping Hyperion Services
    win_scheduled_task:
    name: Stop Task
    actions:
  • path: D:\smtn17\scripts\pystop.py
    arguments: D:\smtn17\scripts
    register: stop_mt

ERROR:
NO ERROR. Executing succesfully. But task not executed. i.e services not stopped.

And i am going to try credssp auth method. Will keep you posted the result.

Thanks,
Usha.

Sorry the first one should work, just change become_method to `become_method: runas`. That’s my fault.

Hi JBorean,

Thats Worked!!!.. Thanks So much JB…i am struggling from 3 days for this second hop issue. Thanks a lot.