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

ansible.windows.win_reboot: failed to get host boot time info #326

Closed
Frantz444 opened this issue Jan 5, 2022 · 7 comments
Closed

ansible.windows.win_reboot: failed to get host boot time info #326

Frantz444 opened this issue Jan 5, 2022 · 7 comments

Comments

@Frantz444
Copy link

SUMMARY

This is related to #324
I'm getting the same behavior using latest ansible version

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_reboot

ANSIBLE VERSION
ansible [core 2.12.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True
COLLECTION VERSION
Collection      Version
--------------- -------
ansible.windows 1.9.0

CONFIGURATION

OS / ENVIRONMENT

EC2 Window Server2019 1809

Connection config:
ansible_connection=winrm
ansible_winrm_transport=kerberos
ansible_winrm_server_cert_validation=ignore
ansible_winrm_kerberos_delegation=true

STEPS TO REPRODUCE

The playbook runs on an Ubuntu 20.04.3 LTS

- hosts: '{{ group_name }}'
  tasks:
  - name: 'Reboot server '
    win_reboot:
EXPECTED RESULTS

Reboot

ACTUAL RESULTS
ansible-playbook [core 2.12.1]
  config file = /home/user/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True
Using /home/user/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/user/inv as it did not pass its verify_file() method
script declined parsing /home/user/inv as it did not pass its verify_file() method
auto declined parsing /home/user/inv as it did not pass its verify_file() method
Parsed /home/user/inv inventory source with ini plugin
Loading collection ansible.windows from /usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.8/dist-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: reboot.yaml **************************************************************************************************************************************************
Positional arguments: ./reboot.yaml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/user/inv',)
extra_vars: ('group_name=phase1',)
forks: 5
1 plays in ./reboot.yaml

PLAY [phase1] **********************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
task path: /home/user/reboot.yaml:1
redirecting (type: modules) ansible.builtin.setup to ansible.windows.setup
Using module file /usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/modules/setup.ps1
Pipelining is enabled.
<a_server> ESTABLISH WINRM CONNECTION FOR USER: a_user on PORT 5986 TO a_server
calling kinit with pexpect for principal a_user
EXEC (via pipeline wrapper)
ok: [a_server]
META: ran handlers

TASK [Reboot server ] ************************************************************************************************************************
task path: /home/user/reboot.yaml:5
ansible.windows.win_reboot: getting boot time
<a_server> ESTABLISH WINRM CONNECTION FOR USER: a_user on PORT 5986 TO a_server
calling kinit with pexpect for principal a_user
EXEC (via pipeline wrapper)
ansible.windows.win_reboot: closing connection plugin
ansible.windows.win_reboot: resetting connection plugin
ansible.windows.win_reboot: getting boot time
<a_server> ESTABLISH WINRM CONNECTION FOR USER: a_user on PORT 5986 TO a_server
calling kinit with pexpect for principal a_user
EXEC (via pipeline wrapper)
ansible.windows.win_reboot: closing connection plugin
ansible.windows.win_reboot: resetting connection plugin
ansible.windows.win_reboot: getting boot time
<a_server> ESTABLISH WINRM CONNECTION FOR USER: a_user on PORT 5986 TO a_server
calling kinit with pexpect for principal a_user
EXEC (via pipeline wrapper)
The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/plugin_utils/_reboot.py", line 146, in reboot_host
    previous_boot_time = _do_until_success_or_retry_limit(task_action, connection, host_context,
  File "/usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/plugin_utils/_reboot.py", line 272, in _do_until_success_or_retry_limit
    return _do_until_success_or_condition(task_action, connection, host_context, action_desc, wait_condition,
  File "/usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/plugin_utils/_reboot.py", line 344, in _do_until_success_or_condition
    raise last_error
  File "/usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/plugin_utils/_reboot.py", line 308, in _do_until_success_or_condition
    res = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/ansible_collections/ansible/windows/plugins/plugin_utils/_reboot.py", line 379, in _get_system_boot_time
    raise _ReturnResultException(msg, rc=rc, stdout=stdout, stderr=stderr)
ansible_collections.ansible.windows.plugins.plugin_utils._reboot._ReturnResultException: ansible.windows.win_reboot: failed to get host boot time info
fatal: [a_server]: FAILED! => {
    "changed": false,
    "elapsed": 0,
    "msg": "ansible.windows.win_reboot: failed to get host boot time info",
    "rc": 1,
    "rebooted": false,
    "stderr": "The system cannot find the path specified.\r\n#< 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><Obj S=\"progress\" RefId=\"1\"><TNRef RefId=\"0\" /><MS><I64 N=\"SourceId\">2</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></Objs>",
    "stdout": "132845804665000000",
    "unreachable": false
}

PLAY RECAP *************************************************************************************************************************************************************
a_server : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

@Frantz444
Copy link
Author

@jborean93 i managed to move to the latest version of ansible and the windows collection, hope you can have a look.

@jborean93
Copy link
Collaborator

Thanks for testing this out, it is a very curious error as the command being run produced the expected output in the stdout but for some reason set a return code of 1 and has the failure The system cannot find the path specified. This seems to indicate there is a problem with starting powershell or even just trying to run the CIM cmdlets produce such a scenario that is just being passed back.

Can you try out the following task?

- raw: |
    (Get-CimInstance -ClassName Win32_OperatingSystem -Property LastBootUpTime).LastBootUpTime.ToFileTime()

If that also returns an rc of 1 including the error message about the path can you add $Error[0] | Select * and $Error[0].Exception.ToString() as extra lines on the command to hopefully provide more information as to what failed.

@jborean93
Copy link
Collaborator

@Frantz444 were you able to test out the above, I'm in the neighborhood of win_reboot and would be good to see if this can be fixed. I'm unable to replicate this problem on my end so am reliant on what you can test out and report.

@Frantz444
Copy link
Author

Hello,

Finally managed to get more information regarding this error using the old way - procexp. After "grep-ing" all the relevant processes found the culprit. It was related to some local miss-configuration of CMD which was altered by another program (some tool Clink). It was removed but apparently kept registry entry to it, wasn't related to %PATH% or other env_variables

Executing WINRM commands directly from CMD went ok, but when running them through POWERSHELL I got that "The system cannot find the path specified". Because the ansible module executes the WINRM calls using POWERSHELL it ended getting this error. But only for the win_reboot module the task failed, for other ones(not only ansible.windows) it worked.

So in the end fixed this entries and got my system cleaned. The module works without any problem.

The though part was to identify the issue because it involves multiple tools in this chain of a system reboot.

@jborean93
Copy link
Collaborator

Thanks for confirming the problem was due to a misconfiguration on the host. There are a lot of complex processes that this particular plugin tries to invoke compared to normal modules which is likely why you only encountered it here. I'm not sure what else the code could do to help this, unless there was anything in particular you wanted to discuss further I'll close the issue.

@snehalpdev
Copy link

@Frantz444 What exact entries were cleaned by you to fix the issue? I am having the exact same issue where rebooting win 2019 server causing error "ansible.windows.win_reboot: failed to get host boot time info"

@Frantz444
Copy link
Author

My entries were related to some tool Clink. It had entries in the path and other env variables. Try looking into all of these and check if you spot some unwanted tools that might alter your windows pwsh execution

shahargolshani pushed a commit to shahargolshani/ansible.windows that referenced this issue Dec 2, 2024
jborean93 added a commit that referenced this issue Dec 4, 2024
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

No branches or pull requests

3 participants