Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_service_info errors out #556

Closed
hellcry37 opened this issue Sep 26, 2023 · 6 comments · Fixed by #559
Closed

win_service_info errors out #556

hellcry37 opened this issue Sep 26, 2023 · 6 comments · Fixed by #559

Comments

@hellcry37
Copy link

SUMMARY

On some windows pcs I get an error when trying to use this module. Not on all, on dome it works ok.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_service_info

ANSIBLE VERSION
ansible [core 2.15.4]
  config file = /home/user/ansible/windows_work_local/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.11.4 (main, Jun 15 2023, 14:07:54) [GCC 10.2.1 20210110] (/usr/local/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/user/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
ansible.windows 2.1.0

# /home/user/.local/lib/python3.11/site-packages/ansible_collections
Collection      Version
--------------- -------
ansible.windows 1.14.0
CONFIGURATION
CONFIG_FILE() = /home/user/ansible/windows_work_local/ansible.cfg
DEFAULT_BECOME_METHOD(/home/user/ansible/windows_work_local/ansible.cfg) = runas
DEFAULT_HOST_LIST(/home/user/ansible/windows_work_local/ansible.cfg) = ['/home/user/ansible/windows_work_local/hosts.ini']
DEFAULT_ROLES_PATH(/home/user/ansible/windows_work_local/ansible.cfg) = ['/home/user/ansible/windows_work_local/roles']
DEFAULT_STDOUT_CALLBACK(/home/user/ansible/windows_work_local/ansible.cfg) = yaml
HOST_KEY_CHECKING(/home/user/ansible/windows_work_local/ansible.cfg) = False
INTERPRETER_PYTHON(/home/user/ansible/windows_work_local/ansible.cfg) = auto_silent
OS / ENVIRONMENT

target win 10 and win 11 laptops

STEPS TO REPRODUCE

I am trying to the the state of all services to use this info in disabling some of them

- name: Get info for all services
  ansible.windows.win_service_info:
  register: pc_services_info
EXPECTED RESULTS

On one laptop and some pc's everything works as expected

ACTUAL RESULTS

On 4 of 5 laptops I get this:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was:    at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
fatal: [laptop1]: FAILED! => changed=false
  msg: 'Unhandled exception while executing module: Exception calling ".ctor" with "2" argument(s): "Failed to query service config (The system cannot find the file specified, Win32ErrorCode 2 - 0x00000002)"'

Verbose:

The full traceback is:
Exception calling ".ctor" with "2" argument(s): "Failed to query service config (The system cannot find the file specified, Win32ErrorCode 2 - 0x00000002)"
At line:31 char:24
+ ...  $service = New-Object -TypeName Ansible.Windows.SCManager.Service -A ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 31

System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "2" argument(s): "Failed to query service config (The system cannot find the file specified, Win32ErrorCode 2 - 0x00000002)" ---> ansible_collections.ansible.windows.plugins.module_utils.SCManager.ServiceManagerException: Failed to query service config (The system cannot find the file specified, Win32ErrorCode 2 - 0x00000002)
   at ansible_collections.ansible.windows.plugins.module_utils.SCManager.Service.Refresh() in c:\Users\user\AppData\Local\Temp\4cqilajp.0.cs:line 1273
   --- End of inner exception stack trace ---
   at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
fatal: [laptop1]: FAILED! => changed=false
  msg: 'Unhandled exception while executing module: Exception calling ".ctor" with "2" argument(s): "Failed to query service config (The system cannot find the file specified, Win32ErrorCode 2 - 0x00000002)"'

@pitoniak32
Copy link

I am seeing this also, the docs are indicating name can be omitted but that causes an error, I also tried with just name: "*" and got the above error.

@hellcry37
Copy link
Author

The question is what is missing on the systems that does not work? I have 4 systems that errors out and 20 that work ok.

@jborean93
Copy link
Collaborator

Hmm we do have a catch block for this code but it seems like this is throwing a different exception type

try {
$service = New-Object -TypeName Ansible.Windows.SCManager.Service -ArgumentList @(
$rawService.Name, [Ansible.Windows.SCManager.ServiceRights]'EnumerateDependents, QueryConfig, QueryStatus'
)
}
catch [Ansible.Windows.SCManager.ServiceManagerException] {
# ERROR_ACCESS_DENIED, ignore the service and continue on.
if ($_.Exception.InnerException -and $_.Exception.InnerException.NativeErrorCode -eq 5) {
$msg = "Failed to access service '$($rawService.Name) to get more info, ignoring: $($_.Exception.Message)"
$module.Warn($msg)
continue
}
throw
}
.

We probably need to just do a generic catch without a specific type for the warning to pick this up. As for why it's happening I'm not 100% sure. It could be that the service name that it is failing on could have a reference to some shared resource id that is failing to be found but unfortunately without knowing the service and the details behind that it'll be hard to figure out why it's failing.

@jborean93
Copy link
Collaborator

I've opened #559 which should treat this error as a warning and display what service it failed on. From there we can look further into why it failed but it might not be something we can fix up in Ansible as it's an error from the underlying Windows APIs.

@hellcry37
Copy link
Author

Excellent, I am looking forward to test this when is merged

@hellcry37
Copy link
Author

I've tried to update ansible, I even added code myself to my instance, for me it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants